From 2ab80a2c18f23dd8b26fbf9880500cd9abc36f6b Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 18 Aug 2023 17:33:21 +0200 Subject: CMake: Allow find_package(Qt6 COMPONENTS Foo) in tests In prefix builds of non-qtbase repositories, calls to find_package(Qt6 COMPONENT Foo) did not work in tests, because the find_package calls in Qt6Config.cmake use NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH is ignored. Non-external-project examples had the same problem. This was fixed by ffe088941378e32ea30c142cca7e63c537a41ff1 which introduced the variable QT_EXAMPLES_CMAKE_PREFIX_PATH as additional parameter in all relevant find_package calls. We now set this variable in qt_build_tests where it should be local to the tests directory and its children. We cannot use QT_ADDITIONAL_PACKAGES_PREFIX_PATH, because it's value is read once and cached in Qt6Config.cmake - we would have to clear the internal cache variable. It would probably be good to rename QT_EXAMPLES_CMAKE_PREFIX_PATH to reflect that it's not just used for examples. However, my naming skills are drained for today. Task-number: QTBUG-88264 Change-Id: I8bcfe9b7f2ee1f1b75dc725977924d09cb36822c Reviewed-by: Alexandru Croitor Reviewed-by: Alexey Edelev --- cmake/QtBuildInternals/QtBuildInternalsConfig.cmake | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cmake/QtBuildInternals/QtBuildInternalsConfig.cmake') diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index ceb070ec0c..913e0cbcff 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -717,6 +717,10 @@ endfunction() macro(qt_build_tests) set(CMAKE_UNITY_BUILD OFF) + # Prepending to QT_EXAMPLES_CMAKE_PREFIX_PATH helps find components of Qt6, because those + # find_package calls use NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH is ignored. + list(PREPEND QT_EXAMPLES_CMAKE_PREFIX_PATH "${QT_BUILD_DIR}/${INSTALL_LIBDIR}/cmake") + if(QT_BUILD_STANDALONE_TESTS) # Find location of TestsConfig.cmake. These contain the modules that need to be # find_package'd when testing. -- cgit v1.2.3