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
Pick-to: 6.6
Change-Id: I0274e470f214a84711013d77068551f9097f4685
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Kai Köhne 2023-05-23 10:56:36 +02:00
parent 885d87488a
commit 3aa6f0b396
2 changed files with 11 additions and 8 deletions

View File

@ -131,10 +131,12 @@ set(__qt_chainload_toolchain_file \"\${__qt_initially_configured_toolchain_file}
list(APPEND init_platform " list(APPEND init_platform "
set(__qt_initial_c_compiler \"${CMAKE_C_COMPILER}\") set(__qt_initial_c_compiler \"${CMAKE_C_COMPILER}\")
set(__qt_initial_cxx_compiler \"${CMAKE_CXX_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 \"\") set(CMAKE_C_COMPILER \"\${__qt_initial_c_compiler}\" CACHE STRING \"\")
endif() 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 \"\") set(CMAKE_CXX_COMPILER \"\${__qt_initial_cxx_compiler}\" CACHE STRING \"\")
endif()") endif()")
endif() endif()

View File

@ -53,15 +53,16 @@ function(qt_internal_create_wrapper_scripts)
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-create.bat" qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_BINDIR}/qt-cmake-create.bat"
DESTINATION "${INSTALL_BINDIR}") DESTINATION "${INSTALL_BINDIR}")
endif() 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. # 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 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 # 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 # build their CMake app with the Unix Makefiles generator, while Qt should be built with the
# Ninja generator. # Ninja generator. In a similar vein, we do want to use the same compiler for all Qt modules,
# The private wrapper is more conveient for building Qt itself, because a developer doesn't need # but not for user applications.
# to specify the same options for each qt module built. # The private wrapper is more convenient for building Qt itself, because a developer doesn't
set(__qt_cmake_extra "-G\"${CMAKE_GENERATOR}\"") # 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) if(generate_unix)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bin/qt-cmake.in"
"${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt-cmake-private" @ONLY "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt-cmake-private" @ONLY
@ -231,7 +232,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. # 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_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 file(RELATIVE_PATH relative_path_from_libexec_dir_to_bin_dir
${__qt_libexec_dir_absolute} ${__qt_libexec_dir_absolute}