From 5e0129f63cbd45767342c43135f6061750511e33 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 20 Jul 2020 17:12:45 +0200 Subject: [PATCH] CMake: Fix configuration of CMake tests in-build-tree Qt6 package was not found the tests were configured in-tree as opposed to standalone tests. Use the same trick we do for building examples in-tree. Specify the path to the build tree packages, and don't create targets. Amends 96e3ee06598d00e7155f3f8574759ea658a134e5 Change-Id: Ia60de416ce0afff5bd40be8c0c6e3c7898fd7ebf Reviewed-by: Cristian Adam --- .../QtBuildInternalsConfig.cmake | 16 +++++++++++----- tests/auto/cmake/CMakeLists.txt | 5 +++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 2d94e384e58..95564e0599e 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -414,18 +414,24 @@ function(qt_set_up_fake_standalone_tests_install_prefix) set(CMAKE_INSTALL_PREFIX "${new_install_prefix}" PARENT_SCOPE) endfunction() +# Mean to be called when configuring examples as part of the main build tree, as well as for CMake +# tests (tests that call CMake to try and build CMake applications). +macro(qt_internal_set_up_build_dir_package_paths) + list(APPEND CMAKE_PREFIX_PATH "${QT_BUILD_DIR}") + # Make sure the CMake config files do not recreate the already-existing targets + set(QT_NO_CREATE_TARGETS TRUE) + set(BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "BOTH") +endmacro() + macro(qt_examples_build_begin) # Examples that are built as part of the Qt build need to use the CMake config files from the # build dir, because they are not installed yet in a prefix build. # Appending to CMAKE_PREFIX_PATH helps find the initial Qt6Config.cmake. # Appending 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(APPEND CMAKE_PREFIX_PATH "${QT_BUILD_DIR}") + qt_internal_set_up_build_dir_package_paths() list(APPEND QT_EXAMPLES_CMAKE_PREFIX_PATH "${QT_BUILD_DIR}") - # Also make sure the CMake config files do not recreate the already-existing targets - set(QT_NO_CREATE_TARGETS TRUE) - set(BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "BOTH") # Because CMAKE_INSTALL_RPATH is empty by default in the repo project, examples need to have # it set here, so they can run when installed. diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index b270ab4eda7..1ad56e1adcf 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -60,6 +60,11 @@ set(required_packages Core Network Xml Sql Test) set(optional_packages DBus Gui Widgets PrintSupport OpenGL Concurrent) # Setup the test when called as a completely standalone project. +if(TARGET Qt6::Core) + # Tests are built as part of the qtbase build tree. + # Setup paths so that the Qt packages are found, similar to examples. + qt_internal_set_up_build_dir_package_paths() +endif() find_package(Qt6 REQUIRED COMPONENTS ${required_packages}) find_package(Qt6 OPTIONAL_COMPONENTS ${optional_packages})