Skip to content

Commit

Permalink
cmake: preload resources into web examples
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pbalcer committed Jan 20, 2019
1 parent 1bfa1b8 commit 3065cbb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3065cbb

Please sign in to comment.