comparison Applications/Platforms/WebAssembly/SharedLibrary/CMakeLists.txt @ 1591:5887a4f8594b

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