Escripten & SDL3

My problem is that I’d like to develop SDL3-based games with Emscripten: There’s an SDL_DetectSandbox function that I really want to have access to so I can warn browser players when and why controllers are not going to work.

I see mentions of Emscripten in the SDL/CMakeLists.txt file, but I don’t know enough CMake (or Emscripten for that matter) in order to build a proper *.a file. I’m hoping that there is some command that I’m supposed to pass to CMake when building the SDL3 libs.

Could someone give me a heads up on how to compile an Emscripten archive file for SDL3?

I think I’ve found it, thanks to 8Observer8’s recent post → SDL3 WebAssebmly doesn't work in full screen mode

I got to here: →

So it really does look like a one-line command.

I’m still building (The emsdk emcmake command takes quite a bit more time than a regular cmake), I’ll comment back with any additional info.

I need to write the whole process down for the next time I start fresh:
It is really this simple.
From inside a build folder that you create next to SDL source folder call this:

$ emcmake cmake -S ../SDL -B .
$ emmake make 
$ sudo make install

Note: When the install command runs, the libs are installed into your active ‘emsdk’ folder, in my case that’s the folder that I cloned from git → GitHub - emscripten-core/emsdk: Emscripten SDK
In my research I did see that it’s highly recommended that you set a destination prefix.

The final steps are to copy libSDL3.a to your project folder and add it to your compile command as an object file.

cp libSDL3.a ~/pathToMyProject/
cd ~/pathToMyProject
em++ main.cpp libSDL3.a -o index.html

Now you include SDL3 in your main.cpp file, and it’s good to go.

Unfortunately I just found out that my initial goal was not to be… SDL_DetectSandbox is an internal function, no public access.
So, that’s a small bummer, but at least I have SDL3 in Emscripten!

1 Like

Man, your tutorial is gold bar, because it’s more valuable than money.

Unfortunately I hit a hard wall when I next tried to compile the support libs (SDL_image, SDL_ttf, etc).
I think the issues mostly stem from trying to do static linking of SDL3 and my lack of experience in the cmake ecosystem.
I’ll add any tips or hints that I come across and would really appreciate it if anyone could help with info, but I’m currently thinking the support libs will have to wait until there’s a SDL3 stable release.

Just a suggestion:
–if you make minimal examples they will be enough
For example:
Your comment was a minimal example, like a minimal tutorial.

Is very hard to read a documentation without examples of uses.
And when I start learn something I just wrote minimal example to follow and answer eventual doubts.