summaryrefslogtreecommitdiff
path: root/SDL-3.2.8/docs/INTRO-emscripten.md
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2026-03-06 13:26:57 -0800
committer3gg <3gg@shellblade.net>2026-03-06 13:26:57 -0800
commitf5c89b3bd5d74849757fd5b4d1a300068522a3ca (patch)
treed6f6e4c81745b393d7594b334710f30c0b2df3bd /SDL-3.2.8/docs/INTRO-emscripten.md
Initial commitHEADmain
Diffstat (limited to 'SDL-3.2.8/docs/INTRO-emscripten.md')
-rw-r--r--SDL-3.2.8/docs/INTRO-emscripten.md50
1 files changed, 50 insertions, 0 deletions
diff --git a/SDL-3.2.8/docs/INTRO-emscripten.md b/SDL-3.2.8/docs/INTRO-emscripten.md
new file mode 100644
index 0000000..a0541c8
--- /dev/null
+++ b/SDL-3.2.8/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)