From 9e044765ec88ee32781278f44a25746744dd48ec Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 12 Aug 2020 19:12:13 +0200 Subject: [PATCH] CMake: Fix empty value of CMAKE_SIZEOF_VOID_P when looking for tools Our initial approach to looking for host Qt tools when cross-compiling to a platform with a different architecture bitness compared to the host one was to unset CMAKE_SIZEOF_VOID_P before calling find_package(Qt6FooTools) and then restoring the value. That works to bypass the architecture bitness test in the ConfigVersion files, but it also influences the paths that find_package() searches in, specifically the lib paths like /usr/lib64 will not be searched in. Fortunately since CMake 3.14, write_basic_package_version_file() can take an additional ARCH_INDEPENDENT parameter. This disables the architecture bitness test when looking for the package, while allowing to still search in the /usr/lib64 like paths. Use it when creating the QtFooToolConfigVersion.cmake files. One could argue we should actually check if the tool executables could run on the host system where find_package is called for cross-compilation. We could do that in another change if the problem ever arises. Amends 03aa74e40d8f1270e1bb28d0791e5bc376ffa0b7 Amends 914b367c7f6a117130b8a56338c46a8102a1f77f Change-Id: I1181ff637ac80064a6a8538170b28a41743fc90c Fixes: QTBUG-81672 Reviewed-by: Christophe Giboudeaux Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann --- cmake/QtBuild.cmake | 4 +--- cmake/QtModuleDependencies.cmake.in | 7 ------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index dfe254c178..28bf5533d6 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -3578,6 +3578,7 @@ endif() "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion + ARCH_INDEPENDENT ) qt_install(FILES @@ -4916,8 +4917,6 @@ function(qt_add_tool target_name) # in the host system. set(BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "BOTH") - set(BACKUP_CMAKE_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}") - set(CMAKE_SIZEOF_VOID_P "") find_package( ${tools_package_name} ${PROJECT_VERSION} @@ -4927,7 +4926,6 @@ function(qt_add_tool target_name) NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PATH NO_CMAKE_SYSTEM_PACKAGE_REGISTRY) - set(CMAKE_SIZEOF_VOID_P "${BACKUP_CMAKE_SIZEOF_VOID_P}") set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "${BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}") set(CMAKE_PREFIX_PATH "${BACKUP_CMAKE_PREFIX_PATH}") diff --git a/cmake/QtModuleDependencies.cmake.in b/cmake/QtModuleDependencies.cmake.in index 56819f8816..d598571d64 100644 --- a/cmake/QtModuleDependencies.cmake.in +++ b/cmake/QtModuleDependencies.cmake.in @@ -35,11 +35,6 @@ endforeach() # Find Qt tool package. set(_tool_deps "@main_module_tool_deps@") -# The tools do not provide linkage targets but executables, where a mismatch -# between 32-bit target and 64-bit host does not matter. -set(BACKUP_@target@_CMAKE_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}") -set(CMAKE_SIZEOF_VOID_P "") - if(QT_HOST_PATH) # Make sure that the tools find the host tools first set(BACKUP_@target@_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}) @@ -56,7 +51,6 @@ foreach(_target_dep ${_tool_deps}) if (NOT ${pkg}_FOUND) set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE) - set(CMAKE_SIZEOF_VOID_P "${BACKUP_@target@_CMAKE_SIZEOF_VOID_P}") if(QT_HOST_PATH) set(CMAKE_PREFIX_PATH ${BACKUP_@target@_CMAKE_PREFIX_PATH}) set(CMAKE_FIND_ROOT_PATH ${BACKUP_@target@_CMAKE_FIND_ROOT_PATH}) @@ -68,7 +62,6 @@ if(QT_HOST_PATH) set(CMAKE_PREFIX_PATH ${BACKUP_@target@_CMAKE_PREFIX_PATH}) set(CMAKE_FIND_ROOT_PATH ${BACKUP_@target@_CMAKE_FIND_ROOT_PATH}) endif() -set(CMAKE_SIZEOF_VOID_P "${BACKUP_@target@_CMAKE_SIZEOF_VOID_P}") # note: target_deps example: "Qt6Core\;5.12.0;Qt6Gui\;5.12.0" set(_target_deps "@target_deps@")