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