summaryrefslogtreecommitdiffstats
path: root/cmake/qt.toolchain.cmake.in
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/qt.toolchain.cmake.in')
-rw-r--r--cmake/qt.toolchain.cmake.in89
1 files changed, 79 insertions, 10 deletions
diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in
index 49553c9bbf..15cf7a432e 100644
--- a/cmake/qt.toolchain.cmake.in
+++ b/cmake/qt.toolchain.cmake.in
@@ -2,7 +2,9 @@ set(__qt_toolchain_used_variables
QT_CHAINLOAD_TOOLCHAIN_FILE
QT_TOOLCHAIN_INCLUDE_FILE
QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR
- QT_TOOLCHAIN_RELOCATABLE_PREFIX)
+ QT_TOOLCHAIN_RELOCATABLE_PREFIX
+ QT_ADDITIONAL_PACKAGES_PREFIX_PATH
+)
@init_additional_used_variables@
# Make cache variables used by this toolchain file available to the
@@ -19,8 +21,6 @@ if($ENV{_QT_TOOLCHAIN_VARS_INITIALIZED})
endforeach()
endif()
-@init_qt_host_path@
-@init_qt_host_path_cmake_dir@
@init_original_toolchain_file@
@init_vcpkg@
@@ -34,7 +34,7 @@ if(__qt_chainload_toolchain_file)
"${__qt_chainload_toolchain_file}" REALPATH)
if(__qt_chainload_toolchain_file_real_path STREQUAL CMAKE_CURRENT_LIST_FILE)
message(FATAL_ERROR
- "Woah, the Qt toolchain file tried to include itself recusively! '${__qt_chainload_toolchain_file}' "
+ "Woah, the Qt toolchain file tried to include itself recursively! '${__qt_chainload_toolchain_file}' "
"Make sure to remove qtbase/CMakeCache.txt and reconfigure qtbase with 'cmake' "
"rather than 'qt-cmake', and then you can reconfigure your own project."
)
@@ -43,10 +43,13 @@ if(__qt_chainload_toolchain_file)
"'${__qt_chainload_toolchain_file}' does not exist.")
else()
include("${__qt_chainload_toolchain_file}")
+ set(__qt_chainload_toolchain_file_included TRUE)
endif()
unset(__qt_chainload_toolchain_file)
endif()
+@init_post_chainload_toolchain@
+
# Compute dynamically the Qt installation prefix from the location of this file. This allows
# the usage of the toolchain file when the Qt installation is relocated.
get_filename_component(QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX
@@ -58,15 +61,75 @@ get_filename_component(QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX
# one level higher is what we're looking for.
get_filename_component(QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
+# REROOT_PATH_ISSUE_MARKER
# There's a subdirectory check in cmake's cmFindCommon::RerootPaths() function, that doesn't handle
# the case of CMAKE_PREFIX_PATH == CMAKE_FIND_ROOT_PATH for a particular pair of entries.
# Instead of collapsing the search prefix (which is the case when one is a subdir of the other),
# it concatenates them creating an invalid path. Workaround it by setting the root path to the
# Qt install prefix, and the prefix path to the lib/cmake subdir.
-set(CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR};${CMAKE_PREFIX_PATH}")
-set(CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX};${CMAKE_FIND_ROOT_PATH}")
+list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}")
+list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}")
+
+# Let CMake load our custom platform modules.
+# CMake-provided platform modules take precedence.
+if(NOT QT_AVOID_CUSTOM_PLATFORM_MODULES)
+ list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/platforms")
+endif()
+
+# Handle packages located in QT_ADDITIONAL_PACKAGES_PREFIX_PATH when cross-compiling. Needed for
+# Conan.
+# 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 ensure the package is found.
+# See 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 "")
+if(QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
+ list(APPEND __qt_toolchain_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 "")
+ set(__qt_env_additional_packages_prefixes $ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH})
+ if(NOT CMAKE_HOST_WIN32)
+ string(REPLACE ":" ";" __qt_env_additional_packages_prefixes
+ "${__qt_env_additional_packages_prefixes}")
+ endif()
+ list(APPEND __qt_toolchain_additional_packages_prefixes
+ ${__qt_env_additional_packages_prefixes})
+ unset(__qt_env_additional_packages_prefixes)
+endif()
-@init_qt_host_path_checks@
+if(__qt_toolchain_additional_packages_prefixes)
+ set(__qt_toolchain_additional_packages_root_paths "")
+ set(__qt_toolchain_additional_packages_prefix_paths "")
+
+ foreach(__qt_additional_path IN LISTS __qt_toolchain_additional_packages_prefixes)
+ file(TO_CMAKE_PATH "${__qt_additional_path}" __qt_additional_path)
+ get_filename_component(__qt_additional_path "${__qt_additional_path}" ABSOLUTE)
+ set(__qt_additional_path_lib_cmake "${__qt_additional_path}")
+ if(NOT __qt_additional_path_lib_cmake MATCHES "/lib/cmake$")
+ string(APPEND __qt_additional_path_lib_cmake "/lib/cmake")
+ endif()
+
+ list(APPEND __qt_toolchain_additional_packages_root_paths
+ "${__qt_additional_path}")
+ list(APPEND __qt_toolchain_additional_packages_prefix_paths
+ "${__qt_additional_path_lib_cmake}")
+ endforeach()
+ list(PREPEND CMAKE_PREFIX_PATH ${__qt_toolchain_additional_packages_prefix_paths})
+ list(PREPEND CMAKE_FIND_ROOT_PATH ${__qt_toolchain_additional_packages_root_paths})
+
+ unset(__qt_additional_path)
+ unset(__qt_additional_path_lib_cmake)
+ unset(__qt_toolchain_additional_packages_root_paths)
+ unset(__qt_toolchain_additional_packages_prefix_paths)
+endif()
+unset(__qt_toolchain_additional_packages_prefixes)
# Allow customization of the toolchain file by placing an additional file next to it.
set(__qt_toolchain_extra_file "${CMAKE_CURRENT_LIST_DIR}/qt.toolchain.extra.cmake")
@@ -87,10 +150,16 @@ if(QT_TOOLCHAIN_INCLUDE_FILE)
endif()
endif()
+# Store initial build type (if any is specified) to be read by QtBuildInternals.cmake when building
+# a Qt repo, standalone tests or a single test.
+if(DEFINED CACHE{CMAKE_BUILD_TYPE})
+ set(__qt_toolchain_cmake_build_type_before_project_call "${CMAKE_BUILD_TYPE}")
+endif()
+
# Compile tests only see a restricted set of variables.
-# All cache variables, this toolchain file uses, must be made available to compile tests,
-# because this toolchain file will be included there too.
-if(NOT ENV{_QT_TOOLCHAIN_VARS_INITIALIZED})
+# All cache variables, this toolchain file uses, must be made available to project-based
+# try_compile tests because this toolchain file will be included there too.
+if(NOT "$ENV{_QT_TOOLCHAIN_VARS_INITIALIZED}")
set(ENV{_QT_TOOLCHAIN_VARS_INITIALIZED} ON)
foreach(var ${__qt_toolchain_used_variables})
set(ENV{_QT_TOOLCHAIN_${var}} "${${var}}")