SDL Wiki



The CMake build system is supported on the following platforms:

Building SDL

Assuming the source for SDL is located at ~/sdl.

cmake -S ~/sdl -B ~/build
cmake --build ~/build

This will build SDL in the ~/build directory. Installation can be done using:

cmake --install ~/build --prefix /usr/local        # '--install' requires CMake 3.15, or newer

This will install SDL to /usr/local.

Including SDL in your project

SDL can be included in your project in 2 major ways:

The following CMake script supports both, depending on the value of MYGAME_VENDORED.

cmake_minimum_required(VERSION 3.0)

# Create an option to switch between a system sdl library and a vendored sdl library
option(MYGAME_VENDORED "Use vendored libraries" OFF)

    add_subdirectory(vendored/sdl EXCLUDE_FROM_ALL)
    # 1. Look for a SDL3 package, 2. look for the SDL3 component and 3. fail if none can be found

# Create your game executable target as usual
add_executable(mygame WIN32 mygame.c)

# Link to the actual SDL3 library. SDL3::SDL3 is the shared SDL library, SDL3::SDL3-static is the static SDL libarary.
target_link_libraries(mygame PRIVATE SDL3::SDL3)

A system SDL library

For CMake to find SDL, it must be installed in a default location CMake is looking for.

The following components are available, to be used as an argument of find_package.

Component name Description
SDL3-shared The SDL3 shared library, available through the SDL3::SDL3-shared target
SDL3-static The SDL3 static library, available through the SDL3::SDL3-static target
SDL3_test The SDL3_test static library, available through the SDL3::SDL3_test target
SDL3 The SDL3 library, available through the SDL3::SDL3 target. This is an alias of SDL3::SDL3 or SDL3::SDL3-static. This component is always available.
Headers The SDL3 headers, available through the SDL3::Headers target. This component is always available.

Using a vendored SDL

This only requires a copy of SDL in a subdirectory.

CMake configuration options for platforms


CMake 3.14+ natively includes support for iOS and tvOS. SDL binaries may be built using Xcode or Make, possibly among other build-systems.

When using a recent version of CMake (3.14+), it should be possible to:

To use, set the following CMake variables when running CMake's configuration stage:


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.