diff UnitTestsSources/WebAssembly/CMakeLists.txt @ 1679:5b8b88e5bfd6

successfully running unit tests in WebAssembly
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2020 12:59:10 +0100
parents
children 03afa09cfcf1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTestsSources/WebAssembly/CMakeLists.txt	Tue Nov 24 12:59:10 2020 +0100
@@ -0,0 +1,99 @@
+# 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(OrthancStone)
+
+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 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
+)
+
+
+# Stone of Orthanc configuration
+# ---------------------------------------------------------------
+set(ALLOW_DOWNLOADS ON)
+
+include(${CMAKE_SOURCE_DIR}/../../Applications/Platforms/WebAssembly/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)
+
+# Needed to redirect std::cout to a <div>
+set(ORTHANC_ENABLE_LOGGING_STDIO OFF CACHE INTERNAL "")
+
+# this will set up the build system for Stone of Orthanc and will
+# populate the ORTHANC_STONE_SOURCES CMake variable
+include(${CMAKE_SOURCE_DIR}/../../Applications/Platforms/WebAssembly/OrthancStoneWebAssemblyConfiguration.cmake)
+
+
+################################################################################
+
+# Define the WASM module
+# ---------------------------------------------------------------
+
+set(USE_SYSTEM_GOOGLE_TEST OFF CACHE BOOL "Use the system version of Google Test")
+set(USE_GOOGLE_TEST_DEBIAN_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)")
+mark_as_advanced(USE_GOOGLE_TEST_DEBIAN_PACKAGE)
+include(${ORTHANC_STONE_ROOT}/../Resources/Orthanc/CMake/DownloadPackage.cmake)
+include(${ORTHANC_STONE_ROOT}/../Resources/Orthanc/CMake/GoogleTestConfiguration.cmake)
+
+
+include(${CMAKE_SOURCE_DIR}/../UnitTestsSources.cmake)
+add_executable(UnitTests ${UNIT_TESTS_SOURCES})
+
+  
+# Declare installation files for the module
+# ---------------------------------------------------------------
+install(
+  TARGETS UnitTests
+  RUNTIME DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/UnitTests/
+  )
+
+# 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}/index.html
+  ${CMAKE_CURRENT_BINARY_DIR}/UnitTests.wasm
+  DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/UnitTests
+  )