Skip to content

Commit

Permalink
Make sleef compilable if CMAKE_OSX_ARCHITECTURES is passed (#376)
Browse files Browse the repository at this point in the history
* Simplify x86 arch check

* Fix sleef compilation when CMAKE_OSX_ARCHITECTURES is passed

Test plan:
  Run `cmake .. -DCMAKE_OSX_ARCHITECTURES=x86_64 -G Ninja; ninja` on M1 Mac
  Run `cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64 -G Ninja; ninja` on x86 Mac

* Compile host executable as universable binaries on OS X
If multiarch option is passed
  • Loading branch information
malfet authored Dec 22, 2020
1 parent 80b994f commit e0a003e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ set(TARGET_LIBARRAYMAP_OBJ "arraymap")
function(add_host_executable TARGETNAME)
if (NOT CMAKE_CROSSCOMPILING)
add_executable(${TARGETNAME} ${ARGN})
# Ensure that Darwin host executable is built as universal binary
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64)$")
target_compile_options(${TARGETNAME} PRIVATE -arch "${CMAKE_HOST_SYSTEM_PROCESSOR}")
target_link_options(${TARGETNAME} PRIVATE -arch "${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
else()
add_executable(${TARGETNAME} IMPORTED)
set_property(TARGET ${TARGETNAME} PROPERTY IMPORTED_LOCATION ${NATIVE_BUILD_DIR}/bin/${TARGETNAME})
Expand All @@ -230,7 +235,11 @@ add_subdirectory("src")
if(SLEEF_SHOW_CONFIG)
message(STATUS "Configuring build for ${PROJECT_NAME}-v${SLEEF_VERSION}")
message(" Target system: ${CMAKE_SYSTEM}")
message(" Target processor: ${CMAKE_SYSTEM_PROCESSOR}")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64)$")
message(" Target processor: ${CMAKE_OSX_ARCHITECTURES}")
else()
message(" Target processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
message(" Host system: ${CMAKE_HOST_SYSTEM}")
message(" Host processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message(" Detected C compiler: ${CMAKE_C_COMPILER_ID} @ ${CMAKE_C_COMPILER}")
Expand Down
10 changes: 8 additions & 2 deletions Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,24 @@ if(NOT CMAKE_BUILD_TYPE)
"Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif()

# TARGET PROCESSOR DETECTION
set(SLEEF_TARGET_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64)$")
set(SLEEF_TARGET_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}")
endif()

# PLATFORM DETECTION
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(SLEEF_ARCH_32BIT ON CACHE INTERNAL "True for 32-bit architecture.")
endif()

if((CMAKE_SYSTEM_PROCESSOR MATCHES "x86") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "amd64") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$"))
if(SLEEF_TARGET_PROCESSOR MATCHES "(x86|AMD64|amd64|^i.86$)")
set(SLEEF_ARCH_X86 ON CACHE INTERNAL "True for x86 architecture.")

set(CLANG_FLAGS_ENABLE_PURECFMA_SCALAR "-mavx2;-mfma;-fno-strict-aliasing")
set(CLANG_FLAGS_ENABLE_PUREC_SCALAR "-fno-strict-aliasing")

elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
elseif(SLEEF_TARGET_PROCESSOR MATCHES "aarch64|arm64")
set(SLEEF_ARCH_AARCH64 ON CACHE INTERNAL "True for Aarch64 architecture.")
# Aarch64 requires support for advsimdfma4
set(COMPILER_SUPPORTS_ADVSIMD 1)
Expand Down

0 comments on commit e0a003e

Please sign in to comment.