lodestone.life

Initializing SDL3 as a git submodule

Create a project directory similar to:

project/
|- CMakeLists.txt
|- external/
|_ src/
	|_ main.c

Initialize git and add SDL3:

git init
git submodule add https://github.com/libsdl-org/SDL.git external/SDL
git submodule update --init --recursive

Add SDL3 to your CMAKE:

cmake_minimum_required(VERSION 3.24)
set(CMAKE_CXX_STANDARD 23)

project(SDL3Test)

add_subdirectory(external/SDL)
add_executable(SDL3Test src/main.c)

# Statically link SDL3
set(SDL_SHARED OFF CACHE BOOL "Build SDL shared library" FORCE)
set(SDL_STATIC ON CACHE BOOL "Build SDL static library" FORCE)

target_link_libraries(SDL3Test PRIVATE SDL3::SDL3)

[!note] Make sure to make a .gitignore file and add the build directory to it.

Afterwards, make and move to the build directory:

mkdir build && cd build

Resources

https://wiki.libsdl.org/SDL3/README/cmake
https://lazyfoo.net/tutorials/SDL3/01-hello-sdl3/index2.php
https://github.com/nicbarker/clay/blob/main/README.md
https://github.com/libsdl-org/SDL/blob/main/examples/demo/01-snake/snake.c
https://wiki.libsdl.org/SDL3/SDL_Event
https://wiki.libsdl.org/SDL3/FrontPage
https://www.youtube.com/watch?v=bO2Zayh12-Q