From 78491331a8b6d176b8ed60c8c8dc8f82aa7c73c2 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 13 Jul 2022 19:09:32 +0200 Subject: [PATCH] CMake: Allow setting Qt6_DIR to find packages when not cross-compiling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So far we always recommended that developers set CMAKE_PREFIX_PATH to point to the location of the Qt installation so that Qt packages are found by CMake. In Qt5 one could also set the Qt5_DIR variable to $qt/lib/cmake/Qt5 to allow the following signature to work: find_package(Qt5 COMPONENTS Core) This was not sufficient in Qt6 because the CoreTools dependency would not be found. Fix this by also looking into the parent folder of CMAKE_CURRENT_LIST_DIR as well as _qt_cmake_dir, like we already do for regular non-Tools packages in _qt_internal_find_dependencies. Note that setting Qt6_DIR is not sufficient for cross-compilation if the qt.toolchain.cmake file is not used. Aside from platform specific options that would have to be passed manually to CMake (like -DCMAKE_SYSTEM_NAME=iOS for iOS) and passing a QT_HOST_PATH value, the code would also need to be adapted to do the necessary CMAKE_FIND_ROOT_PATH manipulations to ensure that dependent packages are found. Task-number: QTBUG-97615 Change-Id: I10c419632d43bb929e184bab3b9d3d27a35ea87a Reviewed-by: Jörg Bornemann (cherry picked from commit 0e2b385c5b77549fb8a25651840821076fb6d93c) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtPublicDependencyHelpers.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/QtPublicDependencyHelpers.cmake b/cmake/QtPublicDependencyHelpers.cmake index b04363b1db4..234ef7e5152 100644 --- a/cmake/QtPublicDependencyHelpers.cmake +++ b/cmake/QtPublicDependencyHelpers.cmake @@ -58,6 +58,8 @@ macro(_qt_internal_find_tool_dependencies target target_dep_list) ${__qt_${target}_version} ${__qt_${target}_find_package_args} PATHS + "${CMAKE_CURRENT_LIST_DIR}/.." + "${_qt_cmake_dir}" ${_qt_additional_packages_prefix_paths} ) if (NOT ${__qt_${target}_pkg}_FOUND)