build: deploy Qt runtime for Windows builds

Run windeployqt as a post-build step for Schedule, copy MinGW runtime DLLs, and place Windows test binaries next to the deployed Qt runtime.
This commit is contained in:
Misaki
2026-10-26 14:54:22 +08:00
parent 059fd721ba
commit 555371a4e0
4 changed files with 73 additions and 2 deletions
+4 -2
View File
@@ -132,8 +132,10 @@ cmake --build --preset linux-gcc
.\build\windows-mingw\bin\Schedule.exe .\build\windows-mingw\bin\Schedule.exe
``` ```
若运行时找不到 Qt DLL,把 `C:/Qt/6.6.3/mingw_64/bin` 加入当前终端 `PATH`,或分发前执行 构建完成后 CMake 会自动调用 `windeployqt` 将 Qt DLL、平台插件和所需运行时复制到
`C:/Qt/6.6.3/mingw_64/bin/windeployqt.exe build/windows-mingw/bin/Schedule.exe`。 `build/windows-mingw/bin`,MinGW 的 `libstdc++` / `libgcc` / `libwinpthread` 也会一并复制,
因此可以直接运行 `Schedule.exe`,不需要手动设置 Qt 的 `PATH`。分发前如需重新收集运行库,
仍可使用 `windeployqt.exe build/windows-mingw/bin/Schedule.exe`。
5. 若 Windows 上安装了 Go,构建会同时生成 `build/windows-mingw/bin/schedule-sync-server.exe` 5. 若 Windows 上安装了 Go,构建会同时生成 `build/windows-mingw/bin/schedule-sync-server.exe`
并运行双客户端同步集成测试;没有 Go 时该测试自动跳过。也可以把同步服务端跑在 Linux 并运行双客户端同步集成测试;没有 Go 时该测试自动跳过。也可以把同步服务端跑在 Linux
或另一台机器上,客户端只需填写 `http://<server>:8787`。 或另一台机器上,客户端只需填写 `http://<server>:8787`。
+57
View File
@@ -50,6 +50,63 @@ if(WIN32 AND ELAWIDGETTOOLS_BUILD_STATIC_LIB)
endif() endif()
endif() endif()
function(schedule_deploy_qt_runtime target)
if(NOT WIN32)
return()
endif()
set(_qt_bin_dir "")
if(TARGET Qt6::qmake)
get_target_property(_qmake Qt6::qmake IMPORTED_LOCATION)
if(_qmake)
get_filename_component(_qt_bin_dir "${_qmake}" DIRECTORY)
endif()
endif()
if(NOT _qt_bin_dir)
get_filename_component(_qt_bin_dir "${Qt6_DIR}/../../../bin" ABSOLUTE)
endif()
find_program(SCHEDULE_WINDEPLOYQT
NAMES windeployqt
HINTS "${_qt_bin_dir}"
NO_DEFAULT_PATH
)
if(NOT SCHEDULE_WINDEPLOYQT)
message(FATAL_ERROR "windeployqt not found under ${_qt_bin_dir}; check CMAKE_PREFIX_PATH")
endif()
set(_deploy_args)
if(MSVC)
list(APPEND _deploy_args --compiler-runtime)
endif()
list(APPEND _deploy_args
--dir "$<TARGET_FILE_DIR:${target}>"
"$<TARGET_FILE:${target}>"
)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND "${SCHEDULE_WINDEPLOYQT}" ${_deploy_args}
COMMENT "Deploying Qt runtime for ${target}"
VERBATIM
)
if(MINGW)
get_filename_component(_mingw_bin_dir "${CMAKE_CXX_COMPILER}" DIRECTORY)
file(GLOB _mingw_runtime
"${_mingw_bin_dir}/libgcc_s_*.dll"
"${_mingw_bin_dir}/libstdc++-6.dll"
"${_mingw_bin_dir}/libwinpthread-1.dll"
)
if(_mingw_runtime)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${_mingw_runtime} "$<TARGET_FILE_DIR:${target}>"
COMMENT "Copying MinGW runtime for ${target}"
VERBATIM
)
endif()
endif()
endfunction()
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(tests) add_subdirectory(tests)
+4
View File
@@ -114,3 +114,7 @@ set_target_properties(Schedule PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
) )
target_link_libraries(Schedule PRIVATE schedule_ui schedule_sync) target_link_libraries(Schedule PRIVATE schedule_ui schedule_sync)
if(WIN32)
schedule_deploy_qt_runtime(Schedule)
endif()
+8
View File
@@ -43,3 +43,11 @@ if(TARGET schedule-sync-server)
ENVIRONMENT "SCHEDULE_SYNC_SERVER_BIN=${CMAKE_BINARY_DIR}/bin/schedule-sync-server${CMAKE_EXECUTABLE_SUFFIX}" ENVIRONMENT "SCHEDULE_SYNC_SERVER_BIN=${CMAKE_BINARY_DIR}/bin/schedule-sync-server${CMAKE_EXECUTABLE_SUFFIX}"
) )
endif() endif()
if(WIN32)
set_target_properties(
test_storage test_services test_grid test_mainwindow test_compactwindow
test_config test_scheduler test_ai test_openai_provider test_sync_integration
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
endif()