[cmake] Enable native compilation on Apple M1 (#6152)

This commit is contained in:
Stefan Wunsch 2021-03-03 18:35:19 +01:00 committed by GitHub
parent 84751ad26f
commit 02b86239db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,18 @@ set(PROC_TARGET_1_FLAGS "-mtune=generic" CACHE STRING "Processor-1 flags")
# This second choice should be used for your own build only
set(PROC_TARGET_2_LABEL native CACHE STRING "Processor-2 label - use it for your own build")
# Get the architecture on an Apple system (x86 or arm64)
if(APPLE)
execute_process(COMMAND uname -m OUTPUT_VARIABLE APPLE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
# On Apple's M1 processor and with Apple's clang compiler, the native flag is different
if(CMAKE_CXX_COMPILER_ID STREQUAL AppleClang AND APPLE_ARCHITECTURE STREQUAL arm64)
set(PROC_TARGET_2_FLAGS "-mcpu=native" CACHE STRING "Processor-2 flags")
else()
set(PROC_TARGET_2_FLAGS "-march=native" CACHE STRING "Processor-2 flags")
endif()
# The later choices is intended to be used if you want to provide specific builds, but it should match your own processor
# You can cross compile but you have to know what you're doing, this mechanism has not been designed for that