- In Xcode, create a New Project. Choose "macOS->App". Don't select "Command-line App".
- In the window that pops up, enter your project name and other details such as the bundle identifier.
- For Interface, choose XIB
- For Language, choose Objective-C (your app doesn't have to be written in Objective-C)
- For Storage, choose None.
- Click Next, and choose where you want your project to be created.
You now have an Xcode project that will create a full-blown macOS Cocoa app, with an app bundle that can have SDL2 embedded in it for easy distribution.
The reasoning behind not creating a command-line app is that we want a full-blown Mac app (aka an App Bundle) that we can embed SDL2.framework
and our app's assets inside, and that can be notarized and distributed. If you instead select the "Command-line App" template, Xcode creates a project that just builds a bare binary.
- Xcode will have created some stuff we don't need (SDL provides it for us). Delete the following files:
- AppDelegate.h
- AppDelegate.m
- MainMenu.xib
- main.m (even this one)
Make sure to choose "Move to Trash" when Xcode asks if you want to really delete them or just remove them from the project file.
-
Using Finder, copy
SDL2.framework
(that you either downloaded from libsdl.org or built yourself) to the same folder asYourProject.xcodeproj
. -
In your project's build settings, choose the YourProject target.
-
In the
General
tab, find theFrameworks, Libraries, and Embedded Content
section. Click the "+", chooseAdd Other
->Add Files
and chooseSDL2.framework
from step 2. Make sure it's the one from Step 2, that's next toYourProject.xcodeproj
. You should now seeSDL2.framework
in theFrameworks, Libraries, and Embedded Content
secion, withEmbed & Sign
next to it. -
In the
Build Settings
tab, search forFramework Search Paths
and double check that Xcode has correctly added$(PROJECT_DIR)
-
In the
Signing & Capabilities
tab, in theApp Sandbox
section, check USB (otherwise your app won't be able to use game controllers). ChangeUser Selected File
toRead/Write
. -
Set up the rest of your project's settings. Choose the App Category, set up Code Signing, set the Minimum Deployment Target, etc.
-
Either create a new file named
main.c
(ormain.cpp
or whatever) or add your app's source code to the project.
You should now have a working Xcode project that builds a macOS app that uses SDL. SDL2.framework
will be bundled inside the app.
If you run your app and get an error along the lines of not being able to validate SDL2.framework
or some such, there are two options:
- Go to the project settings, under the
Signing & Capabilities
tab, scroll down and checkDisable Library Validation
. Then rebuild your app. - Use an
SDL2.framework
that you built and whose code signing matches your app's code signing.