emscripten: Add support for automounting persistent storage before SDL_main.

Now apps can have persistent files available during SDL_main()/SDL_AppInit()
and don't have to mess with Emscripten-specific code to prepare the filesystem
for use.
This commit is contained in:
Ryan C. Gordon
2026-03-25 09:58:41 -04:00
parent be6f1efa26
commit dcc177faa4
5 changed files with 107 additions and 5 deletions

View File

@@ -393,6 +393,10 @@ set_option(SDL_CCACHE "Use Ccache to speed up build" OFF)
set_option(SDL_CLANG_TIDY "Run clang-tidy static analysis" OFF)
dep_option(SDL_GPU_OPENXR "Build SDL_GPU with OpenXR support" ON "SDL_GPU;NOT RISCOS" OFF)
if(EMSCRIPTEN)
option_string(SDL_EMSCRIPTEN_PERSISTENT_PATH "Path to mount Emscripten IDBFS at startup or '' to disable" "")
endif()
set(SDL_VENDOR_INFO "" CACHE STRING "Vendor name and/or version to add to SDL_REVISION")
if(DEFINED CACHE{SDL_SHARED} OR DEFINED CACHE{SDL_STATIC})
@@ -1668,6 +1672,11 @@ elseif(EMSCRIPTEN)
# project. Uncomment at will for verbose cross-compiling -I/../ path info.
sdl_compile_options(PRIVATE "-Wno-warn-absolute-paths")
if(NOT SDL_EMSCRIPTEN_PERSISTENT_PATH STREQUAL "")
set(SDL_EMSCRIPTEN_PERSISTENT_PATH_STRING "${SDL_EMSCRIPTEN_PERSISTENT_PATH}")
sdl_link_dependency(idbfs LIBS idbfs.js)
endif()
sdl_glob_sources(
"${SDL3_SOURCE_DIR}/src/main/emscripten/*.c"
"${SDL3_SOURCE_DIR}/src/main/emscripten/*.h"
@@ -4001,6 +4010,7 @@ if(SDL_SHARED)
)
endif()
endif()
target_link_libraries(SDL3-shared PRIVATE ${SDL_CMAKE_DEPENDS})
target_include_directories(SDL3-shared
PRIVATE