comparison OrthancStone/Resources/WebAssemblySharedLibrary/CMakeLists.txt @ 1901:184b0aeae1af

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