Implement resource packaging for web builds
All checks were successful
Run tests / Run tests (push) Successful in 8m28s

This commit is contained in:
Nikita Lisitsa 2026-07-04 17:33:28 +03:00
parent ce019229bb
commit b989eba66d
2 changed files with 14 additions and 0 deletions

View file

@ -1,4 +1,5 @@
#include <psemek/app/application.hpp>
#include <psemek/app/resource.hpp>
#include <psemek/gfx/init.hpp>
#include <psemek/sdl2/init.hpp>
#include <psemek/sdl2/window.hpp>
@ -50,6 +51,12 @@ int main(int argc, char ** argv) try
log::add_sink(log::default_sink(std::move(synchronized_stdout_stderr[1]), log::level::warning, log::level::error));
log::register_thread("main");
#ifdef __EMSCRIPTEN__
// In web builds, resources are in the root of
// the Emscripten virtual filesystem
app::set_resource_root("/");
#endif
auto const factory = app::make_application_factory();
auto const options = factory->options();

View file

@ -110,6 +110,7 @@ function(psemek_add_executable_impl target is_application)
list(APPEND _TARGET_RUNTIME ${_TARGET_NOEXT}.js)
list(APPEND _TARGET_RUNTIME ${_TARGET_NOEXT}.wasm)
list(APPEND _TARGET_RUNTIME ${_TARGET_NOEXT}.data)
endif()
set(_COPY_FILES ${_TARGET_FILE} ${_TARGET_RUNTIME} ${PSEMEK_PACKAGE_COPY_FILES})
@ -228,6 +229,12 @@ function(psemek_package_files target)
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${PSEMEK_COPY_FILES} ${ARGN}
)
elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
foreach(_FILE IN LISTS ARGN)
target_link_options(${target} PRIVATE
"--preload-file=${CMAKE_CURRENT_LIST_DIR}/${_FILE}@/${_FILE}"
)
endforeach()
else()
psemek_package_output_path(${target} _OUTPUT_PATH)