view Platforms/WebAssembly/CMakeLists.txt @ 115:f598ffb81cda wasm

fix sandboxed build
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 Sep 2017 17:02:58 +0200
parents 3541fc81331a
children c993693e9e63
line wrap: on
line source

# Usage:
# cmake -DCMAKE_TOOLCHAIN_FILE=~/Downloads/emsdk/emscripten/incoming/cmake/Modules/Platform/Emscripten.cmake ~/Subversion/orthanc-stone/Platforms/WebAssembly


cmake_minimum_required(VERSION 2.8.3)


#####################################################################
## Configuration of the Emscripten compiler for WebAssembly target
#####################################################################

set(WASM_FLAGS "-s WASM=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WASM_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WASM_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --js-library ${CMAKE_SOURCE_DIR}/library.js")

# Handling of memory
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1")  # Resize
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s TOTAL_MEMORY=536870912")  # 512MB
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=536870912")  # 512MB + resize
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=1073741824")  # 1GB + resize

# To debug exceptions
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=2")


#####################################################################
## Build a static library containing the Orthanc Stone framework
#####################################################################

include(../../Resources/CMake/OrthancStoneParameters.cmake)

SET(ORTHANC_SANDBOXED ON)
SET(ENABLE_SDL OFF)

include(../../Resources/CMake/OrthancStoneConfiguration.cmake)

add_library(OrthancStone STATIC ${ORTHANC_STONE_SOURCES})






# Regenerate a dummy "library.c" file each time the "library.js" file
# is modified, so as to force a new execution of the linking
add_custom_command(
    OUTPUT "${AUTOGENERATED_DIR}/library.c"
    COMMAND ${CMAKE_COMMAND} -E touch "${AUTOGENERATED_DIR}/library.c" ""
    DEPENDS "${CMAKE_SOURCE_DIR}/library.js")