
function(auto_copy_mingw_dll target)
    if(MINGW)
        # 获取MinGW目录
        get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH)

        # 根据你的环境调整DLL列表
        set(MINGW_DLLS
                "libstdc++-6.dll"
#                "libgcc_s_dw2-1.dll"
                "libgcc_s_seh-1.dll"
                "libwinpthread-1.dll"
                "libbz2-1.dll"
                "libbrotlidec.dll"
                "libbrotlicommon.dll"
                "libharfbuzz-0.dll"
                "libpng16-16.dll"
                "zlib1.dll"
                "libglib-2.0-0.dll"
                "libfreetype-6.dll"
                "libgraphite2.dll"
                "libintl-8.dll"
                "libpcre2-8-0.dll"
                "libiconv-2.dll"
        )

        foreach(DLL ${MINGW_DLLS})
            # 检查文件是否存在
            if(EXISTS "${MINGW_DIR}/${DLL}")
                add_custom_command(TARGET ${target} POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy_if_different
                        "${MINGW_DIR}/${DLL}"
                        "$<TARGET_FILE_DIR:${target}>"
                        COMMENT "Copying ${DLL} to output directory"
                        VERBATIM)
            else()
                message(WARNING "DLL not found: ${MINGW_DIR}/${DLL}")
            endif()
        endforeach()
    endif()
endfunction()