Improving the iOS experience

Hey everyone! I’ve been working on some games and a simple 2D engine which powers them, aptly named Simple 2D, which acts as a very thin layer on top of SDL and OpenGL to make game prototyping a bit easier and faster, and also to enable higher-level scripting with Ruby 2D. My ultimate goal is to get this library working (i.e. these test programs running) on all platforms SDL supports. So far, I’ve been successful building apps from the command line on macOS, Windows, Linux, and Raspberry Pi. Now, I’m venturing into iOS (and Android after that).

I’ve noticed the SDL iOS experience is somewhat inconsistent and in need of a bit more documentation, which I hope to help improve. Namely, the SDL2 source comes with an awesome script, which automates the building of the library archive for all architectures, but SDL2_image, SDL2_mixer, and SDL2_ttf do not have such a script. As for the Xcode-iOS sample projects in the sources, only SDL2_ttf has its dependency, freetype, added to the project for building. (I realize that the dependencies for SDL2_image and SDL2_mixer are actually optional, which is why they probably aren’t in the Xcode projects.)

If I could propose a user story, it would be:
As a game and engine developer, I want a single, command-line script to build the entire SDL2 library, including SDL2_image, SDL2_mixer, SDL2_ttf, and their respective dependencies for all architectures so that I can quickly build the libraries I need to link to my iOS and tvOS application.

I’m happy to build and document whatever is needed to fill in the gaps and accomplish this, but wanted to check with the community here first to see if there have already been efforts to do this, and if folks think this is generally a good idea to begin with. Would love any feedback and public iOS examples people have.

Thanks so much,

I haven’t heard of anything along those lines that is specific to SDL, however, I do recall seeing a few, newish, C/C++ package managers pop up within the past few years. Might some amount of work with one or more those be a prudent route?

It sort of sounds like you want some sort of C/Objective-C package manager? Maybe cocoapods support is the way to go? I don’t know if that’s still a relevant modern option - I used it a few years ago, and it was alright, but not optimal. I haven’t written a podspec file before, so maybe it isn’t the right thing at all. Can anyone with better cocoapods experience chime in here?

1 Like

Thanks @David_Ludwig and @Alex_Barry — great suggestion! I’m an avid user of Homebrew (even made my own tap for Simple 2D), but didn’t think to check out CocoaPods, d’oh. :slight_smile:

I was hoping that someone would’ve beat me to it and created SDL2 pods, but alas, nothing. Guess the audience using CocoaPods doesn’t intersect with those building games with SDL. Oh well. I’ll continue researching a strategy here. I’ve found some helpful gists for compiling libs like jpeg, png, tiff, zlib. Interestingly, webp comes with its own in the SDL2_mixer source. I should be able to adapt those build scripts to the remaining external/ libs in SDL2_mixer and SDL2_ttf. Then, (thinking out loud) maybe make an updated Xcode project for each (image, mixer, ttf) with the dependency libs linked, whose builds can be automated through xcodebuild. Finally, make a new, master SDL2 project template with image, mixer, ttf linked and ready for user code.

Not sure if I’ve got this right, but I’ll give it a go and report back.

1 Like

It would be awesome to make a single cmake or thing for this to export into visual studio or Xcode.

1 Like

I’ve been working on making a simple as possible basis for building cross platform SDL apps too. The idea being that all you should need is one cmake project to build on all platforms (and a little additional stuff for platforms like android and ios):

It’s still work in progress, but I’ve already done some fixes to SDL to get it properly working with android+gradle+cmake. I’m planning on making it work with ios too at some point.

Currently SDL is just included as a subproject (as source), but I think it would be nice to be able to automatically download prebuilt SDL binaries or for example use an installed version on linux. But I didn’t want to complicate the project too much yet. Also maybe in the future it could be possible to use prebuilt SDL library on android too.

I’d like to make including SDL2_image and the others easier too, but I haven’t really looked into that yet. With a quick glance it seems that they are currently not supporting cmake at all. So either cmake support needs to be added or the system needs support downloading prebuilt versions somehow.

1 Like

Hey all, just wanted to provide an update here.

Having had no prior Xcode or iOS experience, I’ve learned A TON since first posting this thread a month ago. My goal was to simplify and perhaps improve the “getting started” experience with SDL2, SDL2_image, SDL2_mixer, and SDL2_ttf on both iOS and tvOS, and I think I’ve been able to do just that.

First thing to note is that working with the SDL projects independently is pretty straightforward, but things get complicated when using them all together. I made an early attempt to use the standard ./configure && make && make install approach in a build script, but cross compilation and config issues made it so frustratingly difficult, I abandoned that route.

I then turned to the Xcode-iOS projects included in each SDL repo, which are all in pretty good condition — some outdated build settings, but nothing critical. Biggest benefit here is that all the proper source files have been added to the project (@David_Ludwig is actually working on a patch to be able to compile the entire src/ directory, so we don’t have to worry about omitting the right sources for each platform), and the right preprocessor configs are present. Here’s the build script I was able to write to make static libraries of SDL2, SDL2_image, SDL2_mixer, and SDL2_ttf for all iOS and tvOS architectures, and create a universal SDL2.framework (with image, mixer, and ttf packed in) for a more natural app development experience. Check out resulting iOS and tvOS libraries and frameworks (might be worth considering adding these to the page).

Some caveats to note with SDL2_mixer:

  • MODPlug failed to compile in the Xcode-iOS project, so I omitted MODPLUG_MUSIC and MODPLUG_HEADER="<modplug.h>" from the Preprocessor Macros currently in the project’s build settings, which can be done by providing our own GCC_PREPROCESSOR_DEFINITIONS when calling xcodebuild from the command line (see the build script for details).
  • SMPEG2 isn’t already in the Xcode-iOS project, and so mixer is built without MP3 support. Not sure if SMPEG2 actually has iOS support or not anyways. Or maybe we should suggest people use whatever the platform SDKs natively support. Either way, something to investigate.

Other than that, everything works quite well. I’m particularly excited about the SDL2.framework, because it means all you have to do to get started is:

  1. Create a new Xcode project for iOS or tvOS, a “Single View Application”
  2. Remove the generated sources and headers, add your own main.c
  3. Add the following “Linked Frameworks and Libraries”, including the new SDL2 framework: AudioToolbox, AVFoundation, CoreGraphics, CoreMotion, Foundation, GameController, ImageIO, MobileCoreServices, OpenGLES, QuartzCore, UIKit
  4. Hit run!

Clearly a ton of prior work was put into the SDL projects to get all this running so smoothly on iOS and tvOS, so I’m deeply grateful to all who worked on it.

If y’all have any feedback, let me know! Hope you enjoy!