From a6a3b82ffb3d7f1ea13293206401ed360a51e9cd Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 7 Sep 2020 17:48:56 +0200 Subject: [PATCH] CMake: Make generated Qt toolchain file a bit more relocatable Rather than force setting the apple sysroot and Qt host paths, first check if they are not already defined on the command line and if they aren't, check that the paths with which Qt was configured exist. The goal of the patch is to not set invalid paths, like when using a Qt built in the CI, which will have a different host path / sysroot compared to what a user has locally. Task-number: QTBUG-85240 Change-Id: Ic37566b4fa845d8d1b4e4b5ba7fa4be769e99ca8 Reviewed-by: Cristian Adam --- cmake/QtBaseGlobalTargets.cmake | 18 +++++++++++++++--- cmake/qt.toolchain.cmake.in | 4 ---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index c6104f0b49c..975defcb836 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -94,11 +94,19 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS if(QT_HOST_PATH) get_filename_component(init_qt_host_path "${QT_HOST_PATH}" ABSOLUTE) # TODO: Figure out how to make these relocatable. - set(init_qt_host_path "set(QT_HOST_PATH \"${init_qt_host_path}\" CACHE PATH \"\" FORCE)") + set(init_qt_host_path " +set(__qt_initial_qt_host_path \"${QT_HOST_PATH}\") +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()") get_filename_component(QT_HOST_PATH_CMAKE_DIR "${Qt${PROJECT_VERSION_MAJOR}HostInfo_DIR}/.." ABSOLUTE) set(init_qt_host_path_cmake_dir - "set(QT_HOST_PATH_CMAKE_DIR \"${QT_HOST_PATH_CMAKE_DIR}\" CACHE PATH \"\" FORCE)") + " +set(__qt_initial_qt_host_path_cmake_dir \"${QT_HOST_PATH}\") +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()") endif() if(CMAKE_TOOLCHAIN_FILE) @@ -160,7 +168,11 @@ if(APPLE) # For simulator_and_device build, we should not explicitly set the sysroot. list(LENGTH CMAKE_OSX_ARCHITECTURES _qt_osx_architectures_count) if(CMAKE_OSX_SYSROOT AND NOT _qt_osx_architectures_count GREATER 1 AND UIKIT) - list(APPEND init_platform "set(CMAKE_OSX_SYSROOT \"${CMAKE_OSX_SYSROOT}\" CACHE PATH \"\")") + list(APPEND init_platform " +set(__qt_initial_cmake_osx_sysroot \"${CMAKE_OSX_SYSROOT}\") +if(NOT DEFINED CMAKE_OSX_SYSROOT AND EXISTS \"\${__qt_initial_cmake_osx_sysroot}\") + set(CMAKE_OSX_SYSROOT \"\${__qt_initial_cmake_osx_sysroot}\" CACHE PATH \"\") +endif()") endif() unset(_qt_osx_architectures_count) diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in index c4884e9dfa3..8a2db98f28f 100644 --- a/cmake/qt.toolchain.cmake.in +++ b/cmake/qt.toolchain.cmake.in @@ -2,11 +2,8 @@ @init_qt_host_path@ @init_qt_host_path_cmake_dir@ - @init_original_toolchain_file@ - @init_vcpkg@ - if(__qt_chainload_toolchain_file) get_filename_component(__qt_chainload_toolchain_file_real_path "${__qt_chainload_toolchain_file}" REALPATH) @@ -40,4 +37,3 @@ get_filename_component(QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR "${CMAKE_CURRENT_LIST_ # Qt install prefix, and the prefix path to the lib/cmake subdir. list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}") list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}") -