From 1bfa1b8696d45eba7cd4d3ab35d0486943c2b1bc Mon Sep 17 00:00:00 2001 From: Piotr Balcer Date: Sun, 20 Jan 2019 14:49:22 +0100 Subject: [PATCH 1/2] cmake: use ALLOW_MEMORY_GROWTH=1 for web examples The default memory limit for emscripten applications is 16 mergabytes, which might be to little for some examples, especially given that the resources are also included in that limit. Normally, using this option disables some asm.js optimizations, but there's no such cost for WebAssembly. --- examples/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1d4fdd797..b9cd3ff59 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -56,7 +56,10 @@ if(${PLATFORM} MATCHES "Android") elseif(${PLATFORM} MATCHES "Web") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1") + # Since WASM is used, ALLOW_MEMORY_GROWTH has no extra overheads + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 --no-heap-copy") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --shell-file ${CMAKE_SOURCE_DIR}/templates/web_shell/shell.html") + set(OUTPUT_EXT ".html") endif() From 3065cbbce9ac3bab73552d4ae39df43ad3aeb414 Mon Sep 17 00:00:00 2001 From: Piotr Balcer Date: Sun, 20 Jan 2019 14:58:10 +0100 Subject: [PATCH 2/2] cmake: preload resources into web examples No examples built for the Web platform functioned properly due to lack of resources in the virtual file system provided by emscripten. This patch addresses this problem by adding '--preload-file local_path/resources@resources' emcc option to link flags whenever necessary. --- examples/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b9cd3ff59..4b04d45a9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -80,6 +80,15 @@ foreach(example_source ${example_sources}) add_executable(${example_name} ${example_source}) target_link_libraries(${example_name} raylib) + + string(REGEX MATCH ".*/.*/" resources_dir ${example_source}) + string(APPEND resources_dir "resources") + + if(${PLATFORM} MATCHES "Web" AND EXISTS ${resources_dir}) + # The local resources path needs to be mapped to /resources virtual path + string(APPEND resources_dir "@resources") + set_target_properties(${example_name} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}") + endif() endforeach() if (${PLATFORM} MATCHES "Desktop")