diff options
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.md | 50 |
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 | |||
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 | First, you should have the Emscripten SDK installed from: | ||
9 | |||
10 | https://emscripten.org/docs/getting_started/downloads.html | ||
11 | |||
12 | Create the file CMakeLists.txt | ||
13 | ```cmake | ||
14 | cmake_minimum_required(VERSION 3.16) | ||
15 | project(hello) | ||
16 | |||
17 | # set the output directory for built objects. | ||
18 | # This makes sure that the dynamic library goes into the build directory automatically. | ||
19 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>") | ||
20 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>") | ||
21 | |||
22 | # This assumes the SDL source is available in vendored/SDL | ||
23 | add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL) | ||
24 | |||
25 | # on Web targets, we need CMake to generate a HTML webpage. | ||
26 | if(EMSCRIPTEN) | ||
27 | set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL "") | ||
28 | endif() | ||
29 | |||
30 | # Create your game executable target as usual | ||
31 | add_executable(hello WIN32 hello.c) | ||
32 | |||
33 | # Link to the actual SDL3 library. | ||
34 | target_link_libraries(hello PRIVATE SDL3::SDL3) | ||
35 | ``` | ||
36 | |||
37 | Build: | ||
38 | ```sh | ||
39 | emcmake cmake -S . -B build | ||
40 | cd build | ||
41 | emmake make | ||
42 | ``` | ||
43 | |||
44 | You can now run your app by pointing a webserver at your build directory and connecting a web browser to it, opening hello.html | ||
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-emscripten.md](README-emscripten.md) | ||