Skip to content

Commit 8edd2eb

Browse files
authored
Add SDL3 CMake config file (#23869)
This is the equivalent of, and heavily based on, #15987 but for SDL3. Assuming that I've understood #19780 (comment) correctly, none of the old style variables are expected to be set so we only need to provide targets. This has the benefit that it Just Works without needing to run `emcc -sUSE_SDL=3` first to download the port.
1 parent aeaecab commit 8edd2eb

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
if(NOT TARGET SDL3::SDL3)
2+
add_library(SDL3::Headers INTERFACE IMPORTED)
3+
set_target_properties(SDL3::Headers PROPERTIES
4+
INTERFACE_COMPILE_OPTIONS "-sUSE_SDL=3"
5+
)
6+
7+
add_library(SDL3::SDL3-static INTERFACE IMPORTED)
8+
set_target_properties(SDL3::SDL3-static PROPERTIES
9+
INTERFACE_COMPILE_OPTIONS "-sUSE_SDL=3"
10+
INTERFACE_LINK_LIBRARIES "-sUSE_SDL=3"
11+
)
12+
13+
add_library(SDL3::SDL3 INTERFACE IMPORTED)
14+
set_target_properties(SDL3::SDL3 PROPERTIES
15+
INTERFACE_COMPILE_OPTIONS "-sUSE_SDL=3"
16+
INTERFACE_LINK_LIBRARIES "-sUSE_SDL=3"
17+
)
18+
endif()

test/cmake/find_modules/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ project(find_modules)
44
add_executable(test_prog test.c)
55

66
find_package(OpenGL REQUIRED)
7-
include_directories(${OPENGL_INCLUDE_DIR})
7+
target_include_directories(test_prog PRIVATE ${OPENGL_INCLUDE_DIR})
88
target_link_libraries(test_prog ${OPENGL_LIBRARIES})
99
message(STATUS " test: OPENGL_LIBRARIES: ${OPENGL_LIBRARIES}")
1010

1111
find_package(OpenAL REQUIRED)
12-
include_directories(${OPENAL_INCLUDE_DIR})
12+
target_include_directories(test_prog PRIVATE ${OPENAL_INCLUDE_DIR})
1313
target_link_libraries(test_prog ${OPENAL_LIBRARY})
1414
message(STATUS " test: OPENAL_LIBRARIES: ${OPENAL_LIBRARIES}")
1515

1616
find_package(SDL2 REQUIRED)
17-
include_directories(${SDL2_INCLUDE_DIRS})
17+
target_include_directories(test_prog PRIVATE ${SDL2_INCLUDE_DIRS})
1818
target_link_libraries(test_prog SDL2::SDL2)
1919
message(STATUS " test: SDL2_LIBRARIES: ${SDL2_LIBRARIES}")
2020
message(STATUS " test: SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}")
@@ -24,3 +24,7 @@ message(STATUS " test: OpenGL::GL IMPORTED_LIBNAME: ${TEST_OPENGL_GL_LIBNAME}")
2424

2525
get_target_property(TEST_OPENGL_GL_INCLUDES OpenGL::GL INTERFACE_INCLUDE_DIRECTORIES)
2626
message(STATUS " test: OpenGL::GL INTERFACE_INCLUDE_DIRECTORIES: ${TEST_OPENGL_GL_INCLUDES}")
27+
28+
find_package(SDL3 REQUIRED)
29+
add_executable(test_prog_sdl3 test_sdl3.c)
30+
target_link_libraries(test_prog_sdl3 SDL3::SDL3)

test/cmake/find_modules/test_sdl3.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Include emscripten/version.h to ensure that the in-tree
2+
// include directory has not been added to the include path.
3+
#include <emscripten/version.h>
4+
#include <SDL3/SDL.h>
5+
6+
int main() {
7+
int compiled = SDL_VERSION;
8+
SDL_Log("SDL version: %d.%d.%d\n",
9+
SDL_VERSIONNUM_MAJOR(compiled),
10+
SDL_VERSIONNUM_MINOR(compiled),
11+
SDL_VERSIONNUM_MICRO(compiled));
12+
return 0;
13+
}

test/test_other.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,8 @@ def test_cmake_find_modules(self):
10811081
output = self.run_js('test_prog.js')
10821082
self.assertContained('AL_VERSION: 1.1', output)
10831083
self.assertContained('SDL version: 2.', output)
1084+
output = self.run_js('test_prog_sdl3.js')
1085+
self.assertContained('SDL version: 3.', output)
10841086

10851087
def test_cmake_threads(self):
10861088
self.run_process([EMCMAKE, 'cmake', test_file('cmake/threads')])

0 commit comments

Comments
 (0)