ddnet/cmake/toolchains/Emscripten.toolchain
2022-03-25 12:42:18 +01:00

38 lines
2.4 KiB
Plaintext

set(WASM_CXX_ENGINE_FLAGS "")
set(WASM_ENGINE_FLAGS "")
set(WASM_ENGINE_FLAGS "-s LLD_REPORT_UNDEFINED -s USE_PTHREADS=1")
# needed for loading files in a c-like style
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s FILESYSTEM=1 -s FORCE_FILESYSTEM=1")
# load data directory to the filesystem
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} --preload-file data")
# remove some annoyance for now, TODO
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} --allow-multiple-definition -Wl,--shared-memory,--no-check-features")
# TODO
#set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -lwebsocket.js -s PROXY_POSIX_SOCKETS=1")
# use Web Assmebly & a WebGL2 comptatible GLES3 implementation
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s WASM=1")
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s USE_WEBGL2=1")
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s FULL_ES3=1")
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[\"$autoResumeAudioContext, $dynCall\"]")
# this flag is the most important one. It tells SDL2 to call emscripten functions when polling event
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s ASYNCIFY=1")
# TODO, has to be fixed in SDL2, can improve responsivness of the site
#set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s PROXY_TO_PTHREAD=1")
# SDL2 is compiled by the gen_libs.sh script for easy up to date code
#set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s USE_SDL=2")
#set(WASM_CXX_ENGINE_FLAGS "${WASM_CXX_ENGINE_FLAGS} -s USE_SDL=2")
# even if slower, memory growth has the advantage of using less resources, keep it on for now (instead of a static memory pool)
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
#set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s INITIAL_MEMORY=2000MB")
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s MAXIMUM_MEMORY=2000MB")
# not optimal but required so that threads are created on fly (instead of delayed when the next javascript calls come in)
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -s PTHREAD_POOL_SIZE=10")
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
# will drastically reduce code size
set(WASM_ENGINE_FLAGS "${WASM_ENGINE_FLAGS} -flto")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -D_REENTRANT -g -O3 ${WASM_CXX_ENGINE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -pthread -D_REENTRANT -g -O3 ${WASM_CXX_ENGINE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread ${WASM_ENGINE_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${WASM_ENGINE_FLAGS}")