cmake: Detect SDL_JOYSTICK_MFI for macOS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a755c6..20a743a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1825,8 +1825,9 @@ elseif(APPLE)
endif()
if(SDL_JOYSTICK)
+ file(GLOB MFI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
if(IOS OR TVOS)
- file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
+ file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
set(SDL_JOYSTICK_MFI 1)
if(IOS)
set(SDL_FRAMEWORK_COREMOTION 1)
@@ -1835,13 +1836,37 @@ elseif(APPLE)
set(SDL_FRAMEWORK_COREHAPTICS 1)
set(HAVE_SDL_SENSORS 1)
else()
- file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
- # FIXME: add checks for SDL_JOYSTICK_MFI???
+ file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
+ set_source_files_properties(${MFI_JOYSTICK_SOURCES} PROPERTIES COMPILE_FLAGS -fobjc-weak)
+ check_objc_source_compiles("
+ #include <AvailabilityMacros.h>
+ #include <TargetConditionals.h>
+ #import <Foundation/Foundation.h>
+ #import <GameController/GameController.h>
+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
+ #error GameController framework doesn't work on this configuration
+ #endif
+ #if TARGET_CPU_X86
+ #error GameController framework doesn't work on this configuration
+ #endif
+ int main() {}" HAVE_FRAMEWORK_GAMECONTROLLER)
+ check_objc_source_compiles("
+ #include <AvailabilityMacros.h>
+ #include <TargetConditionals.h>
+ #import <Foundation/Foundation.h>
+ #import <CoreHaptics/CoreHaptics.h>
+ int main() {}" HAVE_FRAMEWORK_COREHAPTICS)
+ if(HAVE_FRAMEWORK_GAMECONTROLLER AND HAVE_FRAMEWORK_COREHAPTICS)
+ # Only enable MFI if we also have CoreHaptics to ensure rumble works
+ set(SDL_JOYSTICK_MFI 1)
+ set(SDL_FRAMEWORK_GAMECONTROLLER 1)
+ set(SDL_FRAMEWORK_COREHAPTICS 1)
+ endif()
set(SDL_JOYSTICK_IOKIT 1)
set(SDL_FRAMEWORK_IOKIT 1)
set(SDL_FRAMEWORK_FF 1)
endif()
- set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
+ set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES} ${MFI_JOYSTICK_SOURCES})
set(HAVE_SDL_JOYSTICK TRUE)
endif()