From 303b1061370ef4983253fb5986c97ed2cef298c6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 7 Dec 2024 19:38:35 +0100 Subject: [PATCH] CMake: support CMAKE_OSX_ARCHITECTURES (one arch/build) --- CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e476d1e7..e956f1c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,26 +217,51 @@ if(ENABLE_LUAJIT) target_link_libraries(AlberCore PRIVATE libluajit) endif() -# Check for x64 -if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86-64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") +# Detect target architecture +if (NOT APPLE OR "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") + # Normal target detection + if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86-64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") set(HOST_X64 TRUE) + else() + set(HOST_X64 FALSE) + endif() + + if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + set(HOST_ARM64 TRUE) + else() + set(HOST_ARM64 FALSE) + endif() +else() + # Apple target detection + if("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES) + set(HOST_X64 TRUE) + else() + set(HOST_X64 FALSE) + endif() + + if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES) + set(HOST_ARM64 TRUE) + else() + set(HOST_ARM64 FALSE) + endif() + + if (HOST_ARM64 AND HOST_X64) + message(FATAL_ERROR "Universal builds not supported like this! Please compile separately and stitch together") + endif() +endif() + +if (HOST_X64) add_subdirectory(third_party/xbyak) # Add xbyak submodule for x86 JITs include_directories(third_party/xbyak) add_compile_definitions(PANDA3DS_DYNAPICA_SUPPORTED) add_compile_definitions(PANDA3DS_X64_HOST) -else() - set(HOST_X64 FALSE) endif() -# Check for arm64 -if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") - set(HOST_ARM64 TRUE) +if (HOST_ARM64) add_subdirectory(third_party/oaknut) # Add Oaknut submodule for arm64 JITs include_directories(third_party/oaknut/include) add_compile_definitions(PANDA3DS_DYNAPICA_SUPPORTED) add_compile_definitions(PANDA3DS_ARM64_HOST) -else() - set(HOST_ARM64 FALSE) endif() # Enable SSE4.1 if it's not explicitly disabled