summaryrefslogtreecommitdiffstats
path: root/cmake/qt.toolchain.cmake.in
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-10-20 15:46:50 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-10-29 15:34:12 +0200
commit102c1cff72b01b8972e4e5f63bce9616e95dc213 (patch)
treea06957c49912777cbeaa980748887868e5c67ef0 /cmake/qt.toolchain.cmake.in
parentc82bca9efe79a4913499d08d2bc814cb32cfcef9 (diff)
CMake: Clean up and improve QT_HOST_PATH_CMAKE_DIR computation
Previously when one wanted to use a cross-compiled Qt with a host Qt installed in a non-default location, they'd have to provide both QT_HOST_PATH and QT_HOST_PATH_CMAKE_DIR. This change will now try to first check if ${QT_HOST_PATH}/lib/cmake is a valid path on disk and use that. This is nicer to the user because they don't need to specify 2 paths anymore. Furthermore the path computation and sanity checks are now done after any extra toolchain cmake files are loaded, to give an opportunity to the files to set the paths first. Finally, both variables need to be added to __qt_toolchain_used_variables so they are passed along to try_compile calls if the variables are specified manually. Otherwise when the toolchain file is loaded by a try_compile project, it will error out saying no host path found (as long as the initial paths embedded in the toolchain are invalid). Amends 93fc3afe71467ca6aeffa41d7a6f4a170f82b62e and ec90f9013b4c6b63d7e03a964f66f97329be7885 Pick-to: 6.2 Change-Id: I433239b36b084f2d0a7a0dd043fdf87d77c138f3 Reviewed-by: Craig Scott <craig.scott@qt.io>
Diffstat (limited to 'cmake/qt.toolchain.cmake.in')
-rw-r--r--cmake/qt.toolchain.cmake.in65
1 files changed, 60 insertions, 5 deletions
diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in
index 79a37fd95a..d5fc183c74 100644
--- a/cmake/qt.toolchain.cmake.in
+++ b/cmake/qt.toolchain.cmake.in
@@ -2,7 +2,10 @@ 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_HOST_PATH
+ QT_HOST_PATH_CMAKE_DIR
+)
@init_additional_used_variables@
# Make cache variables used by this toolchain file available to the
@@ -19,8 +22,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@
@@ -120,8 +121,6 @@ if(__qt_toolchain_additional_packages_prefixes)
endif()
unset(__qt_toolchain_additional_packages_prefixes)
-@init_qt_host_path_checks@
-
# 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")
if(EXISTS "${__qt_toolchain_extra_file}")
@@ -141,6 +140,62 @@ if(QT_TOOLCHAIN_INCLUDE_FILE)
endif()
endif()
+# Set up QT_HOST_PATH and do sanity checks.
+# A host path is required when cross-compiling but optional when doing a native build.
+set(__qt_toolchain_host_path_required "@qt_host_path_required@")
+set(__qt_toolchain_initial_qt_host_path
+ "@qt_host_path_absolute@")
+set(__qt_toolchain_initial_qt_host_path_cmake_dir
+ "@qt_host_path_cmake_dir_absolute@")
+
+# Prefer initially configured path if none was explicitly set.
+if(NOT DEFINED QT_HOST_PATH AND __qt_toolchain_initial_qt_host_path
+ AND EXISTS "${__qt_toolchain_initial_qt_host_path}")
+ set(QT_HOST_PATH "${__qt_toolchain_initial_qt_host_path}" CACHE PATH "")
+endif()
+
+if(NOT QT_HOST_PATH STREQUAL "")
+ get_filename_component(__qt_toolchain_host_path_absolute "${QT_HOST_PATH}" ABSOLUTE)
+endif()
+
+if(__qt_toolchain_host_path_required AND
+ ("${QT_HOST_PATH}" STREQUAL "" OR NOT EXISTS "${__qt_toolchain_host_path_absolute}"))
+ message(FATAL_ERROR
+ "To use a cross-compiled Qt, please set the QT_HOST_PATH cache variable to the location "
+ "of your host Qt installation.")
+endif()
+
+# QT_HOST_PATH_CMAKE_DIR is needed to work around the rerooting issue when looking for host tools
+# See REROOT_PATH_ISSUE_MARKER.
+# Prefer initially configured path if none was explicitly set.
+if(__qt_toolchain_host_path_required AND NOT DEFINED QT_HOST_PATH_CMAKE_DIR)
+ if(__qt_toolchain_initial_qt_host_path_cmake_dir
+ AND EXISTS "${__qt_toolchain_initial_qt_host_path_cmake_dir}")
+ set(QT_HOST_PATH_CMAKE_DIR "${__qt_toolchain_initial_qt_host_path_cmake_dir}" CACHE PATH "")
+ else()
+ # First try to auto-compute the location instead of requiring to set QT_HOST_PATH_CMAKE_DIR
+ # explicitly.
+ set(__qt_candidate_host_path_cmake_dir "${QT_HOST_PATH}/lib/cmake")
+ if(__qt_candidate_host_path_cmake_dir AND EXISTS "${__qt_candidate_host_path_cmake_dir}")
+ set(QT_HOST_PATH_CMAKE_DIR
+ "${__qt_candidate_host_path_cmake_dir}" CACHE PATH "")
+ endif()
+ endif()
+endif()
+
+if(NOT QT_HOST_PATH_CMAKE_DIR STREQUAL "")
+ get_filename_component(__qt_toolchain_host_path_cmake_dir_absolute
+ "${QT_HOST_PATH_CMAKE_DIR}" ABSOLUTE)
+endif()
+
+if(__qt_toolchain_host_path_required AND
+ ("${QT_HOST_PATH_CMAKE_DIR}" STREQUAL ""
+ OR NOT EXISTS "${__qt_toolchain_host_path_cmake_dir_absolute}"))
+ message(FATAL_ERROR
+ "To use a cross-compiled Qt, please set the QT_HOST_PATH_CMAKE_DIR cache variable to "
+ "the location of your host Qt installation lib/cmake directory.")
+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.