Skip to content

Commit d373294

Browse files
committed
close #19 : add cmake option for single-file wasm build
If enabled, we build ggwave using "-s SINGLE_FILE=1" which causes the WASM to be embedded inside the .js file. Otherwise, 2 separate files are produced: - libggwave.js - libggwave.wasm
1 parent 580090c commit d373294

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ endif()
2121
if (EMSCRIPTEN)
2222
set(GGWAVE_SUPPORT_SDL2_DEFAULT ON)
2323
set(BUILD_SHARED_LIBS_DEFAULT OFF)
24+
25+
option(GGWAVE_WASM_SINGLE_FILE "ggwave: embed WASM inside the generated ggwave.js" ON)
2426
else()
2527
set(GGWAVE_SUPPORT_SDL2_DEFAULT ON)
2628
set(BUILD_SHARED_LIBS_DEFAULT ON)

bindings/javascript/CMakeLists.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ target_link_libraries(${TARGET} PRIVATE
88
ggwave
99
)
1010

11+
unset(EXTRA_FLAGS)
12+
if (GGWAVE_WASM_SINGLE_FILE)
13+
set(EXTRA_FLAGS "-s SINGLE_FILE=1")
14+
message(STATUS "Embedding WASM inside ggwave.js")
15+
16+
add_custom_command(
17+
TARGET libggwave POST_BUILD
18+
COMMAND ${CMAKE_COMMAND} -E copy
19+
${CMAKE_BINARY_DIR}/bin/libggwave.js
20+
${CMAKE_CURRENT_SOURCE_DIR}/ggwave.js
21+
)
22+
endif()
23+
1124
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
1225
--bind \
1326
-s MODULARIZE=1 \
14-
-s SINGLE_FILE=1 \
1527
-s ALLOW_MEMORY_GROWTH=1 \
1628
-s EXPORT_NAME=\"'ggwave_factory'\" \
29+
${EXTRA_FLAGS} \
1730
")
18-
19-
add_custom_command(
20-
TARGET libggwave POST_BUILD
21-
COMMAND ${CMAKE_COMMAND} -E copy
22-
${CMAKE_BINARY_DIR}/bin/libggwave.js
23-
${CMAKE_CURRENT_SOURCE_DIR}/ggwave.js
24-
)

bindings/javascript/ggwave.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)