summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-08-17 09:47:45 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-08-17 21:30:34 +0200
commitfe40e08da4edc0728b305e6068f86b1818136d88 (patch)
tree2a35de80a99b19d5c1a2ef8c533799a8121a7bbc /cmake
parentff00ef641041d2a758ec2560d87ef8f549618a7d (diff)
CMake: Fix building iOS projects with a single-arch Qt build
Automatically set the CMAKE_OSX_SYSROOT and CMAKE_OSX_ARCHITECTURES values with the ones Qt was configured with, when configuring a user project with the Xcode generator and a single arch / sdk Qt build. This ensures that calling xcodebuild from the command line chooses the correct architecture and SDK when building the project. Allow to opt out of this behavior by passing QT_NO_SET_OSX_ARCHITECTURES and QT_NO_SET_OSX_SYSROOT. Amends 55a15a1c1b93d36d705fc69e44b5c806b807dd55 Amends a6a3b82ffb3d7f1ea13293206401ed360a51e9cd Pick-to: 6.2 Task-number: QTBUG-95838 Change-Id: Ifab16e9eee3100a9b80a2a14b3ea29ba8d9aa6fc Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtToolchainHelpers.cmake27
1 files changed, 24 insertions, 3 deletions
diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake
index 00ee5d8b33..5ab1236b8f 100644
--- a/cmake/QtToolchainHelpers.cmake
+++ b/cmake/QtToolchainHelpers.cmake
@@ -104,13 +104,26 @@ function(qt_internal_create_toolchain_file)
unset(init_additional_used_variables)
if(APPLE)
- # For simulator_and_device build, we should not explicitly set the sysroot.
+
+ # 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.
+ # Also allow to opt out just in case.
+ #
+ # TODO: Figure out if the same should apply to universal macOS builds.
+
list(LENGTH CMAKE_OSX_ARCHITECTURES _qt_osx_architectures_count)
if(CMAKE_OSX_SYSROOT 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()")
endif()
@@ -151,14 +164,22 @@ function(qt_internal_create_toolchain_file)
# This is line with default CMake behavior for user projects.
#
# For iOS, we provide a bit more convenience.
- # When the user project is built using the Xcode generator, don't specify a default
+ # When the user project is built using the Xcode generator, we only specify the architecture
+ # if this is a single architecture Qt for iOS build. If we wouldn't, invoking just
+ # xcodebuild from the command line would try to build with the wrong architecture. Also
+ # provide an opt-out option just in case.
+ #
+ # For a multi-architecture build (so simulator_and_device) we don't set an explicit
# architecture and let Xcode and the developer handle it.
+ #
# When using the Ninja generator, specify the first architecture from QT_OSX_ARCHITECTURES
# (even with a simulator_and_device Qt build). This ensures that the default configuration
# at least tries to build something.
if(UIKIT)
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)")
+ 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))")
list(APPEND init_platform
" set(CMAKE_OSX_ARCHITECTURES \"${osx_first_arch}\" CACHE STRING \"\")")
list(APPEND init_platform "endif()")