Enable building the encoder with Enscripten to WebAssebly as a Nodejs cli tool.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f63db7..0ff16e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,7 +33,12 @@
set(GCC_COMPILE_FLAGS "${GCC_COMPILE_FLAGS} -m32")
endif()
- if (STATIC)
+ if (EMSCRIPTEN)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
+
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS}")
+ elseif (STATIC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -static-libgcc -static-libstdc++ -static")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -Wl,-rpath .")
@@ -85,15 +90,16 @@
target_link_libraries(basisu m pthread)
endif()
-install(TARGETS basisu DESTINATION bin)
-
-if (UNIX)
- if (CMAKE_BUILD_TYPE STREQUAL Release)
- if (APPLE)
- add_custom_command(TARGET basisu POST_BUILD COMMAND strip -X -x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/basisu)
- else()
- add_custom_command(TARGET basisu POST_BUILD COMMAND strip -g -X -x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/basisu)
- endif()
- endif()
-endif()
-
+if (NOT EMSCRIPTEN)
+ install(TARGETS basisu DESTINATION bin)
+
+ if (UNIX)
+ if (CMAKE_BUILD_TYPE STREQUAL Release)
+ if (APPLE)
+ add_custom_command(TARGET basisu POST_BUILD COMMAND strip -X -x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/basisu)
+ else()
+ add_custom_command(TARGET basisu POST_BUILD COMMAND strip -g -X -x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/basisu)
+ endif()
+ endif()
+ endif()
+endif()
\ No newline at end of file
diff --git a/build_emscripten.sh b/build_emscripten.sh
new file mode 100755
index 0000000..274f539
--- /dev/null
+++ b/build_emscripten.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+if ! emcc --version
+then
+ echo "Emscripten not found on PATH. Please follow instructions on https://emscripten.org/docs/getting_started/downloads.html"
+ exit
+fi
+
+emcmake cmake .
+emcmake make
\ No newline at end of file