555371a4e0
Run windeployqt as a post-build step for Schedule, copy MinGW runtime DLLs, and place Windows test binaries next to the deployed Qt runtime.
114 lines
3.8 KiB
CMake
114 lines
3.8 KiB
CMake
cmake_minimum_required(VERSION 3.24)
|
|
|
|
find_package(Qt6 6.5 REQUIRED COMPONENTS Core Gui Widgets Sql Network Concurrent WebSockets Test)
|
|
|
|
qt_standard_project_setup()
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
set(CMAKE_AUTORCC ON)
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
# 警告选项集中定义,仅作用于本工程目标,避免第三方库告警阻断构建。
|
|
add_library(schedule_warnings INTERFACE)
|
|
if(MSVC)
|
|
target_compile_options(schedule_warnings INTERFACE /W4 /permissive-)
|
|
if(SCHEDULE_WARNINGS_AS_ERRORS)
|
|
target_compile_options(schedule_warnings INTERFACE /WX)
|
|
endif()
|
|
else()
|
|
target_compile_options(schedule_warnings INTERFACE -Wall -Wextra -Wnon-virtual-dtor)
|
|
if(SCHEDULE_WARNINGS_AS_ERRORS)
|
|
target_compile_options(schedule_warnings INTERFACE -Werror)
|
|
endif()
|
|
endif()
|
|
|
|
add_library(tomlplusplus INTERFACE)
|
|
target_include_directories(tomlplusplus SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/3rd/tomlplusplus)
|
|
|
|
# ElaWidgetTools 以静态库方式引入,避免额外运行时库分发。
|
|
set(QT_VERSION_MAJOR 6)
|
|
set(ELAWIDGETTOOLS_BUILD_STATIC_LIB ON CACHE BOOL "" FORCE)
|
|
set(CMAKE_WARN_DEPRECATED OFF)
|
|
add_subdirectory(3rd/ElaWidgetTools/ElaWidgetTools EXCLUDE_FROM_ALL)
|
|
unset(CMAKE_WARN_DEPRECATED)
|
|
# 第三方库按自身要求的 C++17 编译,避免其 C++20 弃用告警污染构建输出。
|
|
set_target_properties(ElaWidgetTools PROPERTIES
|
|
CXX_STANDARD 17
|
|
CXX_STANDARD_REQUIRED ON
|
|
CXX_EXTENSIONS OFF
|
|
)
|
|
if(NOT MSVC)
|
|
# 第三方库内部仍使用少量 Qt 已弃用 API,抑制其告警但不修改其源码。
|
|
target_compile_options(ElaWidgetTools PRIVATE -Wno-deprecated-declarations)
|
|
endif()
|
|
if(WIN32 AND ELAWIDGETTOOLS_BUILD_STATIC_LIB)
|
|
# ElaProperty.h 默认把使用方当作动态库客户端(dllimport)。静态链接时必须让
|
|
# 使用方也看到 ELAWIDGETTOOLS_LIBRARY,否则 MinGW 会生成 __imp_ 前缀符号。
|
|
target_compile_definitions(ElaWidgetTools INTERFACE ELAWIDGETTOOLS_LIBRARY)
|
|
if(MSVC)
|
|
target_compile_options(ElaWidgetTools INTERFACE /wd4251 /wd4275)
|
|
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(tests)
|
|
|
|
add_subdirectory(tools)
|