From 0041ddce7420aafdb8bb032058a42d47afa34c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 21 Mar 2024 19:34:30 +0100 Subject: [PATCH] CMake: Improve Xcode projects for single SDK builds on Apple platforms Xcode expects the base SDK to always be the device SDK, so we can't pass CMAKE_OSX_SYSROOT on directly. We use the Xcode SUPPORTED_PLATFORMS setting to inform Xcode about which targets we can actually build and run for. The logic is only triggered for single-arch Qt builds. Change-Id: I0012e220cb415fcc5995672ffd60b25ef7eeb4e7 Reviewed-by: Alexey Edelev --- src/corelib/Qt6CoreMacros.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 9e8ce544cc..9e71b4265a 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -3489,6 +3489,21 @@ macro(qt6_standard_project_setup) if(NOT DEFINED QT_I18N_SOURCE_LANGUAGE) set(QT_I18N_SOURCE_LANGUAGE ${__qt_sps_arg_I18N_SOURCE_LANGUAGE}) endif() + + if(CMAKE_GENERATOR STREQUAL "Xcode") + # Ensure we always use device SDK for Xcode for single-arch Qt builds + set(qt_osx_arch_count 0) + if(QT_OSX_ARCHITECTURES) + list(LENGTH QT_OSX_ARCHITECTURES qt_osx_arch_count) + endif() + if(NOT qt_osx_arch_count GREATER 1 AND ${CMAKE_OSX_SYSROOT} MATCHES "^[a-z]+simulator$") + # Xcode expects the base SDK to be the device SDK + set(simulator_sysroot "${CMAKE_OSX_SYSROOT}") + string(REGEX REPLACE "simulator" "os" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}") + set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}" CACHE STRING "" FORCE) + set(CMAKE_XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS "${simulator_sysroot}") + endif() + endif() endif() endmacro()