From 67567b8e0d15445aef7ce491930a6c1290122fac Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 15 Sep 2020 12:23:51 +0200 Subject: [PATCH] CMake: Conditionally set compiler in generated toolchain file Public consumers of the qt toolchain file will most likely not have their compilers in the same location where they were on the Qt build machine. Only set the compiler paths if none was set already, and the paths actually exist. This seems to become a trend in the generated toolchain file, and is only a stop-gap solution. A proper solution (two different toolchain files) may follow. Task-number: QTBUG-83999 Change-Id: I7a603af447333a45c65b98e299ee109932d16517 Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann --- cmake/QtBaseGlobalTargets.cmake | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index b482c3079f..c5527f5915 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -162,8 +162,15 @@ if(DEFINED QT_EMBED_TOOLCHAIN_COMPILER) endif() endif() if(__qt_embed_toolchain_compilers) - list(APPEND init_platform "set(CMAKE_CXX_COMPILER \"${CMAKE_CXX_COMPILER}\" CACHE STRING \"\")") - list(APPEND init_platform "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\" CACHE STRING \"\")") + list(APPEND init_platform " +set(__qt_initial_c_compiler \"${CMAKE_C_COMPILER}\") +set(__qt_initial_cxx_compiler \"${CMAKE_CXX_COMPILER}\") +if(NOT DEFINED CMAKE_C_COMPILER AND EXISTS \"\${__qt_initial_c_compiler}\") + set(CMAKE_C_COMPILER \"\${__qt_initial_c_compiler}\" CACHE STRING \"\") +endif() +if(NOT DEFINED CMAKE_CXX_COMPILER AND EXISTS \"\${__qt_initial_cxx_compiler}\") + set(CMAKE_CXX_COMPILER \"\${__qt_initial_cxx_compiler}\" CACHE STRING \"\") +endif()") endif() unset(__qt_embed_toolchain_compilers)