summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2022-02-03 14:13:25 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-03-16 19:04:01 +0000
commitf94495ad79bd9dbf571a6c77e25b16a0cae03fc7 (patch)
tree858858d89e05ef7440020d84d404a9e20456a988
parentca311cf1ab189ccf91c2835393c71743a3f23fdb (diff)
CMake: Don't rely on CMAKE_FIND_ROOT_PATH_MODE_PACKAGE for examples
We shouldn't set CMAKE_FIND_ROOT_PATH_MODE_PACKAGE to BOTH when cross-building examples without ExternalProjects. Instead append the $build_tree_prefix to CMAKE_FIND_ROOT_PATH and $build_tree_prefix/lib/cmake to QT_EXAMPLES_CMAKE_PREFIX_PATH to circumvent the usual CMake path-rerooting issue. This ensures that the build-tree Config files are found by the in-tree find_package calls when cross-building examples. Task-number: QTBUG-96232 Change-Id: I4e31f0bf3dbfeb4339823fe09addda3ae83f12c3 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit d1c56073b4cf3346168413e7d931c63355307e9d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--cmake/QtBuildInternals/QtBuildInternalsConfig.cmake13
1 files changed, 4 insertions, 9 deletions
diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
index c2225e4ed4..a515fcd43d 100644
--- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
+++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
@@ -719,12 +719,6 @@ 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)
-
- # TODO: Remove reliance on CMAKE_FIND_ROOT_PATH_MODE_PACKAGE and instead pass any required
- # prefixes as a combination of CMAKE_PREFIX_PATH and CMAKE_FIND_ROOT_PATH like we do in
- # qt_internal_add_tool.
- 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)
@@ -807,9 +801,12 @@ macro(qt_examples_build_begin)
# 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.
+ # Appending to CMAKE_FIND_ROOT_PATH ensures the components are found while cross-compiling
+ # without setting CMAKE_FIND_ROOT_PATH_MODE_PACKAGE to BOTH.
if(NOT QT_IS_EXTERNAL_EXAMPLES_BUILD OR NOT __qt_all_examples_ported_to_external_projects)
qt_internal_set_up_build_dir_package_paths()
- list(APPEND QT_EXAMPLES_CMAKE_PREFIX_PATH "${QT_BUILD_DIR}")
+ list(APPEND CMAKE_FIND_ROOT_PATH "${QT_BUILD_DIR}")
+ list(APPEND QT_EXAMPLES_CMAKE_PREFIX_PATH "${QT_BUILD_DIR}/lib/cmake")
endif()
# Because CMAKE_INSTALL_RPATH is empty by default in the repo project, examples need to have
@@ -862,8 +859,6 @@ macro(qt_examples_build_end)
endif()
endforeach()
- set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE})
-
install(CODE "
# Restore backed up CMAKE_INSTALL_PREFIX.
set(CMAKE_INSTALL_PREFIX \"\${_qt_internal_examples_cmake_install_prefix_backup}\")