view Applications/StoneWebViewer/WebAssembly/CMakeLists.txt @ 2152:f68f9a8d0d63 dicom-sr

integration mainline->dicom-sr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 31 Aug 2024 08:40:01 +0200
parents 16c01cc201e7
children 2e050ec85379
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-2024 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)
include(${CMAKE_SOURCE_DIR}/../Version.cmake)

set(ORTHANC_STONE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../../../wasm-binaries/StoneWebViewer" 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 "${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 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
)


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

include(${CMAKE_SOURCE_DIR}/../../../OrthancStone/Resources/CMake/OrthancStoneWebAssemblyParameters.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_MODULE_JOBS OFF)
SET(ENABLE_PUGIXML ON) # Necessary for OsiriX annotations
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)

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()


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

DownloadPackage(
  "a24b8136b8f3bb93f166baf97d9328de"
  "https://orthanc.uclouvain.be/downloads/third-party-downloads/ubuntu-font-family-0.83.zip"
  "${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83")

EmbedResources(
  UBUNTU_FONT  ${CMAKE_BINARY_DIR}/ubuntu-font-family-0.83/Ubuntu-R.ttf
  )


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


# Create the wrapper to call C++ from JavaScript
# ---------------------------------------------------------------

set(LIBCLANG "libclang.so.1" CACHE PATH "Version of clang to generate the code model")
set(STONE_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/stone.js)

include(FindPython3 OPTIONAL RESULT_VARIABLE HAS_CMAKE_PYTHON3)
if (HAS_CMAKE_PYTHON3 STREQUAL "NOTFOUND" OR
    NOT Python3_FOUND)
  # CMake <= 3.12 or Python 3 not available: Fallback to Python 2.7
  set(CLANG_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
else()
  set(CLANG_PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
endif()

add_custom_command(
  COMMAND
  ${CLANG_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_definitions(
  -DSTONE_WEB_VIEWER_VERSION="${STONE_WEB_VIEWER_VERSION}"
  )

add_executable(StoneWebViewer
  ${ORTHANC_STONE_SOURCES}
  ${AUTOGENERATED_SOURCES}
  StoneWebViewer.cpp
  )

# Boost::Math begs for -std=c++14 since Boost 1.82.0
set_property(TARGET StoneWebViewer PROPERTY CXX_STANDARD 14)

if (COMMAND DefineSourceBasenameForTarget)
  DefineSourceBasenameForTarget(StoneWebViewer)
endif()

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

# Make sure to have the wrapper generated
add_dependencies(StoneWebViewer StoneWrapper)


# Declare installation files for the module
# ---------------------------------------------------------------

install(
  TARGETS StoneWebViewer
  RUNTIME DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}
  )


# 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.
# ---------------------------------------------------------------
include(${CMAKE_SOURCE_DIR}/JavaScriptLibraries.cmake)

install(
  FILES
  ${CMAKE_CURRENT_BINARY_DIR}/StoneWebViewer.wasm
  ${CMAKE_SOURCE_DIR}/../WebApplication/app-fixes.css
  ${CMAKE_SOURCE_DIR}/../WebApplication/app.css
  ${CMAKE_SOURCE_DIR}/../WebApplication/app.js
  ${CMAKE_SOURCE_DIR}/../WebApplication/configuration.json
  ${CMAKE_SOURCE_DIR}/../WebApplication/index.html
  ${CMAKE_SOURCE_DIR}/../WebApplication/open-sans.css
  ${CMAKE_SOURCE_DIR}/../WebApplication/pdf-viewer.js
  ${CMAKE_SOURCE_DIR}/../WebApplication/print.js
  ${STONE_WRAPPER}
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}
  )

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
  ${CMAKE_SOURCE_DIR}/../WebApplication/img/orthanc.png
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/img
  )