libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.55k stars 1.77k forks source link

macOS 10.14 SDK Compatibility #9987

Open flibitijibibo opened 3 months ago

flibitijibibo commented 3 months ago

Was building SDL3 against Mojave and ran into some errors - the camera one I think just needs a minimum SDK version requirement in the CMake project...

/home/flibitijibibo/libraries/SDL3/src/camera/coremedia/SDL_camera_coremedia.m:443:13: error: use of undeclared identifier 'AVCaptureDeviceTypeExternalUnknown'
            AVCaptureDeviceTypeExternalUnknown,
            ^
/home/flibitijibibo/libraries/SDL3/src/camera/coremedia/SDL_camera_coremedia.m:445:13: error: 'AVCaptureDeviceTypeBuiltInWideAngleCamera' is unavailable: not available on macOS
            AVCaptureDeviceTypeBuiltInWideAngleCamera
            ^
/home/flibitijibibo/osxcross/target/bin/../SDK/MacOSX10.14.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:441:38: note: 'AVCaptureDeviceTypeBuiltInWideAngleCamera' has been explicitly marked unavailable here
AVF_EXPORT AVCaptureDeviceType const AVCaptureDeviceTypeBuiltInWideAngleCamera API_AVAILABLE(ios(10.0)) API_UNAVAILABLE(macos) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
                                     ^
