summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/docs/INTRO-emscripten.md
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
committer3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
commit6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch)
tree34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/docs/INTRO-emscripten.md
parent8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff)
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/docs/INTRO-emscripten.md')
-rw-r--r--src/contrib/SDL-3.2.20/docs/INTRO-emscripten.md50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/docs/INTRO-emscripten.md b/src/contrib/SDL-3.2.20/docs/INTRO-emscripten.md
new file mode 100644
index 0000000..a0541c8
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/docs/INTRO-emscripten.md
@@ -0,0 +1,50 @@
1
2# Introduction to SDL with Emscripten
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
8First, you should have the Emscripten SDK installed from:
9
10https://emscripten.org/docs/getting_started/downloads.html
11
12Create the file CMakeLists.txt
13```cmake
14cmake_minimum_required(VERSION 3.16)
15project(hello)
16
17# set the output directory for built objects.
18# This makes sure that the dynamic library goes into the build directory automatically.
19set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
20set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
21
22# This assumes the SDL source is available in vendored/SDL
23add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL)
24
25# on Web targets, we need CMake to generate a HTML webpage.
26if(EMSCRIPTEN)
27 set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL "")
28endif()
29
30# Create your game executable target as usual
31add_executable(hello WIN32 hello.c)
32
33# Link to the actual SDL3 library.
34target_link_libraries(hello PRIVATE SDL3::SDL3)
35```
36
37Build:
38```sh
39emcmake cmake -S . -B build
40cd build
41emmake make
42```
43
44You can now run your app by pointing a webserver at your build directory and connecting a web browser to it, opening hello.html
45
46A more complete example is available at:
47
48https://github.com/Ravbug/sdl3-sample
49
50Additional information and troubleshooting is available in [README-emscripten.md](README-emscripten.md)