From 8f75912176e74bc39dc18f6f1ae7fe65cca27017 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 29 Sep 2020 05:05:04 -0400 Subject: Tests: Enable Assembler test case when CMAKE_OSX_ARCHITECTURES has one value --- Tests/Assembler/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/Assembler/CMakeLists.txt b/Tests/Assembler/CMakeLists.txt index a3c9946..cee5210 100644 --- a/Tests/Assembler/CMakeLists.txt +++ b/Tests/Assembler/CMakeLists.txt @@ -8,7 +8,7 @@ set(SRCS) # (at least) the following toolchains can process assembler files directly # and also generate assembler files from C: if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode|Ninja" AND - NOT CMAKE_OSX_ARCHITECTURES) + NOT CMAKE_OSX_ARCHITECTURES MATCHES ";") if((CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang|HP|SunPro|XL)$") OR (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND UNIX) AND NOT (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")) set(C_FLAGS "${CMAKE_C_FLAGS}") @@ -16,6 +16,9 @@ if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode|Ninja" AND if(CMAKE_OSX_SYSROOT AND CMAKE_C_SYSROOT_FLAG AND NOT ";${C_FLAGS};" MATCHES ";${CMAKE_C_SYSROOT_FLAG};") list(APPEND C_FLAGS ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}) endif() + if(CMAKE_OSX_ARCHITECTURES) + list(APPEND C_FLAGS -arch ${CMAKE_OSX_ARCHITECTURES}) + endif() # Clang on OS X, and perhaps other compilers, do not support -g # for both generating and assembling, so drop it from generating. list(REMOVE_ITEM C_FLAGS -g) -- cgit v0.12 From 383e81aa60312433d25d68ab0ef4991aa3b869c1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 29 Sep 2020 16:07:53 -0400 Subject: Tests: Teach RunCMake to ignore Xcode internal objc warnings Xcode on Apple Silicon warns: objc[...]: Class AMSupportURL... is implemented in both ... One of the two will be used. Which one is undefined. Teach RunCMake to drop such lines before matching against expected output. --- Tests/RunCMake/RunCMake.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index c13c694..7d96e50 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -153,6 +153,7 @@ function(run_cmake test) "|contact PGI Sales at" "|[^\n]*xcodebuild[^\n]*warning: file type[^\n]*is based on missing file type" + "|[^\n]*objc[^\n]*: Class AMSupportURL[^\n]* One of the two will be used. Which one is undefined." "|[^\n]*is a member of multiple groups" "|[^\n]*offset in archive not a multiple of 8" "|[^\n]*from Time Machine by path" -- cgit v0.12 From b6c60f14b6df53d8cb6fe442d801fdae50ddf287 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 28 Sep 2020 16:47:36 -0400 Subject: macOS: Default to arm64 architecture on Apple Silicon hosts Detect `arm64` hardware using a method that pierces Rosetta. If `CMAKE_OSX_ARCHITECTURES` is not set, pass explicit flags to the toolchain to use `arm64` instead of letting the toolchain pick. Fixes: #20989 --- Modules/CMakeDetermineSystem.cmake | 19 +++++++++++++++---- Modules/Platform/Darwin-Initialize.cmake | 11 +++++++++++ Source/cmGeneratorTarget.cxx | 3 +++ Source/cmGlobalXCodeGenerator.cxx | 4 ++++ Tests/Assembler/CMakeLists.txt | 2 ++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake index f3ec4da..cb4421a 100644 --- a/Modules/CMakeDetermineSystem.cmake +++ b/Modules/CMakeDetermineSystem.cmake @@ -46,10 +46,21 @@ if(CMAKE_HOST_UNIX) if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|Darwin|^GNU$|Android") exec_program(${CMAKE_UNAME} ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR RETURN_VALUE val) - if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND - CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "Power Macintosh") - # OS X ppc 'uname -m' may report 'Power Macintosh' instead of 'powerpc' - set(CMAKE_HOST_SYSTEM_PROCESSOR "powerpc") + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + # Check whether we are running under Rosetta on arm64 hardware. + execute_process(COMMAND sysctl -q hw.optional.arm64 + OUTPUT_VARIABLE _sysctl_stdout + ERROR_VARIABLE _sysctl_stderr + RESULT_VARIABLE _sysctl_result + ) + if(_sysctl_result EQUAL 0 AND _sysctl_stdout MATCHES "hw.optional.arm64: 1") + set(CMAKE_HOST_SYSTEM_PROCESSOR "arm64") + endif() + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "Power Macintosh") + # OS X ppc 'uname -m' may report 'Power Macintosh' instead of 'powerpc' + set(CMAKE_HOST_SYSTEM_PROCESSOR "powerpc") + endif() endif() elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD") exec_program(arch ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake index d087412..15e6123 100644 --- a/Modules/Platform/Darwin-Initialize.cmake +++ b/Modules/Platform/Darwin-Initialize.cmake @@ -20,6 +20,17 @@ execute_process(COMMAND sw_vers -productVersion set(CMAKE_OSX_ARCHITECTURES "$ENV{CMAKE_OSX_ARCHITECTURES}" CACHE STRING "Build architectures for OSX") +if(NOT CMAKE_CROSSCOMPILING AND + CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND + CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" AND + CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + # When building on Apple Silicon (arm64), we need to explicitly specify + # the architecture to the toolchain since it will otherwise guess the + # architecture based on that of the build system tool. + # Set an *internal variable* to tell the generators to do this. + set(_CMAKE_APPLE_ARCHS_DEFAULT "arm64") +endif() + # macOS, iOS, tvOS, and watchOS should lookup compilers from # Platform/Apple-${CMAKE_CXX_COMPILER_ID}- set(CMAKE_EFFECTIVE_SYSTEM_NAME "Apple") diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 8589ab1..20a137a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3193,6 +3193,9 @@ void cmGeneratorTarget::GetAppleArchs(const std::string& config, if (archs) { cmExpandList(*archs, archVec); } + if (archVec.empty()) { + this->Makefile->GetDefExpandList("_CMAKE_APPLE_ARCHS_DEFAULT", archVec); + } } void cmGeneratorTarget::AddCUDAArchitectureFlags(std::string& flags) const diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index b57bdbc..71b52ec 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -4024,6 +4024,10 @@ void cmGlobalXCodeGenerator::ComputeArchitectures(cmMakefile* mf) } if (this->Architectures.empty()) { + mf->GetDefExpandList("_CMAKE_APPLE_ARCHS_DEFAULT", this->Architectures); + } + + if (this->Architectures.empty()) { // 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. diff --git a/Tests/Assembler/CMakeLists.txt b/Tests/Assembler/CMakeLists.txt index cee5210..a574c4e 100644 --- a/Tests/Assembler/CMakeLists.txt +++ b/Tests/Assembler/CMakeLists.txt @@ -18,6 +18,8 @@ if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode|Ninja" AND endif() if(CMAKE_OSX_ARCHITECTURES) list(APPEND C_FLAGS -arch ${CMAKE_OSX_ARCHITECTURES}) + elseif("${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64") + list(APPEND C_FLAGS -arch arm64) endif() # Clang on OS X, and perhaps other compilers, do not support -g # for both generating and assembling, so drop it from generating. -- cgit v0.12