/home/flibitijibibo/libraries/SDL3/src/camera/coremedia/SDL_camera_coremedia.m:448:9: error: 'AVCaptureDeviceDiscoverySession' is unavailable: not available on macOS
        AVCaptureDeviceDiscoverySession *discoverySession = [AVCaptureDeviceDiscoverySession
        ^
/home/flibitijibibo/osxcross/target/bin/../SDK/MacOSX10.14.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1711:12: note: 'AVCaptureDeviceDiscoverySession' has been explicitly marked unavailable here
@interface AVCaptureDeviceDiscoverySession : NSObject
           ^
/home/flibitijibibo/libraries/SDL3/src/camera/coremedia/SDL_camera_coremedia.m:449:25: error: 'AVCaptureDeviceDiscoverySession' is unavailable: not available on macOS
                        discoverySessionWithDeviceTypes:device_types
                        ^
/home/flibitijibibo/osxcross/target/bin/../SDK/MacOSX10.14.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1711:12: note: 'AVCaptureDeviceDiscoverySession' has been explicitly marked unavailable here
@interface AVCaptureDeviceDiscoverySession : NSObject
           ^
4 errors generated.
make[2]: *** [CMakeFiles/SDL3-shared.dir/build.make:2583: CMakeFiles/SDL3-shared.dir/src/camera/coremedia/SDL_camera_coremedia.m.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:112: CMakeFiles/SDL3-shared.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

... but this one in the dialog subsystem I'm not sure about:

/home/flibitijibibo/libraries/SDL3/src/dialog/cocoa/SDL_cocoadialog.m:25:9: fatal error: 'UniformTypeIdentifiers/UTType.h' file not found
#import <UniformTypeIdentifiers/UTType.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Are we keeping the minimum SDK at 10.11, or will it get bumped for 3.0?

slouken commented 3 months ago

It's getting bumped for 3.0, though I'm not sure what the new requirements are. It's at least 11.3.

FWIW, for older toolchains I just disable the camera and dialog subsystems, and the rest of SDL builds fine.

slouken commented 1 month ago

I updated the build requirements in 571a4b4b3, we require at least Xcode 12.2 and the macOS 11.0 SDK.

I'm not sure how we set SDK requirements in CMake? @madebr, do you know? Is that even a thing?

Also, our deployment targets are:

IPHONEOS_DEPLOYMENT_TARGET = 9.0
MACOSX_DEPLOYMENT_TARGET = 10.11
TVOS_DEPLOYMENT_TARGET = 9.0
XROS_DEPLOYMENT_TARGET = 1.0

Aside from XROS, these are all well below the minimum officially supported targets for the latest version of Xcode, but they still work well so far.

madebr commented 1 month ago

I'm not sure how we set SDK requirements in CMake? @madebr, do you know? Is that even a thing?

There is CMAKE_OSX_DEPLOYMENT_TARGET. It's meant to be set by the user.

When adding message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") at the bottom of the cmake script, does it print usable version information?

slouken commented 1 month ago

The minimum SDK is different from the deployment target. The current macOS code requires the 11.0 SDK, but the deployment target is 10.11.

madebr commented 1 month ago

From this ios toolchain, I got this.

#!/bin/sh

SDK_NAMES="iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator xros xrsimulator macosx"

for SDK_NAME in ${SDK_NAMES}; do
  CMAKE_OSX_SYSROOT_INT=$(xcodebuild -version -sdk "${SDK_NAME}" Path)
  SDK_VERSION=$(xcodebuild -sdk "${CMAKE_OSX_SYSROOT_INT}" -version SDKVersion)
  echo "SDK_NAME=${SDK_NAME} CMAKE_OSX_SYSROOT_INT=${CMAKE_OSX_SYSROOT_INT} SDK_VERSION=${SDK_VERSION}"
done

What does it output on macos?

slouken commented 1 month ago

What does it output on macos?

SDK_NAME=iphoneos CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.5.sdk SDK_VERSION=17.5 SDK_NAME=iphonesimulator CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.5.sdk SDK_VERSION=17.5 SDK_NAME=appletvos CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS17.5.sdk SDK_VERSION=17.5 SDK_NAME=appletvsimulator CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator17.5.sdk SDK_VERSION=17.5 SDK_NAME=watchos CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS10.5.sdk SDK_VERSION=10.5 SDK_NAME=watchsimulator CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator10.5.sdk SDK_VERSION=10.5 SDK_NAME=xros CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/XROS.platform/Developer/SDKs/XROS1.2.sdk SDK_VERSION=1.2 SDK_NAME=xrsimulator CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/XRSimulator.platform/Developer/SDKs/XRSimulator1.2.sdk SDK_VERSION=1.2 SDK_NAME=macosx CMAKE_OSX_SYSROOT_INT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk SDK_VERSION=14.5

slime73 commented 1 month ago

Does the SDK check need to be at the cmake level? SDL already does this, which should probably be updated: https://github.com/libsdl-org/SDL/blob/main/src/video/cocoa/SDL_cocoawindow.m#L25-L27

slouken commented 1 month ago

Actually, I build SDL3 with an older SDK and disable the camera and dialog subsystems, so I'd prefer not to hard-code the requirement. Maybe we just leave it alone for now?

flibitijibibo commented 1 month ago

I do the same thing, but that becomes a problem if SDL at a high level promises X/Y/Z but the people actually building it can only provide X/Y. That's kind of the reason I'm dropping macOS on my end despite organizing Metal support for GPU; I've been able to help Apple devs work on and support GPU for 11+ but I genuinely cannot build SDL3 here anymore, and advertising Mac support from my end while not being able to build such a major component would be really weird... disabling subsystems at the end user level makes sense but upstream doing it feels really sketchy IMO.

slouken commented 1 month ago

Yeah, to be clear, I don't disable them for public builds or development, only for another project where I have to build with a lower SDK and I'm not using those subsystems.

Is there a reason you're not able to upgrade your Xcode version?

flibitijibibo commented 1 month ago

There are a few reasons but the big one is that my MacBook was EOL'd after 10.15, so I can't even run 11.0 let alone build for it - hypothetically I could buy another Mac but I'm trying to avoid that as best as I can 😅

slouken commented 1 month ago

That's a good reason. :)

There's a bunch of changes that Apple has made in 11.0+, so if you're going to do Apple platform support you really need to have a device that can run that. You have chosen... correctly. :)