comparison OrthancStone/Sources/Platforms/WebAssembly/SharedLibrary/CMakeLists.txt @ 1899:917500c46fe0

moved the Platform folder from the Applications folder to the Stone library itself
author Alain Mazy <am@osimis.io>
date Sat, 29 Jan 2022 12:47:32 +0100
parents
children 563f6aa8e24c
comparison
equal deleted inserted replaced
1898:a5e54bd87b25 1899:917500c46fe0
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 **/
22
23
24 cmake_minimum_required(VERSION 2.8.3)
25 cmake_policy(SET CMP0058 NEW)
26
27 project(OrthancStoneModule)
28
29
30 # Warning message related to WebAssembly modules: We know that 1.38.41
31 # DOES NOT work, but that 1.39.17 works.
32 message("")
33 message("=== IMPORTANT: Make sure to use a recent version of Emscripten (preferably >= 2.0.0) ===")
34 message("")
35
36
37 set(ORTHANC_STONE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../../../../wasm-binaries/OrthancStoneModule" CACHE PATH "Where to put the WebAssembly binaries")
38
39
40 # Ask for the generation of a side module
41 set(WASM_FLAGS "-s SIDE_MODULE=1 -s EXPORT_ALL=1") # Must be before "Compiler.cmake"
42
43
44 # Configuration of the Emscripten compiler for WebAssembly target
45 # ---------------------------------------------------------------
46
47 set(USE_WASM ON CACHE BOOL "")
48
49 set(WASM_FLAGS "${WASM_FLAGS} -s WASM=1 -s FETCH=1")
50 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
51 set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1")
52 endif()
53
54 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0")
55 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1")
56 add_definitions(
57 -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
58 )
59
60
61 # Stone of Orthanc configuration
62 # ---------------------------------------------------------------
63
64 include(${CMAKE_SOURCE_DIR}/../OrthancStoneWebAssemblyParameters.cmake)
65
66 SET(ENABLE_DCMTK ON)
67 SET(ENABLE_DCMTK_NETWORKING OFF)
68 SET(ENABLE_DCMTK_TRANSCODING OFF)
69 SET(ENABLE_GOOGLE_TEST OFF)
70 SET(ENABLE_LOCALE ON) # Necessary for text rendering
71 SET(ORTHANC_SANDBOXED ON)
72
73 include(${CMAKE_SOURCE_DIR}/../OrthancStoneWebAssemblyConfiguration.cmake)
74
75
76
77
78 ################################################################################
79
80 # The source files that register a callback cannot be part of a side
81 # module, and must be compiled in the main module. The following
82 # command can be used to identify such files:
83 # $ grep -lrE 'emscripten_' ../../Sources/
84
85 set(SOURCES_WITH_EMSCRIPTEN_CALLBACKS
86 ${CMAKE_SOURCE_DIR}/../WebAssemblyOracle.cpp
87 ${CMAKE_SOURCE_DIR}/../WebAssemblyViewport.cpp
88 ${CMAKE_SOURCE_DIR}/../WebAssemblyCairoViewport.cpp
89 )
90
91 list(REMOVE_ITEM ORTHANC_STONE_SOURCES
92 ${SOURCES_WITH_EMSCRIPTEN_CALLBACKS}
93 )
94
95 configure_file(
96 ${ORTHANC_STONE_ROOT}/../SharedLibrary/OrthancStone.h.in
97 ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-stone/OrthancStone.h
98 )
99
100 configure_file(
101 ${ORTHANC_FRAMEWORK_ROOT}/../SharedLibrary/OrthancFramework.h.in
102 ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework/OrthancFramework.h
103 )
104
105 file(
106 COPY ${CMAKE_SOURCE_DIR}/../../../../OrthancStone/Sources/
107 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-stone
108 NO_SOURCE_PERMISSIONS
109 FILES_MATCHING
110 PATTERN "*.h"
111 PATTERN OrthancStone.h EXCLUDE
112 PATTERN "Deprecated*" EXCLUDE
113 )
114
115 file(
116 COPY ${ORTHANC_FRAMEWORK_ROOT}/
117 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
118 NO_SOURCE_PERMISSIONS
119 FILES_MATCHING
120 PATTERN "*.h"
121 PATTERN OrthancFramework.h EXCLUDE
122 )
123
124 add_executable(OrthancStoneModule
125 ${ORTHANC_STONE_SOURCES}
126 ${AUTOGENERATED_SOURCES}
127 ${CAIRO_SOURCES}
128 ${PIXMAN_SOURCES}
129 ${FREETYPE_SOURCES}
130 )
131
132 set_target_properties(OrthancStoneModule
133 PROPERTIES
134 COMPILE_FLAGS "${WASM_FLAGS}"
135 LINK_FLAGS "${WASM_LINKER_FLAGS}"
136 )
137
138 # CMake does not natively handle SIDE_MODULE, and believes that
139 # Emscripten produces a ".js" file (whereas it creates only the
140 # ".wasm"). Create a dummy ".js" for target to work.
141 add_custom_command(
142 TARGET OrthancStoneModule POST_BUILD
143 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/OrthancStoneModule.js
144 )
145
146 file(
147 COPY ${BOOST_SOURCES_DIR}/boost/
148 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/boost/
149 NO_SOURCE_PERMISSIONS
150 FILES_MATCHING
151 PATTERN "*.h"
152 PATTERN "*.hpp"
153 PATTERN "*.ipp"
154 )
155
156 file(
157 COPY ${JSONCPP_SOURCES_DIR}/include/json/
158 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/json/
159 NO_SOURCE_PERMISSIONS
160 FILES_MATCHING
161 PATTERN "*.h"
162 )
163
164 file(
165 COPY ${CAIRO_SOURCES_DIR}/src/
166 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/cairo/
167 NO_SOURCE_PERMISSIONS
168 FILES_MATCHING
169 PATTERN "*.h"
170 )
171
172 set(DCMTK_MODULES
173 dcmdata
174 config
175 ofstd
176 oflog
177 )
178
179 foreach (module IN LISTS DCMTK_MODULES)
180 file(
181 COPY ${DCMTK_SOURCES_DIR}/ofstd/include/dcmtk/${module}/
182 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/${module}/
183 NO_SOURCE_PERMISSIONS
184 FILES_MATCHING
185 PATTERN "*.h"
186 )
187 endforeach()
188
189
190 install(
191 TARGETS OrthancStoneModule
192 DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/lib
193 )
194
195 install(FILES
196 ${CMAKE_CURRENT_BINARY_DIR}/OrthancStoneModule.wasm
197 DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/lib
198 )
199
200 install(
201 DIRECTORY
202 ${CMAKE_CURRENT_BINARY_DIR}/Include/boost
203 ${CMAKE_CURRENT_BINARY_DIR}/Include/cairo
204 ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk
205 ${CMAKE_CURRENT_BINARY_DIR}/Include/json
206 ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
207 ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-stone
208 DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/include/
209 )
210
211 install(FILES
212 ${SOURCES_WITH_EMSCRIPTEN_CALLBACKS}
213 DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/src/orthanc-stone
214 )