We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4808

Summary: CMake: add support for iOS and tvOS
Product: SDL Reporter: David Ludwig <dll>
Component: buildAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: HG 2.0Keywords: target-2.0.12
Hardware: iPhone/iPod touch   
OS: Other   
Attachments: two hg commits, "hg export"'ed from a rebase on top of hg changeset 13082:f77988be3607

Description David Ludwig 2019-09-23 18:29:33 UTC
Created attachment 3973 [details]
two hg commits, "hg export"'ed from a rebase on top of hg changeset 13082:f77988be3607

The current crop of CMake scripts for SDL2 does not handle CMake-native support for iOS and tvOS.  Attached is a patch that adds support for both OSes.

When using a recent version of CMake (3.14+), the patch should make it possible to:
- build SDL for iOS, both static and dynamic
- build SDL test apps (as iOS/tvOS .app bundles)
- generate a working SDL_config.h for iOS (using SDL_config.h.cmake as a basis)

To use, set the following CMake variables when running CMake's configuration stage:
- CMAKE_SYSTEM_NAME=<OS>   (either "iOS" or "tvOS")
- CMAKE_OSX_SYSROOT=<SDK>  (examples: iphoneos, iphonesimulator, iphoneos12.4, /full/path/to/iPhoneOS.sdk,
                              appletvos, appletvsimulator, appletvos12.4, /full/path/to/AppleTVOS.sdk, etc.)
- CMAKE_OSX_ARCHITECTURES=<semicolon-separated list of CPU architectures> (example: "arm64;armv7s;x86_64")


Examples:
- for iOS Simulator, using the latest, installed SDK:
    cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64

- for iOS Device, using the latest, installed SDK, 64-bit only
    cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64

- for iOS Device, using the latest, installed SDK, mixed 32/64 bit
    cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES="arm64;armv7s"

- for iOS Device, using a specific SDK revision (iOS 12.4, in this example):
    cmake path/to/SDL -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos12.4 -DCMAKE_OSX_ARCHITECTURES=arm64

- for iOS Simulator, using the latest, installed SDK, and building SDL test apps (as .app bundles):
    cmake path/to/SDL -DSDL_TEST=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64
Comment 1 Ryan C. Gordon 2019-09-23 18:33:31 UTC
This patch looks good to me, go ahead and push it, please!

--ryan.
Comment 2 Sam Lantinga 2019-09-23 18:33:42 UTC
This looks good to me. Can you add the documentation for using this to the appropriate README file?
Comment 3 David Ludwig 2019-09-23 18:35:47 UTC
I'll modify the documentation within the next day or so, then I'll push it out.  Thanks!
Comment 4 David Ludwig 2019-09-23 21:11:11 UTC
Looks like I'll also need to do a few, hopefully-minor modifications in order to help support iOS 13.

More to come...
Comment 5 David Ludwig 2019-09-23 22:32:12 UTC
This is now pushed to hg.libsdl.org/SDL.  I'll monitor buildbot, and if nothing new+bad comes up, I'll close this case.
Comment 6 David Ludwig 2019-09-23 22:39:50 UTC
Buildbot is passing, although it does look like the iOS and macOS test machine(s) are currently offline.  :-(

If any problems come up with this, I'm happy to try re-investigating.  Otherwise, I'm going to go ahead and mark this case as RESOLVED.