A simple CMake SDL test project
- CMake 3.1.0 or greater
- A C++11 toolchain:
- Microsoft Visual Studio Community Edition is a gratis option for Windows. (2013+)
- XCode
- GCC / GNU Make [Configuration depends on OS]
- Optionally Ninja for faster builds
- Eclipse CDT
- Codeblocks
- etc.
- LibSDL2 Development Libraries
- If you're on Windows, set an SDL2LIB environment variable to the path of your SDL2 installation.
- If you're on Mac OS X, use Homebrew.
brew install sdl2
- GNU/Linux should be straightforward, e.g.
apt-get install libsdl2-dev
CMake is a Makefile generator. That means a single CMake configuration can be used to build and deploy software for any toolchain which supports it, e.g. GNU Make, Visual Studio, XCode, etc.
What this means for us is that we need to run CMake first to generate our build, and then run the build using our native toolchain.
List available toolchains:
cmake --help
...
Generators
The following generators are available on this platform:
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files (experimental).
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles
= Generates Eclipse CDT 4.0 project files.
KDevelop3 = Generates KDevelop 3 project files.
KDevelop3 - Unix Makefiles = Generates KDevelop 3 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
Use your generator:
Note: for Windows
NMake Makefiles
andNinja
, you'll need to be in the Developer command prompt.
git clone https://github.com/binary132/cmake-sdl.git
cd cmake-sdl
cd build
cmake -G "Ninja" .. # Or -G "NMake Makefiles" on Windows
ninja # or nmake, or make, or open project file in XCode, etc.
The result should be a successful build, with an executable in <project root>/build/target
named SDLTest
.
For an OS with a distribution of SDL2 installed, the binary should be executable as-is. On Windows, you'll need to copy SDL2.dll
from your SDL2 install location.