diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-09-19 13:46:37 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-09-21 13:10:37 +0000 |
commit | ffe088941378e32ea30c142cca7e63c537a41ff1 (patch) | |
tree | e51291904597f8edf32610ea3e15779721af3204 | |
parent | f771b8f6b14418508c110e1e0dcd31b903424fca (diff) |
Fix examples find_package calls to work in prefix builds
To build examples as part of a non-installed Qt prefix build,
not-yet-installed Config files need to be found by find_package()
calls inside example projects.
Facilitate that by propagating the CMAKE_PREFIX_PATH and
QT_EXAMPLES_CMAKE_PREFIX_PATH paths in all relevant find_package()
calls where NO_DEFAULT_PATH is used.
Also adjust the inclusion of the QtFeature.cmake file to be relative
to the qt6 directory, rather than the current list directory.
This is needed to successfully find the file when parsing a Config
file from a non-installed build directory.
Change-Id: I36031279628f1f7741d8f4d7571484a6545227f7
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | cmake/QtBuildInternals/QtBuildInternalsConfig.cmake | 7 | ||||
-rw-r--r-- | cmake/QtConfig.cmake.in | 3 | ||||
-rw-r--r-- | cmake/QtModuleConfig.cmake.in | 2 | ||||
-rw-r--r-- | cmake/QtModuleDependencies.cmake.in | 2 | ||||
-rw-r--r-- | cmake/QtPluginDependencies.cmake.in | 2 |
5 files changed, 11 insertions, 5 deletions
diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index e8002b5550..cfd11cd6f9 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -151,8 +151,13 @@ macro(qt_build_tests) endmacro() macro(qt_examples_build_begin) - # It is part of a Qt build => Use the CMake config files from the binary dir + # 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 "${CMAKE_BINARY_DIR}") + list(APPEND QT_EXAMPLES_CMAKE_PREFIX_PATH "${CMAKE_BINARY_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}) diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 1212c191b9..2a3c862d94 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -6,6 +6,7 @@ if (CMAKE_VERSION VERSION_LESS 3.1.0) endif() get_filename_component(_qt_cmake_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) +set(_qt_@PROJECT_VERSION_MAJOR@_config_cmake_dir "${CMAKE_CURRENT_LIST_DIR}") if (NOT QT_NO_CREATE_TARGETS) include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Targets.cmake") @@ -28,7 +29,7 @@ foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS}) find_package(@INSTALL_CMAKE_NAMESPACE@${module} ${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET} ${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_REQUIRED} - PATHS ${_qt_cmake_dir} NO_DEFAULT_PATH + PATHS ${_qt_cmake_dir} ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH ) if (NOT @INSTALL_CMAKE_NAMESPACE@${module}_FOUND) string(CONFIGURE ${_qt5_module_location_template} _expected_module_location @ONLY) diff --git a/cmake/QtModuleConfig.cmake.in b/cmake/QtModuleConfig.cmake.in index 2f042e6b2c..b24bcb9561 100644 --- a/cmake/QtModuleConfig.cmake.in +++ b/cmake/QtModuleConfig.cmake.in @@ -28,7 +28,7 @@ foreach(extra_cmake_include @extra_cmake_includes@) include("${CMAKE_CURRENT_LIST_DIR}/${extra_cmake_include}") endforeach() -include(${_import_prefix}/../@INSTALL_CMAKE_NAMESPACE@/QtFeature.cmake) +include(${_qt_@PROJECT_VERSION_MAJOR@_config_cmake_dir}/QtFeature.cmake) qt_make_features_available(@QT_CMAKE_EXPORT_NAMESPACE@::@target@) diff --git a/cmake/QtModuleDependencies.cmake.in b/cmake/QtModuleDependencies.cmake.in index 81d6431c67..c9cfa9e752 100644 --- a/cmake/QtModuleDependencies.cmake.in +++ b/cmake/QtModuleDependencies.cmake.in @@ -63,7 +63,7 @@ foreach(_target_dep ${_target_deps}) if (NOT ${pkg}_FOUND) find_dependency(${pkg} ${version} - PATHS "${CMAKE_CURRENT_LIST_DIR}/.." NO_DEFAULT_PATH + PATHS "${CMAKE_CURRENT_LIST_DIR}/.." ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH ) endif() diff --git a/cmake/QtPluginDependencies.cmake.in b/cmake/QtPluginDependencies.cmake.in index 6ca392ec64..0dd6ba5a08 100644 --- a/cmake/QtPluginDependencies.cmake.in +++ b/cmake/QtPluginDependencies.cmake.in @@ -43,7 +43,7 @@ foreach(_target_dep ${_target_deps}) if (NOT ${pkg}_FOUND) find_dependency(${pkg} ${version} - PATHS "${CMAKE_CURRENT_LIST_DIR}/.." NO_DEFAULT_PATH + PATHS "${CMAKE_CURRENT_LIST_DIR}/.." ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH ) endif() |