summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-09-25 20:02:56 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-09-28 15:48:17 +0200
commit7bb91398f25cb2016c0558fd397b376f413e3e96 (patch)
tree04b74cf1913468cc4637bce45951d7dc1a8bf0aa
parent1e883cf9b56376084f3329811aa91f4887ef6fcb (diff)
CMake: Allow finding Qt CMake packages in additional locations
By default, when using the Qt6 CMake package to look for components, the find_package() calls for the components use NO_DEFAULT_PATH to ensure that CMake doesn't accidentally find system (distro) packages. Instead we limit the paths to one level up from where the Qt6 package is. Unfortunately that doesn't quite work for finding Qt packages that might have been installed into a different prefix than where the main Qt prefix is. This happens when Qt addons are built by Conan, and installed into a separate prefix. To allow calls like find_package(Qt6 COMPONENTS ConanAddon) to work in a scenario as described above, introduce a new variable called QT_ADDITIONAL_PACKAGES_PREFIX_PATH which can be used to specify additional paths where Qt CMake packages should be found. This is similar to previously introduced QT_EXAMPLES_CMAKE_PREFIX_PATH variable which was meant for a similar case, but only for examples. Additionally, allow disabling the NO_DEFAULT_PATH option by setting the QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES cache variable to TRUE. This would allow regular usage of CMAKE_PREFIX_PATH to work, at the risk that system Qt CMake packages might be found. Augments 5cd4001bf2a7f0894c6ac269860e833b02df6cde and ffe088941378e32ea30c142cca7e63c537a41ff1. Fixes: QTBUG-86882 Change-Id: Ia8e060cbba6d2a10c3d63d81892f2c71e4236a9a Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--cmake/QtConfig.cmake.in11
-rw-r--r--cmake/QtModuleDependencies.cmake.in17
-rw-r--r--cmake/QtPluginDependencies.cmake.in11
3 files changed, 35 insertions, 4 deletions
diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in
index 95fc581993..f2020ec012 100644
--- a/cmake/QtConfig.cmake.in
+++ b/cmake/QtConfig.cmake.in
@@ -60,11 +60,20 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake
endif()
endif()
+set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
+if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
+ set(__qt_use_no_default_path_for_qt_packages "")
+endif()
+
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} ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH
+ PATHS
+ ${_qt_cmake_dir}
+ ${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
+ ${QT_EXAMPLES_CMAKE_PREFIX_PATH}
+ ${__qt_use_no_default_path_for_qt_packages}
)
if (NOT @INSTALL_CMAKE_NAMESPACE@${module}_FOUND)
string(CONFIGURE ${_qt5_module_location_template} _expected_module_location @ONLY)
diff --git a/cmake/QtModuleDependencies.cmake.in b/cmake/QtModuleDependencies.cmake.in
index 24d132b57d..01cf9d5b3c 100644
--- a/cmake/QtModuleDependencies.cmake.in
+++ b/cmake/QtModuleDependencies.cmake.in
@@ -1,7 +1,16 @@
# Make sure @INSTALL_CMAKE_NAMESPACE@ is found before anything else.
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
+
+set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
+if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
+ set(__qt_use_no_default_path_for_qt_packages "")
+endif()
find_dependency(@INSTALL_CMAKE_NAMESPACE@ @PROJECT_VERSION@
- PATHS "${CMAKE_CURRENT_LIST_DIR}/.." ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH
+ PATHS
+ "${CMAKE_CURRENT_LIST_DIR}/.."
+ ${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
+ ${QT_EXAMPLES_CMAKE_PREFIX_PATH}
+ ${__qt_use_no_default_path_for_qt_packages}
)
# note: _third_party_deps example: "ICU\\;FALSE\\;1.0\\;i18n uc data;ZLIB\\;FALSE\\;\\;"
@@ -75,7 +84,11 @@ foreach(_target_dep ${_target_deps})
if (NOT ${pkg}_FOUND)
find_dependency(${pkg} ${version}
- PATHS "${CMAKE_CURRENT_LIST_DIR}/.." ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH
+ PATHS
+ "${CMAKE_CURRENT_LIST_DIR}/.."
+ ${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
+ ${QT_EXAMPLES_CMAKE_PREFIX_PATH}
+ ${__qt_use_no_default_path_for_qt_packages}
)
endif()
endforeach()
diff --git a/cmake/QtPluginDependencies.cmake.in b/cmake/QtPluginDependencies.cmake.in
index 9d16bedeba..42365b4296 100644
--- a/cmake/QtPluginDependencies.cmake.in
+++ b/cmake/QtPluginDependencies.cmake.in
@@ -27,6 +27,11 @@ foreach(_target_dep ${_third_party_deps})
endif()
endforeach()
+set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
+if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
+ set(__qt_use_no_default_path_for_qt_packages "")
+endif()
+
# note: target_deps example: "Qt6Core\;5.12.0;Qt6Gui\;5.12.0"
set(_target_deps "@target_deps@")
foreach(_target_dep ${_target_deps})
@@ -35,7 +40,11 @@ foreach(_target_dep ${_target_deps})
if (NOT ${pkg}_FOUND)
find_dependency(${pkg} ${version}
- PATHS @find_dependency_paths@ ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH
+ PATHS
+ @find_dependency_paths@
+ ${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
+ ${QT_EXAMPLES_CMAKE_PREFIX_PATH}
+ ${__qt_use_no_default_path_for_qt_packages}
)
endif()
endforeach()