diff options
-rw-r--r-- | cmake/QtToolchainHelpers.cmake | 8 | ||||
-rw-r--r-- | cmake/qt.toolchain.cmake.in | 31 |
2 files changed, 39 insertions, 0 deletions
diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake index 2593aa7429..a0897696bd 100644 --- a/cmake/QtToolchainHelpers.cmake +++ b/cmake/QtToolchainHelpers.cmake @@ -95,6 +95,7 @@ function(qt_internal_create_toolchain_file) endif()") endif() + unset(init_additional_used_variables) if(APPLE) # For simulator_and_device build, we should not explicitly set the sysroot. list(LENGTH CMAKE_OSX_ARCHITECTURES _qt_osx_architectures_count) @@ -125,6 +126,11 @@ function(qt_internal_create_toolchain_file) list(APPEND init_platform "endif()") endif() elseif(ANDROID) + foreach(var ANDROID_NATIVE_API_LEVEL ANDROID_STL ANDROID_ABI + ANDROID_SDK_ROOT ANDROID_NDK_ROOT) + list(APPEND init_additional_used_variables + "list(APPEND __qt_toolchain_used_variables ${var})") + endforeach() list(APPEND init_platform "set(ANDROID_NATIVE_API_LEVEL \"${ANDROID_NATIVE_API_LEVEL}\" CACHE STRING \"\")") list(APPEND init_platform "set(ANDROID_STL \"${ANDROID_STL}\" CACHE STRING \"\")") @@ -151,6 +157,8 @@ function(qt_internal_create_toolchain_file) list(APPEND init_platform "endif()") endif() + string(REPLACE ";" "\n" init_additional_used_variables + "${init_additional_used_variables}") string(REPLACE ";" "\n" init_vcpkg "${init_vcpkg}") string(REPLACE ";" "\n" init_platform "${init_platform}") string(REPLACE "LITERAL_SEMICOLON" ";" init_platform "${init_platform}") diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in index e97e46879d..cdd2813f8b 100644 --- a/cmake/qt.toolchain.cmake.in +++ b/cmake/qt.toolchain.cmake.in @@ -1,3 +1,24 @@ +set(__qt_toolchain_used_variables + QT_CHAINLOAD_TOOLCHAIN_FILE + QT_TOOLCHAIN_INCLUDE_FILE + QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR + QT_TOOLCHAIN_RELOCATABLE_PREFIX) +@init_additional_used_variables@ + +# Make cache variables used by this toolchain file available to the +# try_compile command that operates on sources files. +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ${__qt_toolchain_used_variables}) +list(REMOVE_DUPLICATES CMAKE_TRY_COMPILE_PLATFORM_VARIABLES) + +# Turn the environment variables that are created at the end of this +# file into proper variables. This is needed for try_compile calls +# that operate on whole projects. +if($ENV{_QT_TOOLCHAIN_VARS_INITIALIZED}) + foreach(var ${__qt_toolchain_used_variables}) + set(${var} "$ENV{_QT_TOOLCHAIN_${var}}") + endforeach() +endif() + @init_qt_host_path@ @init_qt_host_path_cmake_dir@ @init_original_toolchain_file@ @@ -64,3 +85,13 @@ if(QT_TOOLCHAIN_INCLUDE_FILE) "${__qt_toolchain_include_file_real_path}") endif() 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}) + set(ENV{_QT_TOOLCHAIN_VARS_INITIALIZED} ON) + foreach(var ${__qt_toolchain_used_variables}) + set(ENV{_QT_TOOLCHAIN_${var}} "${${var}}") + endforeach() +endif() |