From ca59c20939a09587662fa8fecd4e480b68244541 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 4 Nov 2020 14:39:52 +0100 Subject: CMake: Fix usage of cache variables in qt.toolchain.cmake We have some cache variables that are used in our qt.toolchain.cmake toolchain file, for example QT_CHAINLOAD_TOOLCHAIN_FILE. When CMake runs a configure test with try_compile, our toolchain file is included again, but only a restricted set of variables is available. Add the variables that are used in our internal toolchain file to CMAKE_TRY_COMPILE_PLATFORM_VARIABLES. This makes them visible for try_compile calls operating on source files. Also pass the variables via the environment to support try_compile calls that operate on whole projects. Fixes: QTBUG-87873 Change-Id: Iebca9e23686bec5072194b15482e1782b9367a0e Reviewed-by: Alexandru Croitor --- cmake/qt.toolchain.cmake.in | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'cmake/qt.toolchain.cmake.in') 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() -- cgit v1.2.3