view Platforms/Wasm/CMakeLists.txt @ 288:8c8da145fefa am-2

renamings and doc
author am@osimis.io
date Thu, 30 Aug 2018 16:52:40 +0200
parents dc1beee33134
children
line wrap: on
line source

# Usage (Linux):
# source ~/Downloads/emsdk/emsdk_env.sh && cmake -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake ..

cmake_minimum_required(VERSION 2.8.3)


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

set(WASM_FLAGS "-s WASM=1")
set(WASM_MODULE_NAME "StoneFrameworkModule" CACHE STRING "Name of the WebAssembly module")
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 ${STONE_SOURCES_DIR}/Applications/Samples/samples-library.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/WasmWebService.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/default-library.js  -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")

# 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 EXPORT_NAME='\"${WASM_MODULE_NAME}\"' -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=536870912 -s TOTAL_STACK=128000000")  # 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_QT OFF)
SET(ENABLE_SDL OFF)
add_definitions(-DORTHANC_ENABLE_WASM=1)

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

add_library(OrthancStone STATIC ${ORTHANC_STONE_SOURCES})



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

add_custom_command(
    OUTPUT "${AUTOGENERATED_DIR}/default-library.c"
    COMMAND ${CMAKE_COMMAND} -E touch "${AUTOGENERATED_DIR}/default-library.c" ""
    DEPENDS "${ORTHANC_STONE_ROOT}/Platforms/Wasm/default-library.js")


#####################################################################
## Build all the sample applications
#####################################################################

include_directories(${ORTHANC_STONE_ROOT})


macro(BuildSample Target Header Sample)
  add_executable(${Target}
    ${STONE_WASM_SOURCES}

    ${AUTOGENERATED_DIR}/WasmWebService.c
    ${AUTOGENERATED_DIR}/default-library.c

    ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleMainWasm.cpp
#    ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleApplicationContext.cpp
    ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleInteractor.h
    ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleApplicationBase.h
    ${ORTHANC_STONE_ROOT}/Applications/Samples/${Header}
    )
  set_target_properties(${Target} PROPERTIES COMPILE_DEFINITIONS ORTHANC_STONE_SAMPLE=${Sample})
  target_link_libraries(${Target} OrthancStone)
endmacro()

#BuildSample(OrthancStoneEmpty EmptyApplication.h 1)
#BuildSample(OrthancStoneTestPattern TestPatternApplication.h 2)
#BuildSample(OrthancStoneSingleFrame SingleFrameApplication.h 3)
#BuildSample(OrthancStoneSingleVolume SingleVolumeApplication.h 4)
#BuildSample(OrthancStoneBasicPetCtFusion 5)
#BuildSample(OrthancStoneSynchronizedSeries 6)
#BuildSample(OrthancStoneLayoutPetCtFusion 7)
BuildSample(OrthancStoneSimpleViewer SimpleViewerApplication.h 8)