From 633b77511d466b0223a7c8f4fa35d7c1fc6cd45e Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 29 Jan 2023 11:52:45 +0100 Subject: [PATCH] Add CMake Install Support for Windows (#4300) * fix: windows installation with cmake * fix: support install for all win32 compilers * chore: add changelog entry * fix: support `X_VCPKG_APPLOCAL_DEPS_INSTALL` * chore: document cmake min version * fix: vcpkg * fix: plugin path * fix: remove flattening * revert: `qt.conf` changes --------- Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/CMakeLists.txt | 32 +++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0db2ce31a..9e4fc4647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ - Dev: Fixed `final-dtor-non-final-class` warnings. (#4296) - Dev: Fixed `ambiguous-reversed-operator` warnings. (#4296) - Dev: Format YAML and JSON files with prettier. (#4304) +- Dev: Addded CMake Install Support on Windows. (#4300) ## 2.4.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b89ebbfb..5c9e2a7f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -651,17 +651,35 @@ if (BUILD_APP) RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/bin" ) - if (MSVC) - if (NOT VCPKG_INSTALLED_DIR) + if (WIN32) + if (NOT WINDEPLOYQT_PATH) get_target_property(Qt_Core_Location Qt${MAJOR_QT_VERSION}::Core LOCATION) get_filename_component(QT_BIN_DIR ${Qt_Core_Location} DIRECTORY) - set(WINDEPLOYQT_COMMAND "${QT_BIN_DIR}/windeployqt.exe" $ --release --no-compiler-runtime --no-translations --no-opengl-sw) + string(APPEND WINDEPLOYQT_PATH ${QT_BIN_DIR} /windeployqt.exe) + else() + file(TO_CMAKE_PATH "${WINDEPLOYQT_PATH}" WINDEPLOYQT_PATH) + endif() - install(TARGETS ${EXECUTABLE_PROJECT} - RUNTIME DESTINATION . - ) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(WINDEPLOYQT_MODE --debug) + else() + set(WINDEPLOYQT_MODE --release) + endif() - install(CODE "execute_process(COMMAND ${WINDEPLOYQT_COMMAND} --dir \${CMAKE_INSTALL_PREFIX})") + set(WINDEPLOYQT_COMMAND_ARGV "${WINDEPLOYQT_PATH}" "$" ${WINDEPLOYQT_MODE} --no-compiler-runtime --no-translations --no-opengl-sw) + string(REPLACE ";" " " WINDEPLOYQT_COMMAND "${WINDEPLOYQT_COMMAND_ARGV}") + + if (X_VCPKG_APPLOCAL_DEPS_INSTALL) + install(TARGETS ${EXECUTABLE_PROJECT} RUNTIME DESTINATION .) + else() + install(TARGETS ${EXECUTABLE_PROJECT} + RUNTIME_DEPENDENCIES + PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-" + POST_EXCLUDE_REGEXES ".*system32/.*\\.dll" + DIRECTORIES ${QT_BIN_DIR} + RUNTIME DESTINATION .) + install(CODE "message(\"-- Running: ${WINDEPLOYQT_COMMAND} --dir \\\"\${CMAKE_INSTALL_PREFIX}\\\"\")") + install(CODE "execute_process(COMMAND ${WINDEPLOYQT_COMMAND} --dir \"\${CMAKE_INSTALL_PREFIX}\" COMMAND_ERROR_IS_FATAL ANY)") endif() elseif (APPLE) install(TARGETS ${EXECUTABLE_PROJECT}