Improved cmake to use wasm compilation flags across project

This commit is contained in:
Abhishek Aggarwal 2021-02-12 11:35:47 +01:00
parent ff95e37f89
commit 28dcf55b41
4 changed files with 11 additions and 4 deletions

View File

@ -1,4 +1,10 @@
add_subdirectory(marian-dev)
if(COMPILE_WASM)
# This is a bad way of adding compilation flags. Will be improved soon.
add_compile_options(${WASM_COMPILE_FLAGS})
endif(COMPILE_WASM)
add_subdirectory(ssplit-cpp)
# Add include directories for 3rd party targets to be able to use it anywhere in the

View File

@ -33,9 +33,9 @@ if(NOT COMPILE_WASM)
endif()
if(COMPILE_WASM)
add_compile_options(-pthread -O3 -g2 -fPIC -mssse3 -msimd128)
add_compile_options("SHELL:-s WASM=1" "SHELL:-s ASSERTIONS=1" "SHELL:-s DISABLE_EXCEPTION_CATCHING=0" "SHELL:-s LLD_REPORT_UNDEFINED" "SHELL:-s FORCE_FILESYSTEM=1" "SHELL:-s ALLOW_MEMORY_GROWTH=1")
add_compile_options(-Wno-error=pthreads-mem-growth)
list(APPEND WASM_COMPILE_FLAGS -pthread -O3 -g2 -fPIC -mssse3 -msimd128)
list(APPEND WASM_COMPILE_FLAGS "SHELL:-s WASM=1" "SHELL:-s ASSERTIONS=1" "SHELL:-s DISABLE_EXCEPTION_CATCHING=0" "SHELL:-s LLD_REPORT_UNDEFINED" "SHELL:-s FORCE_FILESYSTEM=1" "SHELL:-s ALLOW_MEMORY_GROWTH=1")
list(APPEND WASM_COMPILE_FLAGS -Wno-error=pthreads-mem-growth)
endif(COMPILE_WASM)
add_subdirectory(3rd_party)

View File

@ -21,6 +21,7 @@ if(COMPILE_WASM)
target_compile_definitions(bergamot-translator PUBLIC USE_SSE2 WASM)
# Enable code that is required for generating JS bindings
target_compile_definitions(bergamot-translator PRIVATE WASM_BINDINGS)
target_compile_options(bergamot-translator PRIVATE ${WASM_COMPILE_FLAGS})
endif(COMPILE_WASM)
if (COMPILE_THREAD_VARIANT)

View File

@ -12,6 +12,7 @@ target_include_directories(bergamot-translator-worker
)
# This compile definition is required for generating binding code properly
target_compile_definitions(bergamot-translator-worker PRIVATE WASM_BINDINGS)
target_compile_options(bergamot-translator-worker PRIVATE ${WASM_COMPILE_FLAGS})
set(LINKER_FLAGS "--bind -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0 -s FORCE_FILESYSTEM=1 -s ALLOW_MEMORY_GROWTH=1")
if (NOT PACKAGE_DIR STREQUAL "")
@ -22,6 +23,5 @@ set_target_properties(bergamot-translator-worker PROPERTIES
SUFFIX ".js"
LINK_FLAGS ${LINKER_FLAGS}
)
#target_link_options(bergamot-translator-worker --preload-file ${PACKAGE_DIR}@/)
target_link_libraries(bergamot-translator-worker bergamot-translator)