### W4 Common EMS FLAGS

set(COMMON_CXX    "--closure 0")

set(COMMON_LNK
    "-s ENVIRONMENT=web"
    "-s WASM"
    "-s MODULARIZE"
    "-s ERROR_ON_MISSING_LIBRARIES"
    "-s ERROR_ON_UNDEFINED_SYMBOLS"
    "-s NO_FILESYSTEM"
    "-s EXPORTED_RUNTIME_METHODS=['cwrap']"
    "-s NO_USE_WEBGL2"
    "-s NO_FULL_ES3"
    "-s ALLOW_MEMORY_GROWTH"
)

set(DEBUG_CXX  "-O0" "-g2")
set(DEBUG_LNK
    "--closure 0"
    "-s ASSERTIONS"
    "-s DEMANGLE_SUPPORT"
    "-s RUNTIME_LOGGING"
    "-s INITIAL_MEMORY=128MB"
    "-s MAXIMUM_MEMORY=1024MB"
)

set(RELEASE_CXX  "-Oz" "-g0" "-fno-exceptions"  "-flto" "-DNDEBUG")
set(RELEASE_LNK
    "--closure 0"
    "-flto"
    "-s NO_ASSERTIONS"
    "-s NO_DEMANGLE_SUPPORT"
    "-s DISABLE_EXCEPTION_CATCHING"
    "-s DISABLE_EXCEPTION_THROWING"
    "-s INITIAL_MEMORY=128MB"
    "-s MAXIMUM_MEMORY=1024MB"
)

set(SHIPPING_CXX "-Oz" "-g0" "-fno-exceptions" "-flto"  "-DNDEBUG" "-DW4_IS_SHIPPING")
set(SHIPPING_LNK
    "--closure 0"
    "-flto"
    "-s SINGLE_FILE"
    "-s NO_ASSERTIONS"
    "-s NO_DEMANGLE_SUPPORT"
    "-s DISABLE_EXCEPTION_CATCHING"
    "-s DISABLE_EXCEPTION_THROWING"
    "-s INITIAL_MEMORY=256MB"
    "-s MAXIMUM_MEMORY=4096MB"
)

list(JOIN COMMON_CXX    " " COMMON_CXX_STR)
list(JOIN DEBUG_CXX     " " DEBUG_CXX_STR)
list(JOIN RELEASE_CXX   " " RELEASE_CXX_STR)
list(JOIN SHIPPING_CXX  " " SHIPPING_CXX_STR)
list(JOIN COMMON_LNK    " " COMMON_LNK_STR)
list(JOIN DEBUG_LNK     " " DEBUG_LNK_STR)
list(JOIN RELEASE_LNK   " " RELEASE_LNK_STR)
list(JOIN SHIPPING_LNK  " " SHIPPING_LNK_STR)

set(CMAKE_C_FLAGS                    "${COMMON_CXX_STR}"   CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_C_FLAGS_DEBUG              "${DEBUG_CXX_STR}"    CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_C_FLAGS_RELEASE            "${RELEASE_CXX_STR}"  CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_C_FLAGS_SHIPPING           "${SHIPPING_CXX_STR}" CACHE STRING "W4 OVERRIDEN" FORCE)

set(CMAKE_CXX_FLAGS                  "${COMMON_CXX_STR}"   CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG            "${DEBUG_CXX_STR}"    CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE          "${RELEASE_CXX_STR}"  CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_CXX_FLAGS_SHIPPING         "${SHIPPING_CXX_STR}" CACHE STRING "W4 OVERRIDEN" FORCE)

set(CMAKE_EXE_LINKER_FLAGS_DEBUG     "${COMMON_LNK_STR} ${DEBUG_LNK_STR}"    CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE   "${COMMON_LNK_STR} ${RELEASE_LNK_STR}"  CACHE STRING "W4 OVERRIDEN" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_SHIPPING  "${COMMON_LNK_STR} ${SHIPPING_LNK_STR}" CACHE STRING "W4 OVERRIDEN" FORCE)

