summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/docs/INTRO-cmake.md
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/docs/INTRO-cmake.md')
-rw-r--r--contrib/SDL-3.2.8/docs/INTRO-cmake.md50
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/docs/INTRO-cmake.md b/contrib/SDL-3.2.8/docs/INTRO-cmake.md
new file mode 100644
index 0000000..e6ccace
--- /dev/null
+++ b/contrib/SDL-3.2.8/docs/INTRO-cmake.md
@@ -0,0 +1,50 @@
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
8Create the file CMakeLists.txt
9```cmake
10cmake_minimum_required(VERSION 3.16)
11project(hello)
12
13# set the output directory for built objects.
14# This makes sure that the dynamic library goes into the build directory automatically.
15set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
16set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
17
18# This assumes the SDL source is available in vendored/SDL
19add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL)
20
21# Create your game executable target as usual
22add_executable(hello WIN32 hello.c)
23
24# Link to the actual SDL3 library.
25target_link_libraries(hello PRIVATE SDL3::SDL3)
26```
27
28Build:
29```sh
30cmake -S . -B build
31cmake --build build
32```
33
34Run:
35- On Windows the executable is in the build Debug directory:
36```sh
37cd build/Debug
38./hello
39```
40- On other platforms the executable is in the build directory:
41```sh
42cd build
43./hello
44```
45
46A more complete example is available at:
47
48https://github.com/Ravbug/sdl3-sample
49
50Additional information and troubleshooting is available in [README-cmake.md](README-cmake.md)