if (EMSCRIPTEN)
    SET(CMAKE_C_COMPILER emcc)
    SET(CMAKE_CPP_COMPILER em++)

    set(CMAKE_EXECUTABLE_SUFFIX ".js")
    set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") 
    # set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc") # bitcode

    set(COMPILE_FLAGS "-Wno-missing-prototypes")
    set_target_properties(${WASM_OUTPUT_NAME} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
     
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s WASM=1 --no-entry")
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -std=c++11 -O2")
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s ASSERTIONS=2")
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} --memory-init-file 0 -s TOTAL_MEMORY=134217728 -s ALLOW_MEMORY_GROWTH=1")
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} --bind")
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s ENVIRONMENT=web")

    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s LLD_REPORT_UNDEFINED")

    # set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s WASM_ASYNC_COMPILATION=0")  ## ASYNC
    # set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=0")  ## Error

    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s EXPORTED_FUNCTIONS=\"['_malloc','_free']\"")
    # set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s EXPORTED_FUNCTIONS=@${WASM_EXPORT_API_FILE}\"")
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s EXPORTED_RUNTIME_METHODS=\"['ccall','cwrap']\"")

    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s FULL_ES2=1 -s USE_WEBGL2=1")  ## GL
    set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -o ${WASM_OUTPUT_NAME}.js")      ## Output

    set_target_properties(${WASM_OUTPUT_NAME} PROPERTIES LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS}")
endif()