From d2359b2d4e5db6c42158d536d6e2a2af5ea1e59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6hne?= Date: Wed, 4 Aug 2021 17:36:22 +0200 Subject: Pick up *Tools components also from host Qt Let find_package(Qt6 COMPONENTS LinguistTools) for a cross-compiled Qt fall back to search LinguistTools in the host Qt. Use the same trick as in QtModuleDependencies.cmake: Prepend both CMAKE_PREFIX_PATH and CMAKE_FIND_ROOT_PATH with the QT_HOST_PATH (respective ${QT_HOST_PATH}/lib/cmake). Furthermore adding ${QT_HOST_PATH}/lib/cmake to PATHS argument makes sure that find_package will work even with NO_DEFAULT_PATH. Make sure not to match ShaderTools and Tools packages. ShaderTools is the cross-compiled package, the host package name is ShaderToolsTools. Tools is the cross-compiled module from qttools. Allow an opt out via a QT_NO_FIND_HOST_TOOLS_PATH_MANIPULATION variable in case that we accidentally match more packages ending in Tools that are actually cross-compiled packages. Pick-to: 6.1 6.2 Fixes: QTBUG-95602 Change-Id: Ib0a787716fa529e36f22356da069e705d9eed5fa Reviewed-by: Joerg Bornemann --- cmake/QtConfig.cmake.in | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'cmake') diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 24c5cdd782..2c4058f0da 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -100,6 +100,23 @@ if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES) endif() foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS}) + if(NOT "${QT_HOST_PATH}" STREQUAL "" + AND "${module}" MATCHES "Tools$" + AND NOT "${module}" MATCHES "ShaderTools$" + AND NOT "${module}" MATCHES "^Tools$" + AND NOT QT_NO_FIND_HOST_TOOLS_PATH_MANIPULATION) + # Make sure that a Qt*Tools package is also looked up in QT_HOST_PATH. + # But don't match QtShaderTools and QtTools which are cross-compiled target package names. + # Allow opt out just in case. + # TODO: Handle a hypothetical QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH + # See QTBUG-94524 + set(__qt_find_package_host_qt_path "${QT_HOST_PATH}/lib/cmake") + set(__qt_backup_cmake_prefix_path "${CMAKE_PREFIX_PATH}") + set(__qt_backup_cmake_find_root_path "${CMAKE_FIND_ROOT_PATH}") + list(PREPEND CMAKE_PREFIX_PATH "${__qt_find_package_host_qt_path}") + list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}") + endif() + find_package(@INSTALL_CMAKE_NAMESPACE@${module} ${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET} PATHS @@ -107,8 +124,18 @@ foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS}) ${_qt_additional_packages_prefix_path} ${_qt_additional_packages_prefix_path_env} ${QT_EXAMPLES_CMAKE_PREFIX_PATH} + ${__qt_find_package_host_qt_path} ${__qt_use_no_default_path_for_qt_packages} ) + + if(NOT "${__qt_find_package_host_qt_path}" STREQUAL "") + set(CMAKE_PREFIX_PATH "${__qt_backup_cmake_prefix_path}") + set(CMAKE_FIND_ROOT_PATH "${__qt_backup_cmake_find_root_path}") + unset(__qt_backup_cmake_prefix_path) + unset(__qt_backup_cmake_find_root_path) + unset(__qt_find_package_host_qt_path) + endif() + if (NOT @INSTALL_CMAKE_NAMESPACE@${module}_FOUND) set(_qt_expected_component_config_path "${_qt_cmake_dir}/@INSTALL_CMAKE_NAMESPACE@${module}/@INSTALL_CMAKE_NAMESPACE@${module}Config.cmake") -- cgit v1.2.3