summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmake/QtToolchainHelpers.cmake35
-rw-r--r--cmake/qt.toolchain.cmake.in65
2 files changed, 71 insertions, 29 deletions
diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake
index e7bf2eda56..de8c1e8f52 100644
--- a/cmake/QtToolchainHelpers.cmake
+++ b/cmake/QtToolchainHelpers.cmake
@@ -2,32 +2,19 @@
# as well as CMake application projects.
# Expects various global variables to be set.
function(qt_internal_create_toolchain_file)
- if(NOT "${QT_HOST_PATH}" STREQUAL "")
- # TODO: Figure out how to make these relocatable.
-
- get_filename_component(__qt_host_path_absolute "${QT_HOST_PATH}" ABSOLUTE)
- set(init_qt_host_path "
- set(__qt_initial_qt_host_path \"${__qt_host_path_absolute}\")
- if(NOT DEFINED QT_HOST_PATH AND EXISTS \"\${__qt_initial_qt_host_path}\")
- set(QT_HOST_PATH \"\${__qt_initial_qt_host_path}\" CACHE PATH \"\" FORCE)
- endif()")
+ set(qt_host_path_required FALSE)
- get_filename_component(__qt_host_path_cmake_dir_absolute
+ if(NOT "${QT_HOST_PATH}" STREQUAL "")
+ # If a QT_HOST_PATH is provided when configuring qtbase, we assume it's a cross build
+ # and thus we require the QT_HOST_PATH to be provided also when using the cross-built Qt.
+ # This tells the Qt toolchain file to do appropriate requirement checks.
+ set(qt_host_path_required TRUE)
+
+ # TODO: Figure out how to make the initial QT_HOST_PATH var relocatable in relation
+ # to the target CMAKE_INSTALL_DIR, if at all possible to do so in a reliable way.
+ get_filename_component(qt_host_path_absolute "${QT_HOST_PATH}" ABSOLUTE)
+ get_filename_component(qt_host_path_cmake_dir_absolute
"${Qt${PROJECT_VERSION_MAJOR}HostInfo_DIR}/.." ABSOLUTE)
- set(init_qt_host_path_cmake_dir
- "
- set(__qt_initial_qt_host_path_cmake_dir \"${__qt_host_path_cmake_dir_absolute}\")
- if(NOT DEFINED QT_HOST_PATH_CMAKE_DIR AND EXISTS \"\${__qt_initial_qt_host_path_cmake_dir}\")
- set(QT_HOST_PATH_CMAKE_DIR \"\${__qt_initial_qt_host_path_cmake_dir}\" CACHE PATH \"\" FORCE)
- endif()")
-
- set(init_qt_host_path_checks "
- if(\"\${QT_HOST_PATH}\" STREQUAL \"\" OR NOT EXISTS \"\${QT_HOST_PATH}\")
- message(FATAL_ERROR \"To use a cross-compiled Qt, please specify a path to a host Qt installation by setting the QT_HOST_PATH cache variable.\")
- endif()
- if(\"\${QT_HOST_PATH_CMAKE_DIR}\" STREQUAL \"\" OR NOT EXISTS \"\${QT_HOST_PATH_CMAKE_DIR}\")
- message(FATAL_ERROR \"To use a cross-compiled Qt, please specify a path to a host Qt installation CMake directory by setting the QT_HOST_PATH_CMAKE_DIR cache variable.\")
- endif()")
endif()
if(CMAKE_TOOLCHAIN_FILE)
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.