From 1bb6779389980d794bac92ca0fef63f3549a93b4 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 2 Nov 2020 15:26:24 +0100 Subject: [PATCH] CMake: Let configure guess the compiler from mkspec argument The arguments -platform, -xplatform and -device determine the mkspec that's used for the qmake companion files. If the user specifies a mkspec that indicates usage of clang or icc, set the respective CMake variables to use one of those compilers. Fixes: QTBUG-87836 Change-Id: I2b10d819b0eb92a97d7f79672547b1e2d821cf33 Reviewed-by: Alexandru Croitor --- cmake/QtProcessConfigureArgs.cmake | 20 ++++++++++++++++++++ config_help.txt | 2 ++ 2 files changed, 22 insertions(+) diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake index 9614061212d..734384bc5e6 100644 --- a/cmake/QtProcessConfigureArgs.cmake +++ b/cmake/QtProcessConfigureArgs.cmake @@ -47,6 +47,7 @@ list(TRANSFORM configure_args STRIP) list(TRANSFORM configure_args REPLACE "\\\\" "\\\\\\\\") unset(generator) set(auto_detect_generator TRUE) +set(auto_detect_compiler TRUE) unset(device_options) set_property(GLOBAL PROPERTY UNHANDLED_ARGS "") while(configure_args) @@ -57,6 +58,8 @@ while(configure_args) list(POP_FRONT configure_args generator) elseif(arg STREQUAL "-cmake-use-default-generator") set(auto_detect_generator FALSE) + elseif(arg STREQUAL "-no-guess-compiler") + set(auto_detect_compiler FALSE) elseif(arg STREQUAL "-skip") list(POP_FRONT configure_args qtrepo) push("-DBUILD_${qtrepo}=OFF") @@ -552,6 +555,22 @@ macro(translate_list_input name cmake_var) endif() endmacro() +function(guess_compiler_from_mkspec) + if(NOT auto_detect_compiler) + return() + endif() + string(REGEX MATCH "(^|;)-DQT_QMAKE_TARGET_MKSPEC=\([^;]+\)" m ${cmake_args}) + set(mkspec ${CMAKE_MATCH_2}) + if(mkspec MATCHES "-clang(-|$)") + push("-DCMAKE_C_COMPILER=clang") + push("-DCMAKE_CXX_COMPILER=clang++") + elseif(mkspec MATCHES "-icc(-|$)") + push("-DCMAKE_C_COMPILER=icc") + push("-DCMAKE_CXX_COMPILER=icpc") + endif() + set(cmake_args "${cmake_args}" PARENT_SCOPE) +endfunction() + drop_input(commercial) drop_input(confirm-license) translate_boolean_input(precompile_header BUILD_WITH_PCH) @@ -576,6 +595,7 @@ if(NOT "${INPUT_device}" STREQUAL "") endif() translate_string_input(platform QT_QMAKE_TARGET_MKSPEC) translate_string_input(xplatform QT_QMAKE_TARGET_MKSPEC) +guess_compiler_from_mkspec() translate_string_input(qpa_default_platform QT_QPA_DEFAULT_PLATFORM) translate_list_input(sanitize ECM_ENABLE_SANITIZERS) diff --git a/config_help.txt b/config_help.txt index e790c61e7d2..1d4c73ec953 100644 --- a/config_help.txt +++ b/config_help.txt @@ -90,6 +90,8 @@ Build options: CMake instead of auto-detecting one. -cmake-use-default-generator ... Turn off auto-detection of the CMake build system generator. + -no-guess-compiler ... Do not guess the compiler from the target mkspec. + Only applies to the CMake build. -release ............. Build Qt with debugging turned off [yes] -debug ............... Build Qt with debugging turned on [no] -debug-and-release ... Build two versions of Qt, with and without