view Applications/Samples/WebAssembly/CMakeLists.txt @ 2078:fdb012c86a75 deep-learning

integration mainline->deep-learning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 21:21:11 +0200
parents 5956d7357098 07964689cb0b
children a6d5373e471c
line wrap: on
line source

# Stone of Orthanc
# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
# Department, University Hospital of Liege, Belgium
# Copyright (C) 2017-2023 Osimis S.A., Belgium
# Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


cmake_minimum_required(VERSION 2.8.3)
cmake_policy(SET CMP0058 NEW)

project(OrthancStone)

set(SAMPLES_VERSION "mainline")

if (SAMPLES_VERSION STREQUAL "mainline")
  set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "mainline")
  set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg")
else()
  set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "1.11.2")
  set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web")
endif()

set(ORTHANC_STONE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../../../wasm-binaries/" CACHE PATH "Where to put the WebAssembly binaries")


# Configuration of the Emscripten compiler for WebAssembly target
# ---------------------------------------------------------------
set(USE_WASM ON CACHE BOOL "")

set(WASM_FLAGS "-s WASM=1 -s FETCH=1 -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1")
endif()

set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ENVIRONMENT=web")
set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")
set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1")
set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=268435456")  # 256MB + resize
set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1")
add_definitions(
  -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
  -DORTHANC_HAS_WASM_SIMD=0
  -DORTHANC_WEBGL2_HEAP_COMPAT=0
)


# Stone of Orthanc configuration
# ---------------------------------------------------------------
set(ALLOW_DOWNLOADS ON)

include(${CMAKE_SOURCE_DIR}/../../../OrthancStone/Resources/CMake/OrthancStoneWebAssemblyParameters.cmake)

SET(ENABLE_DCMTK OFF)  # Not necessary
SET(ENABLE_GOOGLE_TEST OFF)
SET(ENABLE_LOCALE ON)  # Necessary for text rendering
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(${CMAKE_SOURCE_DIR}/../../../OrthancStone/Resources/CMake/OrthancStoneWebAssemblyConfiguration.cmake)


# We embed a font to be used for on-screen overlays
# ---------------------------------------------------------------

DownloadPackage(
  "a24b8136b8f3bb93f166baf97d9328de"
  "http://orthanc.osimis.io/ThirdPartyDownloads/ubuntu-font-family-0.83.zip"
  "${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83")

EmbedResources(
  COLORMAP_HOT ${CMAKE_SOURCE_DIR}/../../Resources/Colormaps/hot.lut
  UBUNTU_FONT  ${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83/Ubuntu-R.ttf
  )

add_library(OrthancStone STATIC
  ${ORTHANC_STONE_SOURCES}
  ${AUTOGENERATED_SOURCES}
  )

################################################################################

# Define the WASM module
# ---------------------------------------------------------------

project(RtViewerWasm)

add_executable(RtViewerWasm
  RtViewer/RtViewerWasm.cpp
  ../Common/RtViewerApp.cpp
  ../Common/RtViewerApp.h
  ../Common/RtViewerView.cpp
  ../Common/RtViewerView.h
  )

set_target_properties(RtViewerWasm
  PROPERTIES
  COMPILE_FLAGS "${WASM_FLAGS}"
  LINK_FLAGS "${WASM_LINKER_FLAGS}"
  )

target_link_libraries(RtViewerWasm OrthancStone)

# Declare installation files for the module
# ---------------------------------------------------------------
install(
  TARGETS RtViewerWasm
  RUNTIME DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/RtViewer/
  )

# Declare installation files for the companion files (web scaffolding)
# please note that ${CMAKE_CURRENT_BINARY_DIR}/RtViewerWasm.js
# (the generated JS loader for the WASM module) is handled by the `install1`
# section above: it is considered to be the binary output of 
# the linker.
# ---------------------------------------------------------------
install(
  FILES
  ${CMAKE_SOURCE_DIR}/RtViewer/RtViewerWasmApp.js
  ${CMAKE_SOURCE_DIR}/RtViewer/index.html
  ${CMAKE_CURRENT_BINARY_DIR}/RtViewerWasm.wasm
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/RtViewer/
  )

################################################################################

# Define the WASM module
# ---------------------------------------------------------------

project(SingleFrameViewerWasm)

add_executable(SingleFrameViewerWasm
  SingleFrameViewer/SingleFrameViewer.cpp
  )

set_target_properties(SingleFrameViewerWasm
  PROPERTIES
  COMPILE_FLAGS "${WASM_FLAGS}"
  LINK_FLAGS "${WASM_LINKER_FLAGS}"
  )

target_link_libraries(SingleFrameViewerWasm OrthancStone)

# Declare installation files for the module
# ---------------------------------------------------------------
install(
  TARGETS SingleFrameViewerWasm
  RUNTIME DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/SingleFrameViewer/
  )

# Declare installation files for the companion files (web scaffolding)
# please note that ${CMAKE_CURRENT_BINARY_DIR}/RtViewerWasm.js
# (the generated JS loader for the WASM module) is handled by the `install1`
# section above: it is considered to be the binary output of 
# the linker.
# ---------------------------------------------------------------
install(
  FILES
  ${CMAKE_SOURCE_DIR}/SingleFrameViewer/SingleFrameViewerApp.js
  ${CMAKE_SOURCE_DIR}/SingleFrameViewer/index.html
  ${CMAKE_CURRENT_BINARY_DIR}/SingleFrameViewerWasm.wasm
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/SingleFrameViewer/
  )