From 4d882809316fdd70c224e5b28ab3a87fddcbac6a Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 2 Sep 2025 22:34:10 +0300 Subject: [PATCH] cmake: simd detection clean-up for Apple multi-arch configs. (cherry picked from commit 83bb0f9105922fd49282f0b931f7873a71877ac8) --- CMakeLists.txt | 6 ++++++ cmake/sdlcompilers.cmake | 18 ++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da7bf7dddd..ebdcde19a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,12 @@ include("${SDL3_SOURCE_DIR}/cmake/PreseedEmscriptenCache.cmake") SDL_DetectCompiler() SDL_DetectTargetCPUArchitectures(SDL_CPUS) +if(APPLE AND CMAKE_OSX_ARCHITECTURES) + list(LENGTH CMAKE_OSX_ARCHITECTURES _num_arches) + if(_num_arches GREATER 1) + set(APPLE_MULTIARCH TRUE) + endif() +endif() # Increment this if there is an incompatible change - but if that happens, # we should rename the library from SDL3 to SDL4, at which point this would diff --git a/cmake/sdlcompilers.cmake b/cmake/sdlcompilers.cmake index f4e43b73fd..af80a8eb24 100644 --- a/cmake/sdlcompilers.cmake +++ b/cmake/sdlcompilers.cmake @@ -165,20 +165,19 @@ function(check_x86_source_compiles BODY VAR) if(ARGN) message(FATAL_ERROR "Unknown arguments: ${ARGN}") endif() - if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES) + if(APPLE_MULTIARCH AND (SDL_CPU_X86 OR SDL_CPU_X64)) set(test_conditional 1) else() set(test_conditional 0) endif() check_c_source_compiles(" #if ${test_conditional} - # include \"TargetConditionals.h\" - # if TARGET_CPU_X86 || TARGET_CPU_X86_64 + # if defined(__i386__) || defined(__x86_64__) # define test_enabled 1 # else - # define test_enabled 0 + # define test_enabled 0 /* feign success in Apple multi-arch configs */ # endif - #else + #else /* test normally */ # define test_enabled 1 #endif #if test_enabled @@ -196,20 +195,19 @@ function(check_arm_source_compiles BODY VAR) if(ARGN) message(FATAL_ERROR "Unknown arguments: ${ARGN}") endif() - if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES) + if(APPLE_MULTIARCH AND (SDL_CPU_ARM32 OR SDL_CPU_ARM64)) set(test_conditional 1) else() set(test_conditional 0) endif() check_c_source_compiles(" #if ${test_conditional} - # include \"TargetConditionals.h\" - # if TARGET_CPU_ARM || TARGET_CPU_ARM64 + # if defined(__arm__) || defined(__aarch64__) # define test_enabled 1 # else - # define test_enabled 0 + # define test_enabled 0 /* feign success in Apple multi-arch configs */ # endif - #else + #else /* test normally */ # define test_enabled 1 #endif #if test_enabled