diff options
author | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
commit | 6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch) | |
tree | 34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/docs/INTRO-cmake.md | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
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.md | 57 |
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 | |||
4 | The easiest way to use SDL is to include it as a subproject in your project. | ||
5 | |||
6 | We'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 | ||
10 | git clone https://github.com/libsdl-org/SDL.git vendored/SDL | ||
11 | ``` | ||
12 | |||
13 | # Create the file CMakeLists.txt | ||
14 | ```cmake | ||
15 | cmake_minimum_required(VERSION 3.16) | ||
16 | project(hello) | ||
17 | |||
18 | # set the output directory for built objects. | ||
19 | # This makes sure that the dynamic library goes into the build directory automatically. | ||
20 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>") | ||
21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>") | ||
22 | |||
23 | # This assumes the SDL source is available in vendored/SDL | ||
24 | add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL) | ||
25 | |||
26 | # Create your game executable target as usual | ||
27 | add_executable(hello WIN32 hello.c) | ||
28 | |||
29 | # Link to the actual SDL3 library. | ||
30 | target_link_libraries(hello PRIVATE SDL3::SDL3) | ||
31 | ``` | ||
32 | |||
33 | # Configure and Build: | ||
34 | ```sh | ||
35 | cmake -S . -B build | ||
36 | cmake --build build | ||
37 | ``` | ||
38 | |||
39 | # Run: | ||
40 | The executable should be in the `build` directory: | ||
41 | |||
42 | ```sh | ||
43 | cd build | ||
44 | ./hello | ||
45 | ``` | ||
46 | |||
47 | If 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 | ||
49 | cd build/Debug | ||
50 | ./hello | ||
51 | ``` | ||
52 | |||
53 | A more complete example is available at: | ||
54 | |||
55 | https://github.com/Ravbug/sdl3-sample | ||
56 | |||
57 | Additional information and troubleshooting is available in [README-cmake.md](README-cmake.md) | ||