A project template for SDL-based programs targeting several platforms:
- Windows
- Linux
- macOS
- Android
- Emscripten
Clone repository and update submodules:
git clone https://github.com/genpfault/sdl-base.git
git submodule update --init --recursive
Ensure CMake (>= 3.18) and Ninja are in your PATH:
-
Configure:
cmake -B build -G "Ninja Multi-Config" . -
Build:
cmake --build build --config ReleaseThe Ninja Multi-Config generator lets you use other
CMAKE_BUILD_TYPEs like "Debug" or "RelWithDebInfo" can be used instead of "Release".
The resulting binaries are in build/<build-type>/
You can build with the Visual Studio command-line tools by running vcvarsall.bat (locations vary) in your shell before running cmake:
# 32-bit
path\to\vcvarsall\vcvarsall.bat x86
# 64-bit
path\to\vcvarsall\vcvarsall.bat amd64
Alternatively, generate a Visual Studio project with one of the Visual Studio generators and an architecture flag. For example:
# 32-bit
cmake -B build -G "Visual Studio 16 2019" -A Win32 .
# 64-bit
cmake -B build -G "Visual Studio 16 2019" -A x64 .
Install the build dependencies for your distro's SDL package.
For Debian & derivatives:
-
Enable the
deb-srcarchives and update the package lists:sudo apt update -
Install the dependencies for
libsdl2:sudo apt build-dep libsdl2
-
Install Homebrew, which automatically installs the XCode command line tools.
-
Install CMake and Ninja using Homebrew:
brew install cmake brew install ninja -
Configure/build using the generic instructions above.
-
Bootstrap an Android SDK command-line tools install with these instructions and add an
ANDROID_HOMEvariable pointing at the root of it to your envrionment. -
SDK setup:
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "cmake;3.22.1"Gradle will automatically pull in the rest of the SDK depdendencies using
sdkmanagerin the next step. -
Build:
cd android ./gradlew build -
Deploy to connected device:
./gradlew installRelease
-
Activate the Emscripten environment:
# linux: source /path/to/emsdk/emsdk_env.sh # windows: path\to\emsdk\emsdk_env.bat -
Use
emcmaketo wrap the configuration command:emcmake cmake -B build -G "Ninja Multi-Config" . -
Build using a regular
cmakecommand:cmake --build build --config Release -
Run using
emrun:emrun build/Release/sdl-base.html