Improve support for QT_ADDITIONAL_PACKAGES_PREFIX_PATH

Allow to set QT_ADDITIONAL_PACKAGES_PREFIX_PATH as both an env
variable and CMake cache variable. Also normalize path and list
separators, so that they can be used similar to CMAKE_PREFIX_PATH.

The environment variable is intended to be set by the conan virtualenv
generator, so that e.g.

  find_package(Qt6 COMPONENTS NetworkAuth REQUIRED)

also works if NetworkAuth is not installed into the Qt prefix.

Pick-to: 6.1
Fixes: QTBUG-91142
Change-Id: Ia9f9b9fa2b1b051d33073629139640d0f4c7a843
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Craig Scott <craig.scott@qt.io>
This commit is contained in:
Kai Köhne 2021-02-24 16:07:37 +01:00
parent 65c6fbea24
commit 5bbd700124
3 changed files with 12 additions and 4 deletions

View File

@ -46,6 +46,10 @@ if(APPLE AND (NOT CMAKE_SYSTEM_NAME OR CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/macos")
endif()
set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING "Additional directories where find(Qt6 ...) components are searched")
file(TO_CMAKE_PATH "${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}" _qt_additional_packages_prefix_path)
file(TO_CMAKE_PATH "$ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH}" _qt_additional_packages_prefix_path_env)
# Find required dependencies, if any.
include(CMakeFindDependencyMacro)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake")
@ -68,7 +72,8 @@ foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS})
${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_REQUIRED}
PATHS
${_qt_cmake_dir}
${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
${_qt_additional_packages_prefix_path}
${_qt_additional_packages_prefix_path_env}
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
${__qt_use_no_default_path_for_qt_packages}
)

View File

@ -8,7 +8,8 @@ endif()
find_dependency(@INSTALL_CMAKE_NAMESPACE@ @PROJECT_VERSION@
PATHS
"${CMAKE_CURRENT_LIST_DIR}/.."
${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
${_qt_additional_packages_prefix_path}
${_qt_additional_packages_prefix_path_env}
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
${__qt_use_no_default_path_for_qt_packages}
)
@ -86,7 +87,8 @@ foreach(_target_dep ${_target_deps})
find_dependency(${pkg} ${version}
PATHS
"${CMAKE_CURRENT_LIST_DIR}/.."
${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
${_qt_additional_packages_prefix_path}
${_qt_additional_packages_prefix_path_env}
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
${__qt_use_no_default_path_for_qt_packages}
)

View File

@ -42,7 +42,8 @@ foreach(_target_dep ${_target_deps})
find_dependency(${pkg} ${version}
PATHS
@find_dependency_paths@
${QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
${_qt_additional_packages_prefix_path}
${_qt_additional_packages_prefix_path_env}
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
${__qt_use_no_default_path_for_qt_packages}
)