diff options
Diffstat (limited to 'cmake/QtToolchainHelpers.cmake')
-rw-r--r-- | cmake/QtToolchainHelpers.cmake | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake index 5f3d2dc4d3..26b44bb10c 100644 --- a/cmake/QtToolchainHelpers.cmake +++ b/cmake/QtToolchainHelpers.cmake @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +# SPDX-License-Identifier: BSD-3-Clause # Create a CMake toolchain file for convenient configuration of both internal Qt builds # as well as CMake application projects. @@ -31,6 +31,14 @@ set(__qt_chainload_toolchain_file \"\${__qt_initially_configured_toolchain_file} list(APPEND init_platform "set(CMAKE_SYSTEM_PROCESSOR arm64 CACHE STRING \"\")") endif() + if(QT_QMAKE_TARGET_MKSPEC) + list(APPEND init_platform + "if(NOT QT_QMAKE_TARGET_MKSPEC)" + " set(QT_QMAKE_TARGET_MKSPEC ${QT_QMAKE_TARGET_MKSPEC} CACHE STRING \"\")" + "endif()" + ) + endif() + if("${QT_QMAKE_TARGET_MKSPEC}" STREQUAL "linux-g++-32" AND NOT QT_NO_AUTO_DETECT_LINUX_X86) set(__qt_toolchain_common_flags_init "-m32") @@ -121,39 +129,41 @@ set(__qt_chainload_toolchain_file \"\${__qt_initially_configured_toolchain_file} endif() if(__qt_embed_toolchain_compilers) 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()") +set(__qt_initial_c_compiler \"${CMAKE_C_COMPILER}\") +set(__qt_initial_cxx_compiler \"${CMAKE_CXX_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(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() unset(init_additional_used_variables) if(APPLE) - # For an iOS simulator_and_device build, we should not explicitly set the sysroot, but let - # CMake do it's universal build magic to use one sysroot / sdk per-arch. - # For a single arch / sysroot iOS build, try to use the initially configured sysroot - # path if it exists, otherwise just set the name of the sdk to be used. - # The latter "name" part is important for user projects so that running 'xcodebuild' from - # the command line chooses the correct sdk. + # For an iOS simulator_and_device build, we should not explicitly set the sysroot, + # but let CMake do it's universal build magic to use one sysroot / sdk per-arch. + # For a single arch / sysroot build, try to use the initially configured sysroot + # by name. + # # Also allow to opt out just in case. # # TODO: Figure out if the same should apply to universal macOS builds. + # We want to preserve the sysroot as an SDK name, instead of the path + # that CMake transforms it into in Darwin-initialize.cmake, so we pick + # it out from the cache, where it hasn't been touched by CMake. + set(cmake_sysroot_name "$CACHE{CMAKE_OSX_SYSROOT}") + list(LENGTH CMAKE_OSX_ARCHITECTURES _qt_osx_architectures_count) - if(CMAKE_OSX_SYSROOT AND NOT _qt_osx_architectures_count GREATER 1 AND UIKIT) + if(cmake_sysroot_name AND NOT _qt_osx_architectures_count GREATER 1 AND UIKIT) list(APPEND init_platform " - set(__qt_uikit_sdk \"${QT_UIKIT_SDK}\") - set(__qt_initial_cmake_osx_sysroot \"${CMAKE_OSX_SYSROOT}\") - if(NOT DEFINED CMAKE_OSX_SYSROOT AND EXISTS \"\${__qt_initial_cmake_osx_sysroot}\") - set(CMAKE_OSX_SYSROOT \"\${__qt_initial_cmake_osx_sysroot}\" CACHE PATH \"\") - elseif(NOT DEFINED CMAKE_OSX_SYSROOT AND NOT QT_NO_SET_OSX_SYSROOT) - set(CMAKE_OSX_SYSROOT \"\${__qt_uikit_sdk}\" CACHE PATH \"\") - endif()") +if(NOT DEFINED CMAKE_OSX_SYSROOT) + set(CMAKE_OSX_SYSROOT \"${cmake_sysroot_name}\" CACHE STRING \"\") +endif()") endif() if(CMAKE_OSX_DEPLOYMENT_TARGET) @@ -208,7 +218,7 @@ set(__qt_chainload_toolchain_file \"\${__qt_initially_configured_toolchain_file} qt_internal_get_first_osx_arch(osx_first_arch) list(APPEND init_platform "if((NOT CMAKE_GENERATOR STREQUAL \"Xcode\" AND NOT __qt_toolchain_building_qt_repo) - OR (CMAKE_GENERATOR STREQUAL \"Xcode\" AND __qt_uikit_sdk AND NOT QT_NO_SET_OSX_ARCHITECTURES))") + OR (CMAKE_GENERATOR STREQUAL \"Xcode\" AND __qt_apple_sdk AND NOT QT_NO_SET_OSX_ARCHITECTURES))") list(APPEND init_platform " set(CMAKE_OSX_ARCHITECTURES \"${osx_first_arch}\" CACHE STRING \"\")") list(APPEND init_platform "endif()") @@ -222,15 +232,11 @@ set(__qt_chainload_toolchain_file \"\${__qt_initially_configured_toolchain_file} elseif(ANDROID) list(APPEND init_platform "# Detect Android SDK/NDK from environment before loading the Android platform toolchain file." -"if(NOT DEFINED ANDROID_SDK_ROOT)" -" if(NOT \"\$ENV{ANDROID_SDK_ROOT}\" STREQUAL \"\")" -" set(ANDROID_SDK_ROOT \"\$ENV{ANDROID_SDK_ROOT}\" CACHE STRING \"Path to the Android SDK\")" -" endif()" +"if(\"$\{ANDROID_SDK_ROOT}\" STREQUAL \"\" AND NOT \"\$ENV{ANDROID_SDK_ROOT}\" STREQUAL \"\")" +" set(ANDROID_SDK_ROOT \"\$ENV{ANDROID_SDK_ROOT}\" CACHE STRING \"Path to the Android SDK\")" "endif()" -"if(NOT DEFINED ANDROID_NDK_ROOT)" -" if(NOT \"\$ENV{ANDROID_NDK_ROOT}\" STREQUAL \"\")" -" set(ANDROID_NDK_ROOT \"\$ENV{ANDROID_NDK_ROOT}\" CACHE STRING \"Path to the Android NDK\")" -" endif()" +"if(\"$\{ANDROID_NDK_ROOT}\" STREQUAL \"\" AND NOT \"\$ENV{ANDROID_NDK_ROOT}\" STREQUAL \"\")" +" set(ANDROID_NDK_ROOT \"\$ENV{ANDROID_NDK_ROOT}\" CACHE STRING \"Path to the Android NDK\")" "endif()" ) |