SFML and Xcode in Silicon Mac OSX

Getting SFML set up with Xcode is a bit of a pain with M1 Mac's, here is what I did to get it working (not including any C++ setup that I'd done a while earlier).

ARM Compatible SFML binaries

The current stable releases (2.5.1 at time of writing) are not compatible with M1 Macs, however the nightly snapshots for the project have ARM compatibility buils

The latest stable at the time of writing (2.5.1) is not compatible with M1 Macs, being for the intel architecture. In the snapshots (which is for 3.0+) the team has released ARM compatibility builds. Look for macos-clang-arm64.tar.gz in the snapshots page.

The structure in the zip is slightly different from the current stable build, so the installation instructions need to be modified slightly. After unzipping everything is within a Library/Frameworks folder and needs separating out:

  • For dylibs to be used, which I've found to be the only way to get the templates to work, you need to copy the include folder to /usr/local/include. The dylib files themselves are in the lib folder. These are sitting alongside the external libraries, so copy just the files (not the folders) to /usr/local/lib. They should all end in .dylib
  • To install the SFML dependencies, copy the folders within the lib folderwith .framework in the title to /Library/Frameworks (these are ones like ogg.framework and vorbis.framework)
  • To install the SFML framework binaries (maybe you'll have better luck with them than me), copy the .framework folders that are sibling folders to include and lib to the /Library/Frameworks system folder.

(maybe optional) Xcode templates

When installing SFML I also grabbed the Xcode templates from the latest stable build to help with setting up projects. Just follow the usual instructions for this.

Creating your first SFML program

In Xcode create a new project and under the Mac OS section select the new "SFML App" template. Fill in the details on the create dialog. As mentioned above: for the SFML binaries I couldn't get Frameworks working so opted for Dylibs.

Once the project is created go into the project settings.

  • In General change the Minimum Deployments to at least 12.0
  • In Build Settings: Change the "C++ Language Dialect" to at least C++14
  • In Build Phases->Run Script select "For install builds only"

Now the hardest part, getting OSX to trust the external libraries. I found this to be very fiddly, I had the System Preferences->Security Settings in one screen and Xcode in the other. When I went to run the build Xcode kept stating that each of the libraries was from an unknown developer, clicking Cancel would then have a message show in Security Settings to "Allow anyway". Click on that and then continue through the messages one by one. I had to go through it several times as there seems to be a bit of timing involved between being able to "Allow anyway" and the next dialog showing. Eventually I had bypassed the security setting for each of them.

But wait there's more...

Once all that configuration was done the build will still not work, as SFML 3.0+ has changed some of the interfaces from the template. The change is fairly easy though, instead of passing in coordinates separately they're using the Vector2u class. Instead of sf::VideoMode(800, 600) you want sf::VideoMode(sf::Vector2u(800, 600)), and instead of window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelPtr()); you want window.setIcon(icon.getSize(), icon.getPixelPtr());

You won't need to worry about this if building from scratch, but you do need to follow SFML 3.0+ interfaces.

This was a several hour hunt to get to this point, so hope this helps! If you stumble across this in the future and something isn't working please post a comment. And if you stumble across a solution for future versions please share!

Blambo

Blambo