From 1c261198f96198370f8f9efd9f4e1ba1e887e823 Mon Sep 17 00:00:00 2001 From: zinface Date: Tue, 21 Mar 2023 00:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=20windows-deployqt:=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=8A=A8=E6=80=81=20QSci=20=E5=BA=93?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E8=87=AA=E5=8A=A8=20windeployqt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/platforms/utils.cmake | 49 ++++++++++++++++++++ cmake/platforms/windows-deployqt.cmake | 62 +++----------------------- 2 files changed, 55 insertions(+), 56 deletions(-) diff --git a/cmake/platforms/utils.cmake b/cmake/platforms/utils.cmake index de5eea8..0b4613a 100644 --- a/cmake/platforms/utils.cmake +++ b/cmake/platforms/utils.cmake @@ -52,3 +52,52 @@ function(qt5_qt6_compatible_check _CHECK_FILE _VAR) set(${_VAR} false PARENT_SCOPE) endif(_index LESS 0) endfunction(qt5_qt6_compatible_check _CHECK_FILE _VAR) + + +# windeployqt_install + # Windows 在 install 目标时进行 windeployqt 的自动化 + # 根据 + # https://blog.nathanosman.com/2017/11/24/using-windeployqt-with-cpack.html +function(windeployqt_install TARGET) + # string(TOLOWER "${ALIAS}_file" _file) + # string(TOLOWER "${ALIAS}_output" _output) + + set(WINDEPLOYQT_EXECUTABLE "${WINDOWS_QT_DIR}/../../../bin/windeployqt") + # + file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/${TARGET}_PATH" + CONTENT "$" + ) + install(CODE + " + file(READ \"${CMAKE_BINARY_DIR}/${TARGET}_PATH\" _file) + execute_process( + COMMAND \"${WINDEPLOYQT_EXECUTABLE}\" + # 虚假的运行 windeployqt 而不复制任何内容 + --dry-run + # 扫描QML-从目录开始导入。 + --qmlimport ${WINDOWS_QT_DIR}/../../../qml + # 部署编译器运行时(仅限桌面)。 + --compiler-runtime + # 以源 目标的输出形成映射关系,以便用于解析内容 + --list mapping + \${_file} + OUTPUT_VARIABLE _output + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # 将内容转为一个列表,使用 WINDOWS_COMMAND 类型的处理方式 + separate_arguments(_files WINDOWS_COMMAND \${_output}) + + while(_files) + list(GET _files 0 _src) + list(GET _files 1 _dest) + execute_process( + COMMAND \"\${CMAKE_COMMAND}\" -E + copy_if_different \${_src} \"\${CMAKE_INSTALL_PREFIX}/bin/\${_dest}\" + ) + message(\"COPY \${_src} \${CMAKE_INSTALL_PREFIX}/bin/\${_dest}\") + list(REMOVE_AT _files 0 1) + endwhile(_files) + " + ) +endfunction(windeployqt_install TARGET) diff --git a/cmake/platforms/windows-deployqt.cmake b/cmake/platforms/windows-deployqt.cmake index 97b02a1..4594e89 100644 --- a/cmake/platforms/windows-deployqt.cmake +++ b/cmake/platforms/windows-deployqt.cmake @@ -98,46 +98,9 @@ if(WINDOWS_DEPLOY_QT) # ---------- Windeployqt With Install Target ---------- # - # - set(WINDEPLOYQT_EXECUTABLE "${WINDOWS_QT_DIR}/../../../bin/windeployqt") - # - file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/${PROJECT_NAME}_PATH" - CONTENT "$" - ) - install(CODE - " - file(READ \"${CMAKE_BINARY_DIR}/${PROJECT_NAME}_PATH\" _file) - execute_process( - COMMAND \"${WINDEPLOYQT_EXECUTABLE}\" - # 虚假的运行 windeployqt 而不复制任何内容 - --dry-run - # 扫描QML-从目录开始导入。 - --qmlimport ${WINDOWS_QT_DIR}/../../../qml - # 部署编译器运行时(仅限桌面)。 - --compiler-runtime - # 以源 目标的输出形成映射关系,以便用于解析内容 - --list mapping - \${_file} - OUTPUT_VARIABLE _output - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # 将内容转为一个列表,使用 WINDOWS_COMMAND 类型的处理方式 - separate_arguments(_files WINDOWS_COMMAND \${_output}) - - while(_files) - list(GET _files 0 _src) - list(GET _files 1 _dest) - execute_process( - COMMAND \"\${CMAKE_COMMAND}\" -E - copy_if_different \${_src} \"\${CMAKE_INSTALL_PREFIX}/bin/\${_dest}\" - ) - message(\"COPY \${_src} \${CMAKE_INSTALL_PREFIX}/bin/\${_dest}\") - list(REMOVE_AT _files 0 1) - endwhile(_files) - " - ) - + include(cmake/platforms/utils.cmake) + windeployqt_install(${PROJECT_NAME}) + # ---------------------------------- QSci ---------------------------------- # # 当 QSci 需要构建为动态库时,就已经开始导致了关联性错误,这个与原始分支上的预期的方案不符 @@ -172,22 +135,9 @@ if(WINDOWS_DEPLOY_QT) # 部署运行时使用指定的目录 --dir ${WINDOWS_APPLICATION_DEPLOY_PATH} ) - - add_custom_command(TARGET windows-deployqt - POST_BUILD - COMMAND ${WINDOWS_QT_DIR}/../../../bin/windeployqt - # - ${WINDOWS_APPLICATION_DEPLOY_PATH}/QSci.dll - - # 扫描QML-从目录开始导入。 - --qmlimport ${WINDOWS_QT_DIR}/../../../qml - # 部署编译器运行时(仅限桌面)。 - --compiler-runtime - # 详细级别(0-2) - --verbose 2 - # 部署运行时使用指定的目录 - --dir ${CMAKE_INSTALL_PREFIX}/bin - ) + + # ---------- Windeployqt With Install Target ---------- # + windeployqt_install(QSci) endif(NOTEPAD_BUILD_BY_SHARED)