view Applications/Platforms/WebAssembly/SharedLibrary/CMakeLists.txt @ 1676:5e76d5e8167a

limit the amount of frames to be prefetched
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 23 Nov 2020 18:49:42 +0100
parents 4cdc297be5a6
children 9ac2a65d4172
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-2020 Osimis S.A., 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(OrthancStoneModule)


# Warning message related to WebAssembly modules: We know that 1.38.41
# DOES NOT work, but that 1.39.17 works.
message("")
message("=== IMPORTANT: Make sure to use a recent version of Emscripten (preferably >= 2.0.0) ===")
message("")


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


# Ask for the generation of a side module
set(WASM_FLAGS "-s SIDE_MODULE=1 -s EXPORT_ALL=1")  # Must be before "Compiler.cmake"


# 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")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1")
endif()

set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0")
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
# ---------------------------------------------------------------

include(${CMAKE_SOURCE_DIR}/../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(ORTHANC_SANDBOXED ON)

include(${CMAKE_SOURCE_DIR}/../OrthancStoneWebAssemblyConfiguration.cmake)




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

# The source files that register a callback cannot be part of a side
# module, and must be compiled in the main module. The following
# command can be used to identify such files:
#  $ grep -lrE 'emscripten_' ../../Sources/

set(SOURCES_WITH_EMSCRIPTEN_CALLBACKS
  ${CMAKE_SOURCE_DIR}/../WebAssemblyOracle.cpp
  ${CMAKE_SOURCE_DIR}/../WebAssemblyViewport.cpp
  ${CMAKE_SOURCE_DIR}/../WebAssemblyCairoViewport.cpp
  )

list(REMOVE_ITEM ORTHANC_STONE_SOURCES
  ${SOURCES_WITH_EMSCRIPTEN_CALLBACKS}
  )

configure_file(
  ${ORTHANC_STONE_ROOT}/../SharedLibrary/OrthancStone.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-stone/OrthancStone.h
  )

configure_file(
  ${ORTHANC_FRAMEWORK_ROOT}/../SharedLibrary/OrthancFramework.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework/OrthancFramework.h
  )

file(
  COPY ${CMAKE_SOURCE_DIR}/../../../../OrthancStone/Sources/
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-stone
  NO_SOURCE_PERMISSIONS
  FILES_MATCHING
  PATTERN "*.h"
  PATTERN OrthancStone.h EXCLUDE
  PATTERN "Deprecated*" EXCLUDE
  )

file(
  COPY ${ORTHANC_FRAMEWORK_ROOT}/
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
  NO_SOURCE_PERMISSIONS
  FILES_MATCHING
  PATTERN "*.h"
  PATTERN OrthancFramework.h EXCLUDE
  )

add_executable(OrthancStoneModule
  ${ORTHANC_STONE_SOURCES}
  ${AUTOGENERATED_SOURCES}  
  ${CAIRO_SOURCES}
  ${PIXMAN_SOURCES}
  ${FREETYPE_SOURCES}
  )

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

# CMake does not natively handle SIDE_MODULE, and believes that
# Emscripten produces a ".js" file (whereas it creates only the
# ".wasm"). Create a dummy ".js" for target to work.
add_custom_command(
  TARGET OrthancStoneModule POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/OrthancStoneModule.js
  )

file(
  COPY ${BOOST_SOURCES_DIR}/boost/
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/boost/
  NO_SOURCE_PERMISSIONS
  FILES_MATCHING
  PATTERN "*.h"
  PATTERN "*.hpp"
  PATTERN "*.ipp"
  )

file(
  COPY ${JSONCPP_SOURCES_DIR}/include/json/
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/json/
  NO_SOURCE_PERMISSIONS
  FILES_MATCHING
  PATTERN "*.h"
  )

file(
  COPY ${CAIRO_SOURCES_DIR}/src/
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/cairo/
  NO_SOURCE_PERMISSIONS
  FILES_MATCHING
  PATTERN "*.h"
  )

set(DCMTK_MODULES
  dcmdata
  config
  ofstd
  oflog
  )

foreach (module IN LISTS DCMTK_MODULES)
  file(
    COPY ${DCMTK_SOURCES_DIR}/ofstd/include/dcmtk/${module}/
    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/${module}/
    NO_SOURCE_PERMISSIONS
    FILES_MATCHING
    PATTERN "*.h"
    )
endforeach()

    
install(
  TARGETS OrthancStoneModule
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/lib
  )

install(FILES
  ${CMAKE_CURRENT_BINARY_DIR}/OrthancStoneModule.wasm
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/lib
  )

install(
  DIRECTORY
  ${CMAKE_CURRENT_BINARY_DIR}/Include/boost
  ${CMAKE_CURRENT_BINARY_DIR}/Include/cairo
  ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk
  ${CMAKE_CURRENT_BINARY_DIR}/Include/json
  ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
  ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-stone
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/include/
  )

install(FILES
  ${SOURCES_WITH_EMSCRIPTEN_CALLBACKS}
  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/src/orthanc-stone
  )