summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/docs/INTRO-cmake.md
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/docs/INTRO-cmake.md')
-rw-r--r--src/contrib/SDL-3.2.20/docs/INTRO-cmake.md57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/docs/INTRO-cmake.md b/src/contrib/SDL-3.2.20/docs/INTRO-cmake.md
new file mode 100644
index 0000000..05990e4
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/docs/INTRO-cmake.md
@@ -0,0 +1,57 @@
1
2# Introduction to SDL with CMake
3
4The easiest way to use SDL is to include it as a subproject in your project.
5
6We'll start by creating a simple project to build and run [hello.c](hello.c)
7
8# Get a copy of the SDL source:
9```sh
10git clone https://github.com/libsdl-org/SDL.git vendored/SDL
11```
12
13# Create the file CMakeLists.txt
14```cmake
15cmake_minimum_required(VERSION 3.16)
16project(hello)
17
18# set the output directory for built objects.
19# This makes sure that the dynamic library goes into the build directory automatically.
20set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
21set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
22
23# This assumes the SDL source is available in vendored/SDL
24add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL)
25
26# Create your game executable target as usual
27add_executable(hello WIN32 hello.c)
28
29# Link to the actual SDL3 library.
30target_link_libraries(hello PRIVATE SDL3::SDL3)
31```
32
33# Configure and Build:
34```sh
35cmake -S . -B build
36cmake --build build
37```
38
39# Run:
40The executable should be in the `build` directory:
41
42```sh
43cd build
44./hello
45```
46
47If there wasn't an executable there despite the above Build section running successfully, it's likely because you're following this guide using the Visual Studio toolchain, it should instead be in the `build/Debug` directory:
48```sh
49cd build/Debug
50./hello
51```
52
53A more complete example is available at:
54
55https://github.com/Ravbug/sdl3-sample
56
57Additional information and troubleshooting is available in [README-cmake.md](README-cmake.md)