Enable building the encoder with Enscripten to WebAssebly as a Nodejs cli tool.

This commit is contained in:
Maciej Kacper Jagiełło
2020-05-16 17:28:17 +02:00
parent 374a04d54d
commit 4433e80fe4
2 changed files with 28 additions and 13 deletions

View File

@@ -33,7 +33,12 @@ if (NOT MSVC)
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 @@ if (NOT MSVC)
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()

9
build_emscripten.sh Executable file
View File

@@ -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