summaryrefslogtreecommitdiffstats
path: root/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2023-08-17 17:14:09 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2023-08-19 11:03:36 +0200
commitba9623860056cbb75e426e27905f9c29b687cefa (patch)
treed98a0ca6f2cf4d52d35ee78488a6e13f166256b6 /cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
parentf780893c39d6090e804c8caeb08af4f919777109 (diff)
Fix running CMake test projects in prefix builds
Consider the following situation: There are CMake tests in qttools/tests/auto/cmake that configure and build CMake test projects, essentially as external projects. One of those test projects does find_package(Qt6 COMPONENTS LinguistTools). This call fails in a prefix build, because Qt6LinguistToolsConfig.cmake is not installed yet. It merely exists in qttools-build/lib/cmake/Qt6LinguistTools. We must adjust CMAKE_PREFIX_PATH to be able to find Qt6LinguistTools. We also must adjust QT_ADDITIONAL_PACKAGES_PREFIX_PATH to be able to find the LinguistTools component of the Qt6 package. Use the prefixes setup from the support for building examples as external projects and use it for CMake test projects as well. Task-number: QTBUG-84884 Change-Id: I1bd5d5084cf931196bdb014cd75ca7578cd9decb Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake/QtBuildInternals/QtBuildInternalsConfig.cmake')
-rw-r--r--cmake/QtBuildInternals/QtBuildInternalsConfig.cmake40
1 files changed, 7 insertions, 33 deletions
diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
index 80d1d5413c..b77960c7f2 100644
--- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
+++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
@@ -1146,39 +1146,13 @@ function(qt_internal_add_example_external_project subdir)
cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${singleOpts}" "${multiOpts}")
- # TODO: Fix example builds when using Conan / install prefixes are different for each repo.
- if(QT_SUPERBUILD OR QtBase_BINARY_DIR)
- # When doing a top-level build or when building qtbase,
- # always use the Config file from the current build directory, even for prefix builds.
- # We strive to allow building examples without installing Qt first, which means we can't
- # use the install or staging Config files.
- set(qt_prefixes "${QT_BUILD_DIR}")
- set(qt_cmake_dir "${QT_CONFIG_BUILD_DIR}/${QT_CMAKE_EXPORT_NAMESPACE}")
- else()
- # This is a per-repo build that isn't the qtbase repo, so we know that
- # qtbase was found via find_package() and Qt6_DIR must be set
- set(qt_cmake_dir "${${QT_CMAKE_EXPORT_NAMESPACE}_DIR}")
-
- # In a prefix build of a non-qtbase repo, we want to pick up the installed Config files
- # for all repos except the one that is currently built. For the repo that is currently
- # built, we pick up the Config files from the current repo build dir instead.
- # For non-prefix builds, there's only one prefix, the main build dir.
- # Both are handled by this assignment.
- set(qt_prefixes "${QT_BUILD_DIR}")
-
- # Appending to QT_ADDITIONAL_PACKAGES_PREFIX_PATH helps find Qt6 components in
- # non-qtbase prefix builds because we use NO_DEFAULT_PATH in find_package calls.
- # It also handles the cross-compiling scenario where we need to adjust both the root path
- # and prefixes, with the prefixes containing lib/cmake. This leverages the infrastructure
- # previously added for Conan.
- list(APPEND QT_ADDITIONAL_PACKAGES_PREFIX_PATH ${qt_prefixes})
-
- # In a prefix build, look up all repo Config files in the install prefix,
- # except for the current repo, which will look in the build dir (handled above).
- if(QT_WILL_INSTALL)
- list(APPEND qt_prefixes "${QT6_INSTALL_PREFIX}")
- endif()
- endif()
+ _qt_internal_get_build_vars_for_external_projects(
+ CMAKE_DIR_VAR qt_cmake_dir
+ PREFIXES_VAR qt_prefixes
+ ADDITIONAL_PACKAGES_PREFIXES_VAR qt_additional_packages_prefixes
+ )
+
+ list(APPEND QT_ADDITIONAL_PACKAGES_PREFIX_PATH "${qt_additional_packages_prefixes}")
set(vars_to_pass_if_defined)
set(var_defs)