Giter Club home page Giter Club logo

sdl2-macos-sample's Introduction

How to Create a macOS SDL2 App Xcode Project For Fun and Profit

Initial Project Creation

  1. In Xcode, create a New Project. Choose "macOS->App". Don't select "Command-line App".
  2. In the window that pops up, enter your project name and other details such as the bundle identifier.
  3. For Interface, choose XIB
  4. For Language, choose Objective-C (your app doesn't have to be written in Objective-C)
  5. For Storage, choose None.
  6. 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.

Setup

  1. 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.

  1. Using Finder, copy SDL2.framework (that you either downloaded from libsdl.org or built yourself) to the same folder as YourProject.xcodeproj.

  2. In your project's build settings, choose the YourProject target.

  3. In the General tab, find the Frameworks, Libraries, and Embedded Content section. Click the "+", choose Add Other->Add Files and choose SDL2.framework from step 2. Make sure it's the one from Step 2, that's next to YourProject.xcodeproj. You should now see SDL2.framework in the Frameworks, Libraries, and Embedded Content secion, with Embed & Sign next to it.

  4. In the Build Settings tab, search for Framework Search Paths and double check that Xcode has correctly added $(PROJECT_DIR)

  5. In the Signing & Capabilities tab, in the App Sandbox section, check USB (otherwise your app won't be able to use game controllers). Change User Selected File to Read/Write.

  6. Set up the rest of your project's settings. Choose the App Category, set up Code Signing, set the Minimum Deployment Target, etc.

  7. Either create a new file named main.c (or main.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.

Troubleshooting

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:

  1. Go to the project settings, under the Signing & Capabilities tab, scroll down and check Disable Library Validation. Then rebuild your app.
  2. Use an SDL2.framework that you built and whose code signing matches your app's code signing.

sdl2-macos-sample's People

Contributors

sridenour avatar

Watchers

 avatar  avatar

Forkers

kwccoin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.