mirror of https://github.com/qt/qtbase.git
CMake: Improve automatic compiler embedding into the Qt toolchain
Embedding the initial CMAKE_CXX_COMPILER into qt.toolchain.cmake breaks Boot2Qt builds, because the CXX environment variable is not used anymore when building qtsvg or other projects. Disable automatic embedding when cross-compiling, while keeping it enabled for non-cross-compiling cases (to keep Windows and and ICC configurations working). Allow opting in or out of the embedding in case if the default is wrong, via QT_EMBED_TOOLCHAIN_COMPILER. Task-number: QTBUG-85067 Change-Id: I1d8f9f580bc379b77c34eefb5728bb49f93cc81a Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
parent
28ef8d283d
commit
e2b2cd9397
|
@ -108,10 +108,48 @@ if(VCPKG_TARGET_TRIPLET)
|
|||
list(APPEND init_vcpkg "set(VCPKG_TARGET_TRIPLET \"${VCPKG_TARGET_TRIPLET}\" CACHE STRING \"\")")
|
||||
endif()
|
||||
|
||||
# On Windows compilers aren't easily mixed. Avoid that qtbase is built using cl.exe for example and then for another
|
||||
# build gcc is picked up from %PATH%. The same goes when using a custom compiler on other platforms, such as ICC.
|
||||
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 \"\")")
|
||||
# By default we don't want to allow mixing compilers for building different repositories, so we
|
||||
# embed the initially chosen compilers into the toolchain.
|
||||
# This is because on Windows compilers aren't easily mixed.
|
||||
# We want to avoid that qtbase is built using cl.exe for example, and then for another repo
|
||||
# gcc is picked up from %PATH%.
|
||||
# The same goes when using a custom compiler on other platforms, such as ICC.
|
||||
#
|
||||
# There are a few exceptions though.
|
||||
#
|
||||
# When crosscompiling using Boot2Qt, the environment setup shell script sets up the CXX env var,
|
||||
# which is used by CMake to determine the initial compiler that should be used.
|
||||
# Unfortunately, the CXX env var contains not only the compiler name, but also a few required
|
||||
# arch-specific compiler flags. This means that when building qtsvg, if the Qt created toolchain
|
||||
# file sets the CMAKE_CXX_COMPILER variable, the CXX env var is ignored and thus the extra
|
||||
# arch specific compiler flags are not picked up anymore, leading to a configuration failure.
|
||||
#
|
||||
# To avoid this issue, disable automatic embedding of the compilers into the qt toolchain when
|
||||
# cross compiling. This is merely a heuristic, becacuse we don't have enough data to decide
|
||||
# when to do it or not.
|
||||
# For example on Linux one might want to allow mixing of clang and gcc (maybe).
|
||||
#
|
||||
# To allow such use cases when the default is wrong, one can provide a flag to explicitly opt-in
|
||||
# or opt-out of the compiler embedding into the Qt toolchain.
|
||||
#
|
||||
# Passing -DQT_EMBED_TOOLCHAIN_COMPILER=ON will force embedding of the compilers.
|
||||
# Passing -DQT_EMBED_TOOLCHAIN_COMPILER=OFF will disable embedding of the compilers.
|
||||
set(__qt_embed_toolchain_compilers TRUE)
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
set(__qt_embed_toolchain_compilers FALSE)
|
||||
endif()
|
||||
if(DEFINED QT_EMBED_TOOLCHAIN_COMPILER)
|
||||
if(QT_EMBED_TOOLCHAIN_COMPILER)
|
||||
set(__qt_embed_toolchain_compilers TRUE)
|
||||
else()
|
||||
set(__qt_embed_toolchain_compilers FALSE)
|
||||
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 \"\")")
|
||||
endif()
|
||||
unset(__qt_embed_toolchain_compilers)
|
||||
|
||||
if(APPLE)
|
||||
# For simulator_and_device build, we should not explicitly set the sysroot.
|
||||
|
|
Loading…
Reference in New Issue