Building for iOS at the command line

I know that the Xcode projects for iOS and MacOS have been merged in recent releases of SDL2, with them now being different targets rather than separate project files. But what’s the new syntax for building libSDL2.a for iOS at the command line?

With the separate project for iOS it used to be:

PROJ="-project SDL.xcodeproj"
SDK_DEVICE="-sdk iphoneos"
CONF_RELEASE="-configuration Release"
SCHEME="libSDL"

xcodebuild OTHER_CFLAGS="-fembed-bitcode" ONLY_ACTIVE_ARCH=NO -arch arm64 $PROJ $SDK_DEVICE $CONF_RELEASE -scheme='$SCHEME' build $SYMROOT

I presume I need to modify this to stop it trying to build for MacOS (which fails anyway), but I don’t know the required incantation!

1 Like

Experimentally it looks like -target 'Static Library-iOS' is the magic word, but I would appreciate confirmation from an expert. :slightly_smiling_face:

That should be it, IIRC.

(haven’t tried to build anything with Xcode from the command line in a long time)

1 Like

Seems to work. I had to add the CoreHaptics framework as well, but my app seems to build successfully with SDL 2.26.2. :grinning:

Using this script to trigger xcode in command line to build sdl2 & libs for ios/tvos:
Script to build SDL libs on iOS / tvOS · Issue #4410 · libsdl-org/SDL · GitHub

Looks like you’re using -scheme rather than -target to isolate just the iOS build. Is there any advantage in doing that? As far as I can tell -target is doing what I want.

Schemes can have different actions and are associated with a target. Available actions:

  • build
  • archive
  • test
  • installsrc
  • install
  • clean

I didn’t notice at the time, but the scheme specified in your OP isn’t one of the schemes in the actual SDL Xcode project, which is why it wasn’t working. That’s why you also had to specify a target. Since each target is already associated with a scheme, you can just specify the scheme.

You can see which schemes are available in Xcode in the scheme navigator

Since it seems like you’re trying to build the static library, for macOS use Static Library as the scheme, and for iOS use Static Library-iOS

Then you won’t have to specify a target.

1 Like

It was working, in the sense that it was building for both MacOS and iOS. But the MacOS build fails which is why I’ve now specified an explicit target. My command line still includes that same scheme:

-target 'Static Library-iOS' -scheme='libSDL'

I’m happy with the results I am getting, but if I do encounter any problems from specifying a ‘non-existent’ scheme I can try the method you use.

I suspect the reason it worked is that the syntax is wrong: -scheme=. The equals sign is probably making it create an environment variable! That is what was in the original script I was given a long time ago - probably by you!

I’m now trying to do the same for SDL_ttf, but the SDL_ttf.xcodeproj file does not include a Static Library-iOS scheme, indeed it seems only to include targets for MacOS! What should I do to build a static SDL_ttf library for iOS?

Found the answer here.