From 01d12a2d98c5bcda5b15d2ebfe6d32b872e8f6e6 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 14 Dec 2023 17:23:38 +0100 Subject: [PATCH] CMake: Deploy correct arch files when cross-compiling to arm Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When cross-compiling a user project from x86_64 to arm64 MSVC Windows target, during deployment we need to deploy arm libraries. By default because we use an x86_64 windeployqt, it always deploys x86_64 libraries. Make sure to pass the path to the target WoA qtpaths.bat file to windeployqt, so it deploys arm libraries. Pick-to: 6.6 6.5 Fixes: QTBUG-119619 Change-Id: Ib3b5498ae906726d1f9e0919333c102898b48ea9 Reviewed-by: 🌴 Alexey Edelev 🌴 Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff (cherry picked from commit 571201603acc731330c9af42a3aca9cda41d38fd) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/Qt6CoreDeploySupport.cmake | 7 +++++++ src/corelib/Qt6CoreMacros.cmake | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/corelib/Qt6CoreDeploySupport.cmake b/src/corelib/Qt6CoreDeploySupport.cmake index e189b265387..6560a23e1b4 100644 --- a/src/corelib/Qt6CoreDeploySupport.cmake +++ b/src/corelib/Qt6CoreDeploySupport.cmake @@ -404,6 +404,13 @@ function(qt6_deploy_runtime_dependencies) if(arg_NO_COMPILER_RUNTIME) list(APPEND tool_options --no-compiler-runtime) endif() + + # Specify path to target Qt's qtpaths .exe or .bat file, so windeployqt deploys the correct + # libraries when cross-compiling from x86_64 to arm64 windows. + if(__QT_DEPLOY_TARGET_QT_PATHS_PATH) + list(APPEND tool_options --qtpaths "${__QT_DEPLOY_TARGET_QT_PATHS_PATH}") + endif() + list(APPEND tool_options ${arg_DEPLOY_TOOL_OPTIONS}) elseif(__QT_DEPLOY_SYSTEM_NAME STREQUAL Darwin) set(extra_binaries_option "-executable=") diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index e80bf0bbacb..c4e7e815641 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -2863,6 +2863,20 @@ function(_qt_internal_setup_deploy_support) endif() endif() + # Generate path to the target (not host) qtpaths file. Needed for windeployqt when + # cross-compiling from an x86_64 host to an arm64 target, so it knows which architecture + # libraries should be deployed. + if(CMAKE_HOST_WIN32) + if(CMAKE_CROSSCOMPILING) + set(qt_paths_ext ".bat") + else() + set(qt_paths_ext ".exe") + endif() + else() + set(qt_paths_ext "") + endif() + set(target_qtpaths_path "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_BINS}/qtpaths${qt_paths_ext}") + file(GENERATE OUTPUT "${QT_DEPLOY_SUPPORT}" CONTENT "cmake_minimum_required(VERSION 3.16...3.21) @@ -2909,6 +2923,7 @@ set(__QT_DEPLOY_QT_INSTALL_PREFIX \"${QT6_INSTALL_PREFIX}\") set(__QT_DEPLOY_QT_INSTALL_BINS \"${QT6_INSTALL_BINS}\") set(__QT_DEPLOY_QT_INSTALL_PLUGINS \"${QT6_INSTALL_PLUGINS}\") set(__QT_DEPLOY_QT_INSTALL_TRANSLATIONS \"${QT6_INSTALL_TRANSLATIONS}\") +set(__QT_DEPLOY_TARGET_QT_PATHS_PATH \"${target_qtpaths_path}\") set(__QT_DEPLOY_PLUGINS \"\") set(__QT_DEPLOY_MUST_ADJUST_PLUGINS_RPATH \"${must_adjust_plugins_rpath}\") set(__QT_DEPLOY_USE_PATCHELF \"${QT_DEPLOY_USE_PATCHELF}\")