diff options
author | Brad King <brad.king@kitware.com> | 2020-07-16 15:46:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-07-20 14:03:15 (GMT) |
commit | 26673bf48011a48fe0ad01e97409a32c1f50143d (patch) | |
tree | 38c4a14ec2adaa5ae451c1ce38afacbe0b1d7966 | |
parent | ce624cfbd4fcbf5c486850ac331fa1e1dba28f8b (diff) | |
download | CMake-26673bf48011a48fe0ad01e97409a32c1f50143d.zip CMake-26673bf48011a48fe0ad01e97409a32c1f50143d.tar.gz CMake-26673bf48011a48fe0ad01e97409a32c1f50143d.tar.bz2 |
Xcode: Explicitly specify default native architecture on macOS
When `CMAKE_OSX_ARCHITECTURES` is not specified, we add the Xcode
setting `ONLY_ACTIVE_ARCH = YES` with the intention of targeting the
native architecture of the host. However, the default `ARCHS` value
chosen by "Xcode 12 Universal Apps" includes multiple architectures.
Add an explicit `ARCHS` setting with value `$(NATIVE_ARCH_ACTUAL)`
to tell Xcode to use the host's native architecture only.
Fixes: #20893
-rw-r--r-- | Help/release/3.18.rst | 14 | ||||
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 6 | ||||
-rw-r--r-- | Modules/CompilerId/Xcode-3.pbxproj.in | 1 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 12 |
4 files changed, 32 insertions, 1 deletions
diff --git a/Help/release/3.18.rst b/Help/release/3.18.rst index 386b61b..427840e 100644 --- a/Help/release/3.18.rst +++ b/Help/release/3.18.rst @@ -318,3 +318,17 @@ Other Changes * The :manual:`cmake-file-api(7)` "codemodel" version 2 "target" object gained a new ``precompileHeaders`` field in the ``compileGroups`` objects. + +Updates +======= + +Changes made since CMake 3.18.0 include the following. + +3.18.1 +------ + +* The :generator:`Xcode` generator, when :variable:`CMAKE_OSX_ARCHITECTURES` + is not defined, now selects ``$(NATIVE_ARCH_ACTUAL)`` as the default + architecture (the Xcode ``ARCHS`` setting). This is needed for Xcode 12 + to select the host's architecture, which older versions of Xcode did + by default. diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index df48fa5..44332a6 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -469,6 +469,12 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_clang_cxx_library "CLANG_CXX_LIBRARY = \"${CMAKE_MATCH_3}\";") endif() endif() + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_SYSROOT MATCHES "^$|[Mm][Aa][Cc][Oo][Ss]") + # When targeting macOS, use only the host architecture. + set(id_archs [[ARCHS = "$(NATIVE_ARCH_ACTUAL)";]]) + else() + set(id_archs "") + endif() configure_file(${CMAKE_ROOT}/Modules/CompilerId/Xcode-3.pbxproj.in ${id_dir}/CompilerId${lang}.xcodeproj/project.pbxproj @ONLY) unset(_ENV_MACOSX_DEPLOYMENT_TARGET) diff --git a/Modules/CompilerId/Xcode-3.pbxproj.in b/Modules/CompilerId/Xcode-3.pbxproj.in index 672044e..6fe17e5 100644 --- a/Modules/CompilerId/Xcode-3.pbxproj.in +++ b/Modules/CompilerId/Xcode-3.pbxproj.in @@ -84,6 +84,7 @@ CODE_SIGNING_REQUIRED = NO; CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)"; SYMROOT = .; + @id_archs@ @id_toolset@ @id_lang_version@ @id_clang_cxx_library@ diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index e006be2..65828ce 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -12,6 +12,7 @@ #include <cm/memory> #include <cmext/algorithm> +#include <cmext/string_view> #include "cmsys/RegularExpression.hxx" @@ -3118,6 +3119,14 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( if (archs.empty()) { // Tell Xcode to use NATIVE_ARCH instead of ARCHS. buildSettings->AddAttribute("ONLY_ACTIVE_ARCH", this->CreateString("YES")); + // When targeting macOS, use only the host architecture. + if (this->SystemName == "Darwin"_s && + (!sysroot || !*sysroot || + cmSystemTools::LowerCase(sysroot).find("macos") != + std::string::npos)) { + buildSettings->AddAttribute("ARCHS", + this->CreateString("$(NATIVE_ARCH_ACTUAL)")); + } } else { // Tell Xcode to use ARCHS (ONLY_ACTIVE_ARCH defaults to NO). buildSettings->AddAttribute("ARCHS", this->CreateString(archs)); @@ -3217,7 +3226,8 @@ void cmGlobalXCodeGenerator::ComputeArchitectures(cmMakefile* mf) } if (this->Architectures.empty()) { - // With no ARCHS we use ONLY_ACTIVE_ARCH. + // With no ARCHS we use ONLY_ACTIVE_ARCH and possibly a + // platform-specific default ARCHS placeholder value. // Look up the arch that Xcode chooses in this case. if (const char* arch = mf->GetDefinition("CMAKE_XCODE_ARCHS")) { this->ObjectDirArchDefault = arch; |