CMake: Introduce QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH
When installing conan packages we have one installation prefix per package. When cross-building a conan package, we need to make known those multiple host prefixes to Qt, analogous to QT_ADDITIONAL_PACKAGES_PREFIX_PATH. Pick-to: 6.2 6.3 Fixes: QTBUG-94524 Change-Id: I68cbede350f95266a5fd3559e9b9c214c5858eed Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
d08f59d083
commit
e044c94a61
@ -49,23 +49,30 @@ endif()
|
|||||||
|
|
||||||
set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING
|
set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING
|
||||||
"Additional directories where find(Qt6 ...) components are searched")
|
"Additional directories where find(Qt6 ...) components are searched")
|
||||||
|
set(QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH "" CACHE STRING
|
||||||
|
"Additional directories where find(Qt6 ...) host Qt components are searched")
|
||||||
|
|
||||||
# Collect additional package prefix paths to look for Qt packages, both from command line and the
|
# Collect additional package prefix paths to look for Qt packages, both from command line and the
|
||||||
# env variable.
|
# env variable ${prefixes_var}. The result is stored in ${out_var} and is a list of paths ending
|
||||||
if(NOT DEFINED _qt_additional_packages_prefix_paths)
|
# with "/lib/cmake".
|
||||||
set(_qt_additional_packages_prefix_paths "")
|
function(__qt_internal_collect_additional_prefix_paths out_var prefixes_var)
|
||||||
|
if(DEFINED "${out_var}")
|
||||||
set(_qt_additional_packages_prefixes "")
|
return()
|
||||||
if(QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
|
|
||||||
list(APPEND _qt_additional_packages_prefixes ${QT_ADDITIONAL_PACKAGES_PREFIX_PATH})
|
|
||||||
endif()
|
|
||||||
if(DEFINED ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
|
|
||||||
AND NOT "$ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH}" STREQUAL "")
|
|
||||||
list(APPEND _qt_additional_packages_prefixes $ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH})
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(_qt_additional_path IN LISTS _qt_additional_packages_prefixes)
|
set(additional_packages_prefix_paths "")
|
||||||
file(TO_CMAKE_PATH "${_qt_additional_path}" _qt_additional_path)
|
|
||||||
|
set(additional_packages_prefixes "")
|
||||||
|
if(${prefixes_var})
|
||||||
|
list(APPEND additional_packages_prefixes ${${prefixes_var}})
|
||||||
|
endif()
|
||||||
|
if(DEFINED ENV{${prefixes_var}}
|
||||||
|
AND NOT "$ENV{${prefixes_var}}" STREQUAL "")
|
||||||
|
list(APPEND additional_packages_prefixes $ENV{${prefixes_var}})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(additional_path IN LISTS additional_packages_prefixes)
|
||||||
|
file(TO_CMAKE_PATH "${additional_path}" additional_path)
|
||||||
|
|
||||||
# The prefix paths need to end with lib/cmake to ensure the packages are found when
|
# The prefix paths need to end with lib/cmake to ensure the packages are found when
|
||||||
# cross compiling. Search for REROOT_PATH_ISSUE_MARKER in the qt.toolchain.cmake file for
|
# cross compiling. Search for REROOT_PATH_ISSUE_MARKER in the qt.toolchain.cmake file for
|
||||||
@ -74,14 +81,36 @@ if(NOT DEFINED _qt_additional_packages_prefix_paths)
|
|||||||
# NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH values are discarded.
|
# NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH values are discarded.
|
||||||
# CMAKE_FIND_ROOT_PATH values are not discarded and togegher with the PATHS option, it
|
# CMAKE_FIND_ROOT_PATH values are not discarded and togegher with the PATHS option, it
|
||||||
# ensures packages from additional prefixes are found.
|
# ensures packages from additional prefixes are found.
|
||||||
if(NOT _qt_additional_path MATCHES "/lib/cmake$")
|
if(NOT additional_path MATCHES "/lib/cmake$")
|
||||||
string(APPEND _qt_additional_path "/lib/cmake")
|
string(APPEND additional_path "/lib/cmake")
|
||||||
endif()
|
endif()
|
||||||
list(APPEND _qt_additional_packages_prefix_paths "${_qt_additional_path}")
|
list(APPEND additional_packages_prefix_paths "${additional_path}")
|
||||||
endforeach()
|
endforeach()
|
||||||
unset(_qt_additional_path)
|
|
||||||
unset(_qt_additional_packages_prefixes)
|
set("${out_var}" "${additional_packages_prefix_paths}" PARENT_SCOPE)
|
||||||
endif()
|
endfunction()
|
||||||
|
|
||||||
|
__qt_internal_collect_additional_prefix_paths(_qt_additional_packages_prefix_paths
|
||||||
|
QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
|
||||||
|
__qt_internal_collect_additional_prefix_paths(_qt_additional_host_packages_prefix_paths
|
||||||
|
QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH)
|
||||||
|
|
||||||
|
# Take a list of prefix paths ending with "/lib/cmake", and return a list of absolute paths with
|
||||||
|
# "/lib/cmake" removed.
|
||||||
|
function(__qt_internal_prefix_paths_to_roots out_var prefix_paths)
|
||||||
|
set(result "")
|
||||||
|
foreach(path IN LISTS prefix_paths)
|
||||||
|
if(path MATCHES "/lib/cmake$")
|
||||||
|
string(APPEND path "/../..")
|
||||||
|
endif()
|
||||||
|
get_filename_component(path "${path}" ABSOLUTE)
|
||||||
|
list(APPEND result "${path}")
|
||||||
|
endforeach()
|
||||||
|
set("${out_var}" "${result}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
__qt_internal_prefix_paths_to_roots(_qt_additional_host_packages_root_paths
|
||||||
|
"${_qt_additional_host_packages_prefix_paths}")
|
||||||
|
|
||||||
# Public helpers available to all Qt packages.
|
# Public helpers available to all Qt packages.
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/QtFeature.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/QtFeature.cmake")
|
||||||
@ -143,14 +172,14 @@ foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS})
|
|||||||
# Make sure that a Qt*Tools package is also looked up in QT_HOST_PATH.
|
# Make sure that a Qt*Tools package is also looked up in QT_HOST_PATH.
|
||||||
# But don't match QtShaderTools and QtTools which are cross-compiled target package names.
|
# But don't match QtShaderTools and QtTools which are cross-compiled target package names.
|
||||||
# Allow opt out just in case.
|
# Allow opt out just in case.
|
||||||
# TODO: Handle a hypothetical QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH
|
|
||||||
# See QTBUG-94524
|
|
||||||
get_filename_component(__qt_find_package_host_qt_path
|
get_filename_component(__qt_find_package_host_qt_path
|
||||||
"${Qt@PROJECT_VERSION_MAJOR@HostInfo_DIR}/.." ABSOLUTE)
|
"${Qt@PROJECT_VERSION_MAJOR@HostInfo_DIR}/.." ABSOLUTE)
|
||||||
set(__qt_backup_cmake_prefix_path "${CMAKE_PREFIX_PATH}")
|
set(__qt_backup_cmake_prefix_path "${CMAKE_PREFIX_PATH}")
|
||||||
set(__qt_backup_cmake_find_root_path "${CMAKE_FIND_ROOT_PATH}")
|
set(__qt_backup_cmake_find_root_path "${CMAKE_FIND_ROOT_PATH}")
|
||||||
list(PREPEND CMAKE_PREFIX_PATH "${__qt_find_package_host_qt_path}")
|
list(PREPEND CMAKE_PREFIX_PATH "${__qt_find_package_host_qt_path}"
|
||||||
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}")
|
${_qt_additional_host_packages_prefix_paths})
|
||||||
|
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}"
|
||||||
|
${_qt_additional_host_packages_root_paths})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(@INSTALL_CMAKE_NAMESPACE@${module}
|
find_package(@INSTALL_CMAKE_NAMESPACE@${module}
|
||||||
@ -161,6 +190,7 @@ foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS})
|
|||||||
${_qt_additional_packages_prefix_paths}
|
${_qt_additional_packages_prefix_paths}
|
||||||
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
|
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
|
||||||
${__qt_find_package_host_qt_path}
|
${__qt_find_package_host_qt_path}
|
||||||
|
${_qt_additional_host_packages_prefix_paths}
|
||||||
${__qt_use_no_default_path_for_qt_packages}
|
${__qt_use_no_default_path_for_qt_packages}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
# Make sure @INSTALL_CMAKE_NAMESPACE@ is found before anything else.
|
# Make sure @INSTALL_CMAKE_NAMESPACE@ is found before anything else.
|
||||||
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
|
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
|
||||||
|
|
||||||
|
if("${_qt_cmake_dir}" STREQUAL "")
|
||||||
|
set(_qt_cmake_dir "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}")
|
||||||
|
endif()
|
||||||
set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
|
set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
|
||||||
if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
|
if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
|
||||||
set(__qt_use_no_default_path_for_qt_packages "")
|
set(__qt_use_no_default_path_for_qt_packages "")
|
||||||
@ -53,8 +56,10 @@ if(__qt_@target@_tool_deps AND NOT "${QT_HOST_PATH}" STREQUAL "")
|
|||||||
# Make sure that the tools find the host tools first
|
# Make sure that the tools find the host tools first
|
||||||
set(BACKUP_@target@_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH})
|
set(BACKUP_@target@_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH})
|
||||||
set(BACKUP_@target@_CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH})
|
set(BACKUP_@target@_CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH})
|
||||||
list(PREPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH_CMAKE_DIR}")
|
list(PREPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH_CMAKE_DIR}"
|
||||||
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}")
|
"${_qt_additional_host_packages_prefix_paths}")
|
||||||
|
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}"
|
||||||
|
"${_qt_additional_host_packages_root_paths}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(__qt_@target@_target_dep ${__qt_@target@_tool_deps})
|
foreach(__qt_@target@_target_dep ${__qt_@target@_tool_deps})
|
||||||
|
@ -123,6 +123,19 @@ function(qt_internal_add_tool target_name)
|
|||||||
"Neither QT_HOST_PATH_CMAKE_DIR nor "
|
"Neither QT_HOST_PATH_CMAKE_DIR nor "
|
||||||
"Qt${PROJECT_VERSION_MAJOR}HostInfo_DIR} available.")
|
"Qt${PROJECT_VERSION_MAJOR}HostInfo_DIR} available.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Look for tools in additional host Qt installations. This is done for conan support where
|
||||||
|
# we have separate installation prefixes per package. For simplicity, we assume here that
|
||||||
|
# all host Qt installations use the same value of INSTALL_LIBDIR.
|
||||||
|
if(DEFINED QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH)
|
||||||
|
file(RELATIVE_PATH rel_host_cmake_dir "${QT_HOST_PATH}" "${QT_HOST_PATH_CMAKE_DIR}")
|
||||||
|
foreach(host_path IN LISTS QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH)
|
||||||
|
set(host_cmake_dir "${host_path}/${rel_host_cmake_dir}")
|
||||||
|
list(PREPEND CMAKE_PREFIX_PATH "${host_cmake_dir}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH}")
|
||||||
|
endif()
|
||||||
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}")
|
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}")
|
||||||
|
|
||||||
find_package(
|
find_package(
|
||||||
|
@ -81,9 +81,14 @@ endif()
|
|||||||
# Handle packages located in QT_ADDITIONAL_PACKAGES_PREFIX_PATH when cross-compiling. Needed for
|
# Handle packages located in QT_ADDITIONAL_PACKAGES_PREFIX_PATH when cross-compiling. Needed for
|
||||||
# Conan.
|
# Conan.
|
||||||
# We prepend to CMAKE_PREFIX_PATH so that a find_package(Qt6Foo) call works, without having to go
|
# We prepend to CMAKE_PREFIX_PATH so that a find_package(Qt6Foo) call works, without having to go
|
||||||
# through the Qt6 umbrella package. The paths must end in lib/cmake to esnsure the package is found.
|
# through the Qt6 umbrella package. The paths must end in lib/cmake to ensure the package is found.
|
||||||
# See REROOT_PATH_ISSUE_MARKER.
|
# See REROOT_PATH_ISSUE_MARKER.
|
||||||
# We prepend to CMAKE_FIND_ROOT_PATH, due to the bug mentioned at REROOT_PATH_ISSUE_MARKER.
|
# We prepend to CMAKE_FIND_ROOT_PATH, due to the bug mentioned at REROOT_PATH_ISSUE_MARKER.
|
||||||
|
#
|
||||||
|
# Note that we don't handle QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH here, because we would thwart
|
||||||
|
# our efforts to not accidentally pick up host packages. For now, we say that
|
||||||
|
# find_package(Qt6FooTools) is not supported, and people must use find_package(Qt6 COMPONENTS
|
||||||
|
# FooTools) instead.
|
||||||
set(__qt_toolchain_additional_packages_prefixes "")
|
set(__qt_toolchain_additional_packages_prefixes "")
|
||||||
if(QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
|
if(QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
|
||||||
list(APPEND __qt_toolchain_additional_packages_prefixes
|
list(APPEND __qt_toolchain_additional_packages_prefixes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user