diff Applications/StoneWebViewer/WebAssembly/CMakeLists.txt @ 1538:d1806b4e4839

moving OrthancStone/Samples/ as Applications/Samples/
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2020 13:24:38 +0200
parents StoneWebViewer/WebAssembly/CMakeLists.txt@433cf964838d
children 8ddf77198ed7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/StoneWebViewer/WebAssembly/CMakeLists.txt	Tue Aug 11 13:24:38 2020 +0200
@@ -0,0 +1,129 @@
+cmake_minimum_required(VERSION 2.8.3)
+
+project(OrthancStone)
+
+# Configuration of the Emscripten compiler for WebAssembly target
+# ---------------------------------------------------------------
+set(USE_WASM ON CACHE BOOL "")
+
+set(EMSCRIPTEN_SET_LLVM_WASM_BACKEND ON CACHE BOOL "")
+
+set(WASM_FLAGS "-s WASM=1 -s FETCH=1")
+if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1")
+endif()
+
+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} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=268435456")  # 256MB + resize
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1")
+add_definitions(
+  -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
+)
+
+# Stone of Orthanc configuration
+# ---------------------------------------------------------------
+set(ALLOW_DOWNLOADS ON)
+
+include(${CMAKE_SOURCE_DIR}/../../OrthancStone/Resources/CMake/OrthancStoneParameters.cmake)
+
+SET(ENABLE_DCMTK ON)
+SET(ENABLE_DCMTK_NETWORKING OFF)
+SET(ENABLE_DCMTK_TRANSCODING OFF)
+SET(ENABLE_GOOGLE_TEST OFF)
+SET(ENABLE_LOCALE ON)  # Necessary for text rendering
+SET(ENABLE_WASM ON)
+SET(ORTHANC_SANDBOXED ON)
+
+# this will set up the build system for Stone of Orthanc and will
+# populate the ORTHANC_STONE_SOURCES CMake variable
+include(${ORTHANC_STONE_ROOT}/Resources/CMake/OrthancStoneConfiguration.cmake)
+
+if (CMAKE_BUILD_TYPE MATCHES Debug)
+  # specific flags go here
+elseif (CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
+  # specific flags go here
+elseif (CMAKE_BUILD_TYPE MATCHES Release)
+  # specific flags go here
+else()
+  message(FATAL_ERROR "CMAKE_BUILD_TYPE must match either Debug, RelWithDebInfo or Release" )
+endif()
+
+################################################################################
+
+project(StoneWebViewer)
+
+
+# Create the wrapper to call C++ from JavaScript
+# ---------------------------------------------------------------
+
+set(LIBCLANG "libclang-4.0.so.1" CACHE PATH "Version of clang to generate the code model")
+set(STONE_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/stone.js)
+
+add_custom_command(
+  COMMAND
+  ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/ParseWebAssemblyExports.py --libclang=${LIBCLANG} ${CMAKE_SOURCE_DIR}/StoneWebViewer.cpp > ${STONE_WRAPPER}
+  DEPENDS
+  ${CMAKE_SOURCE_DIR}/StoneWebViewer.cpp
+  ${CMAKE_SOURCE_DIR}/ParseWebAssemblyExports.py
+  OUTPUT
+  ${STONE_WRAPPER}
+  )
+
+add_custom_target(StoneWrapper
+  DEPENDS
+  ${STONE_WRAPPER}
+  )  
+
+
+# Define the WASM module
+# ---------------------------------------------------------------
+
+add_executable(StoneWebViewer
+  ${ORTHANC_STONE_SOURCES}
+  ${AUTOGENERATED_SOURCES}
+  StoneWebViewer.cpp
+  )
+
+# Make sure to have the wrapper generated
+add_dependencies(StoneWebViewer StoneWrapper)
+
+
+# Declare installation files for the module
+# ---------------------------------------------------------------
+
+install(
+  TARGETS StoneWebViewer
+  RUNTIME DESTINATION .
+  )
+
+
+# Declare installation files for the companion files (web scaffolding)
+# please note that ${CMAKE_CURRENT_BINARY_DIR}/StoneWebViewer.js
+# (the generated JS loader for the WASM module) is handled by the `install`
+# section above: it is considered to be the binary output of 
+# the linker.
+# ---------------------------------------------------------------
+install(
+  FILES
+  ${CMAKE_CURRENT_BINARY_DIR}/StoneWebViewer.wasm
+  ${CMAKE_SOURCE_DIR}/../WebApplication/app.css
+  ${CMAKE_SOURCE_DIR}/../WebApplication/app.js
+  ${CMAKE_SOURCE_DIR}/../WebApplication/index.html
+  ${STONE_WRAPPER}
+  DESTINATION .
+  )
+
+install(
+  FILES
+  ${CMAKE_SOURCE_DIR}/../WebApplication/img/grid1x1.png
+  ${CMAKE_SOURCE_DIR}/../WebApplication/img/grid1x2.png
+  ${CMAKE_SOURCE_DIR}/../WebApplication/img/grid2x1.png
+  ${CMAKE_SOURCE_DIR}/../WebApplication/img/grid2x2.png
+  ${CMAKE_SOURCE_DIR}/../WebApplication/img/loading.gif
+  DESTINATION img
+  )