SDL 2.0
|
SDL's build system was traditionally based on autotools. Over time, this approach has suffered from several issues across the different supported platforms. To solve these problems, a new build system based on CMake was introduced. It is developed in parallel to the legacy autotools build system, so users can experiment with it without complication.
The CMake build system is supported on the following platforms:
Assuming the source for SDL is located at ~/sdl
This will build the static and dynamic versions of SDL in the ~/build
directory. Installation can be done using:
SDL can be included in your project in 2 major ways:
The following CMake script supports both, depending on the value of MYGAME_VENDORED
.
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 |
---|---|
SDL2 | The SDL2 shared library, available through the SDL2::SDL2 target [^SDL_TARGET_EXCEPTION] |
SDL2-static | The SDL2 static library, available through the SDL2::SDL2-static target |
SDL2main | The SDL2main static library, available through the SDL2::SDL2main target |
SDL2test | The SDL2test static library, available through the SDL2::SDL2test target |
This only requires a copy of SDL in a subdirectory.
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:
CMAKE_SYSTEM_NAME=<OS>
(either iOS
or tvOS
)CMAKE_OSX_SYSROOT=<SDK>
(examples: iphoneos
, iphonesimulator
, iphoneos12.4
, /full/path/to/iPhoneOS.sdk
, appletvos
, appletvsimulator
, appletvos12.4
, /full/path/to/AppleTVOS.sdk
, etc.)CMAKE_OSX_ARCHITECTURES=<semicolon-separated list of CPU architectures>
(example: "arm64;armv7s;x86_64")for iOS-Simulator, using the latest, installed SDK:
for iOS-Device, using the latest, installed SDK, 64-bit only
for iOS-Device, using the latest, installed SDK, mixed 32/64 bit
for iOS-Device, using a specific SDK revision (iOS 12.4, in this example):
for iOS-Simulator, using the latest, installed SDK, and building SDL test apps (as .app bundles):
for tvOS-Simulator, using the latest, installed SDK:
for tvOS-Device, using the latest, installed SDK:
[^SDL_TARGET_EXCEPTION]: SDL2::SDL2
can be an ALIAS to a static SDL2::SDL2-static
target for multiple reasons.