From 58187aa14f940683a017b6e5f0f10f1d17f64fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6hne?= Date: Tue, 23 May 2023 10:56:36 +0200 Subject: [PATCH] CMake: Use stored compiler only for qt-cmake-private Change the heuristic only to use the stored compiler if we are building qt itself, like with qt-cmake-private / qt-configure-module. qt-cmake is also used by end-users, where the heuristic to change the compiler default base on paths is surprising, and can go wrong. Fixes: QTBUG-108323 Change-Id: I0274e470f214a84711013d77068551f9097f4685 Reviewed-by: Joerg Bornemann Reviewed-by: Qt CI Bot (cherry picked from commit 3aa6f0b3961322a40f046cfb39a40d118f57216e) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtToolchainHelpers.cmake | 6 ++++-- cmake/QtWrapperScriptHelpers.cmake | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake index f6df13af85a..c8e2b778111 100644 --- a/cmake/QtToolchainHelpers.cmake +++ b/cmake/QtToolchainHelpers.cmake @@ -131,10 +131,12 @@ set(__qt_chainload_toolchain_file \"\${__qt_initially_configured_toolchain_file} 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}\") +if(QT_USE_ORIGINAL_COMPILER AND 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}\") +if(QT_USE_ORIGINAL_COMPILER AND NOT DEFINED CMAKE_CXX_COMPILER + AND EXISTS \"\${__qt_initial_cxx_compiler}\") set(CMAKE_CXX_COMPILER \"\${__qt_initial_cxx_compiler}\" CACHE STRING \"\") endif()") endif() diff --git a/cmake/QtWrapperScriptHelpers.cmake b/cmake/QtWrapperScriptHelpers.cmake index a883860a09d..e42c3e282fa 100644 --- a/cmake/QtWrapperScriptHelpers.cmake +++ b/cmake/QtWrapperScriptHelpers.cmake @@ -53,15 +53,16 @@ function(qt_internal_create_wrapper_scripts) qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-create.bat" DESTINATION "${INSTALL_BINDIR}") endif() - # Provide a private convenience wrapper with options which should not be propagated via the + # Provide a private convenience wrapper with options that should not be propagated via the # public qt-cmake wrapper e.g. CMAKE_GENERATOR. # These options can not be set in a toolchain file, but only on the command line. # These options should not be in the public wrapper, because a consumer of Qt might want to # build their CMake app with the Unix Makefiles generator, while Qt should be built with the - # Ninja generator. - # The private wrapper is more conveient for building Qt itself, because a developer doesn't need - # to specify the same options for each qt module built. - set(__qt_cmake_extra "-G\"${CMAKE_GENERATOR}\"") + # Ninja generator. In a similar vein, we do want to use the same compiler for all Qt modules, + # but not for user applications. + # The private wrapper is more convenient for building Qt itself, because a developer doesn't + # need to specify the same options for each qt module built. + set(__qt_cmake_extra "-G\"${CMAKE_GENERATOR}\" -DQT_USE_ORIGINAL_COMPILER=ON") if(generate_unix) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.in" "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt-cmake-private" @ONLY @@ -232,7 +233,7 @@ function(qt_internal_create_qt_configure_tests_wrapper_script) # The script takes a path to the repo for which the standalone tests will be configured. set(script_name "qt-internal-configure-tests") - set(script_passed_args "-DQT_BUILD_STANDALONE_TESTS=ON") + set(script_passed_args "-DQT_BUILD_STANDALONE_TESTS=ON -DQT_USE_ORIGINAL_COMPILER=ON") file(RELATIVE_PATH relative_path_from_libexec_dir_to_bin_dir ${__qt_libexec_dir_absolute}