It's not a very difficult thing to do, but clear, simple instructions can be useful. Thankfully, there's a good Getting Started guide with official documentation for building SFML (and you really should read it). If, after reading that, you want things spelled out even more... here you go.
Step 1: Prepare Xcode
Make sure you have Xcode downloaded and installed. Make sure you have your command line tools set up. You do this by doing
Xcode -> Preferences -> Downloads and making sure you have
Command Line Tools downloaded and installed.
Step 2: Prepare Cmake
I won't go into what Cmake is, but download and install the latest version. SFML needs it.
Step 3: Download SFML 2
Step 4: Open a Terminal
Hopefully you've got the Terminal sitting on your dock, but in case not it can be found under
Applications -> Utilities -> Terminal.app.
Step 5: Set up Cmake
In your terminal, run:
This tells Cmake you're going to be making 32-bit and 64-bit universal builds. If you want only 32-bit, just set it to
i386. If you want only 64-bit, set it to
x86_64. I recommend building both though in a universal build. It'll help when you want to distribute your program.
Step 6: Get Ready to Build
Next, do the following in your terminal:
cd <sfml folder>
In the first line, replace
<sfml folder> with the path to the folder where you downloaded and extracted the SFML source to.
mkdir build just creates the directory
build where we can do our dirty work, and
cd build moves into that folder.
Step 7: Run Cmake
Now run the following (you can copy and paste):
cmake -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang -DSFML_BUILD_FRAMEWORKS=ON \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_C_FLAGS="-stdlib=libc++" ../
This runs Cmake and tells it to do a few things. Particularly, it's saying "Use
clang to build (which is what gives us the C++11 features we're wanting), build frameworks, build templates for Xcode so I can easily create SFML projects, and make sure you use the C++11 standard library." This doesn't actually build SFML, but it sets everything up so we can run the next two commands...
Step 8: Build!
make is a fancy program that will actually do all the building of SFML for you. The
-j4 option just says "Use 4 threads to do this." If you don't want to use multiple threads to build (which is sloooow), you can omit this option. If you want to use more threads, like 8, you can change it to
-j8 (I personally use 8 threads).
Step 9: Install!
The last step:
sudo make install
This will prompt you for your password. Give it your password. It'll place all the SFML files in their final resting place on your system, and it needs some elevated privileges to write the files to the necessary folders. If you're curious where it's writing the files to, just look at the output. Anyway, now you're done!
Bonus Step: Making an Xcode Project
What good is building and installing SFML if you don't use it? We'll set up a simple project now. Open Xcode. Then create a new project. Then select the
SFML App template:
In the next screen, give your project a name. Make sure to say you want to use C++11! The "C++ Compiler and Standard Library" option does not default to Clang and C++11. You have to set this yourself. Assuming you followed my instructions and made SFML a universal framework for 32-bit and 64-bit, the rest of the options can stay the same.
You should now be able to run the created project!