comparison OrthancFramework/SharedLibrary/CMakeLists.txt @ 4063:e00f3d089991 framework

shared library of orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 16:40:34 +0200
parents
children d6362b2c4b61
comparison
equal deleted inserted replaced
4062:0953b3dc3261 4063:e00f3d089991
1
2 ## To see all the exported symbols in the DLL:
3 ##
4 ## $ i686-w64-mingw32-objdump -p ./libOrthancFramework.dll
5 ##
6 ## IMPORTANT: "-static-libgcc" prevents catching exception in the
7 ## .EXE, which makes throwing exceptions crash the software!
8 ##
9
10
11 cmake_minimum_required(VERSION 2.8)
12 project(OrthancFramework)
13
14 # *Do not* use CMAKE_INSTALL_PREFIX, otherwise CMake automatically
15 # *adds CMAKE_INSTALL_PREFIX to the include_directories()!
16 set(ORTHANC_INSTALL_DIR "/tmp/install" CACHE PATH "")
17 SET(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests")
18
19
20 # This must be before inclusion of "OrthancFrameworkParameters.cmake" to take effect
21 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
22 CMAKE_COMPILER_IS_GNUCXX) # MinGW
23 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions)
24 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
25 endif()
26
27 include(${CMAKE_SOURCE_DIR}/../Resources/CMake/OrthancFrameworkParameters.cmake)
28
29 set(ENABLE_DCMTK ON)
30 set(ENABLE_DCMTK_TRANSCODING ON)
31 set(ENABLE_GOOGLE_TEST ON)
32 set(ENABLE_JPEG ON)
33 set(ENABLE_LOCALE ON)
34 set(ENABLE_LUA ON)
35 set(ENABLE_PNG ON)
36 set(ENABLE_PUGIXML ON)
37 set(ENABLE_ZLIB ON)
38
39 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
40 # WebAssembly or asm.js
41 set(BOOST_LOCALE_BACKEND "libiconv")
42 set(ORTHANC_SANDBOXED ON)
43
44 else()
45 # Enable all the remaining modules for other targets
46 set(ENABLE_CRYPTO_OPTIONS ON)
47 set(ENABLE_DCMTK_NETWORKING ON)
48 set(ENABLE_OPENSSL_ENGINES ON)
49 set(ENABLE_SQLITE ON)
50 set(ENABLE_WEB_CLIENT ON)
51 set(ENABLE_WEB_SERVER ON)
52
53 set(BOOST_LOCALE_BACKEND "icu")
54 endif()
55
56
57 set(ORTHANC_BUILDING_FRAMEWORK_LIBRARY ON)
58
59 # Don't use the version script that is reserved for plugins
60 set(ENABLE_PLUGINS_VERSION_SCRIPT OFF)
61
62 include(${CMAKE_SOURCE_DIR}/../Resources/CMake/OrthancFrameworkConfiguration.cmake)
63
64 if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP)
65 set(ORTHANC_STATIC_JSONCPP ON)
66 else()
67 set(ORTHANC_STATIC_JSONCPP OFF)
68 endif()
69
70 if (STATIC_BUILD OR NOT USE_SYSTEM_BOOST)
71 set(ORTHANC_STATIC_BOOST ON)
72 else()
73 set(ORTHANC_STATIC_BOOST OFF)
74 endif()
75
76 if (STATIC_BUILD OR NOT USE_SYSTEM_SQLITE)
77 set(ORTHANC_STATIC_SQLITE ON)
78 else()
79 set(ORTHANC_STATIC_SQLITE OFF)
80 endif()
81
82 if (STATIC_BUILD OR NOT USE_SYSTEM_PUGIXML)
83 set(ORTHANC_STATIC_PUGIXML ON)
84 else()
85 set(ORTHANC_STATIC_PUGIXML OFF)
86 endif()
87
88
89 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
90 CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
91
92 # Control the visibility of JsonCpp
93 if (ORTHANC_STATIC_JSONCPP)
94 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
95 set_source_files_properties(${JSONCPP_SOURCES}
96 PROPERTIES COMPILE_DEFINITIONS "JSON_API=__declspec(dllexport)"
97 )
98 set(ORTHANC_JSON_API "__declspec(dllimport)")
99 else()
100 set(ORTHANC_JSON_API "__attribute__((visibility(\"default\")))")
101 set_source_files_properties(${JSONCPP_SOURCES}
102 PROPERTIES COMPILE_DEFINITIONS "JSON_API=${ORTHANC_JSON_API}"
103 )
104 endif()
105 endif()
106
107 # Control the visibility of SQLite
108 if (ORTHANC_STATIC_SQLITE)
109 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
110 set_source_files_properties(${SQLITE_SOURCES}
111 PROPERTIES COMPILE_DEFINITIONS "SQLITE_API=__declspec(dllexport)"
112 )
113 set(ORTHANC_SQLITE_API "__declspec(dllimport)")
114 else()
115 set(ORTHANC_SQLITE_API "__attribute__((visibility(\"default\")))")
116 set_source_files_properties(${SQLITE_SOURCES}
117 PROPERTIES COMPILE_DEFINITIONS "SQLITE_API=${ORTHANC_SQLITE_API}"
118 )
119 endif()
120 endif()
121
122 # Control the visibility of Boost
123 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND
124 ORTHANC_STATIC_BOOST)
125 set_source_files_properties(${ORTHANC_CORE_SOURCES_INTERNAL}
126 PROPERTIES COMPILE_DEFINITIONS "BOOST_DATE_TIME_SOURCE;BOOST_FILESYSTEM_SOURCE;BOOST_LOCALE_SOURCE;BOOST_REGEX_SOURCE"
127 )
128 endif()
129
130 # Control the visibility of Pugixml
131 if (ORTHANC_STATIC_PUGIXML)
132 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
133 set_source_files_properties(${PUGIXML_SOURCES}
134 PROPERTIES COMPILE_DEFINITIONS "PUGIXML_API=__declspec(dllexport)"
135 )
136 set(ORTHANC_PUGIXML_API "__declspec(dllimport)")
137 else()
138 set(ORTHANC_PUGIXML_API "__attribute__((visibility(\"default\")))")
139 set_source_files_properties(${PUGIXML_SOURCES}
140 PROPERTIES COMPILE_DEFINITIONS "PUGIXML_API=${ORTHANC_PUGIXML_API}"
141 )
142 endif()
143 endif()
144 endif()
145
146
147 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
148 execute_process(
149 COMMAND
150 ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/../Resources/WindowsResources.py
151 ${ORTHANC_VERSION} "OrthancFramework" OrthancFramework.dll "Shared library containing the Orthanc framework"
152 ERROR_VARIABLE Failure
153 OUTPUT_FILE ${AUTOGENERATED_DIR}/Version.rc
154 )
155
156 if (Failure)
157 message(FATAL_ERROR "Error while computing the version information: ${Failure}")
158 endif()
159
160 list(APPEND AUTOGENERATED_SOURCES ${AUTOGENERATED_DIR}/Version.rc)
161 endif()
162
163
164 add_definitions(
165 -DCIVETWEB_API= # Don't export the public symbols from CivetWeb
166 )
167
168 # Those two files collided with each other, and thus are merged into a
169 # single "DllMain.cpp"
170 list(REMOVE_ITEM ORTHANC_CORE_SOURCES
171 ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_dll.cpp
172 ${OPENSSL_SOURCES_DIR}/crypto/dllmain.c
173 )
174
175 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
176 # In WebAssembly, a SIDE_MODULE is an executable
177 add_executable(OrthancFramework
178 ${AUTOGENERATED_SOURCES}
179 ${ORTHANC_CORE_SOURCES}
180 ${ORTHANC_DICOM_SOURCES}
181 DllMain.cpp
182 )
183
184 # CMake does not natively handle SIDE_MODULE, and believes that
185 # Emscripten produces a ".js" file (whereas it creates only the
186 # ".wasm"). Create a dummy ".js" for target to work.
187 add_custom_command(
188 TARGET OrthancFramework POST_BUILD
189 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/OrthancFramework.js
190 )
191 else()
192 add_library(OrthancFramework SHARED
193 ${AUTOGENERATED_SOURCES}
194 ${ORTHANC_CORE_SOURCES}
195 ${ORTHANC_DICOM_SOURCES}
196 DllMain.cpp
197 )
198 endif()
199
200 # By default, hide all the symbols
201 set_target_properties(OrthancFramework PROPERTIES C_VISIBILITY_PRESET hidden)
202 set_target_properties(OrthancFramework PROPERTIES CXX_VISIBILITY_PRESET hidden)
203
204 target_link_libraries(OrthancFramework ${DCMTK_LIBRARIES})
205
206 if (LIBICU_LIBRARIES)
207 target_link_libraries(OrthancFramework ${LIBICU_LIBRARIES})
208 endif()
209
210 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
211 target_link_libraries(OrthancFramework winpthread)
212 endif()
213
214
215 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
216 set_target_properties(
217 OrthancFramework PROPERTIES
218 VERSION ${ORTHANC_VERSION}
219 SOVERSION ${ORTHANC_VERSION}
220 )
221 endif()
222
223
224 file(
225 COPY ${CMAKE_SOURCE_DIR}/../Sources/
226 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
227 NO_SOURCE_PERMISSIONS
228 FILES_MATCHING
229 PATTERN "*.h"
230 PATTERN OrthancFramework.h EXCLUDE
231 )
232
233 configure_file(
234 ${CMAKE_SOURCE_DIR}/OrthancFramework.h.in
235 ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework/OrthancFramework.h
236 )
237
238
239 if (ORTHANC_STATIC_BOOST)
240 file(
241 COPY ${BOOST_SOURCES_DIR}/boost/
242 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/boost/
243 NO_SOURCE_PERMISSIONS
244 FILES_MATCHING
245 PATTERN "*.h"
246 PATTERN "*.hpp"
247 PATTERN "*.ipp"
248 )
249 endif()
250
251
252 if (ENABLE_SQLITE AND ORTHANC_STATIC_SQLITE)
253 file(
254 COPY ${SQLITE_SOURCES_DIR}/
255 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
256 NO_SOURCE_PERMISSIONS
257 FILES_MATCHING
258 PATTERN "*.h"
259 )
260 endif()
261
262
263 if (ORTHANC_STATIC_JSONCPP)
264 file(
265 COPY ${JSONCPP_SOURCES_DIR}/include/json/
266 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/json/
267 NO_SOURCE_PERMISSIONS
268 FILES_MATCHING
269 PATTERN "*.h"
270 )
271 endif()
272
273
274 if (ENABLE_DCMTK AND (STATIC_BUILD OR NOT USE_SYSTEM_DCMTK))
275 file(
276 COPY ${DCMTK_SOURCES_DIR}/dcmdata/include/dcmtk/dcmdata/
277 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/dcmdata/
278 NO_SOURCE_PERMISSIONS
279 FILES_MATCHING
280 PATTERN "*.h"
281 )
282
283 file(
284 COPY ${DCMTK_SOURCES_DIR}/config/include/dcmtk/config/
285 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/config/
286 NO_SOURCE_PERMISSIONS
287 FILES_MATCHING
288 PATTERN "*.h"
289 )
290
291 file(
292 COPY ${DCMTK_SOURCES_DIR}/ofstd/include/dcmtk/ofstd/
293 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/ofstd/
294 NO_SOURCE_PERMISSIONS
295 FILES_MATCHING
296 PATTERN "*.h"
297 )
298
299 file(
300 COPY ${DCMTK_SOURCES_DIR}/oflog/include/dcmtk/oflog/
301 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/oflog/
302 NO_SOURCE_PERMISSIONS
303 FILES_MATCHING
304 PATTERN "*.h"
305 )
306 endif()
307
308
309 if (ENABLE_PUGIXML AND (STATIC_BUILD OR NOT USE_SYSTEM_PUGIXML))
310 file(
311 COPY ${PUGIXML_SOURCES_DIR}/src/
312 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
313 NO_SOURCE_PERMISSIONS
314 FILES_MATCHING
315 PATTERN "*.hpp"
316 )
317 endif()
318
319
320 if (ENABLE_LUA AND (STATIC_BUILD OR NOT USE_SYSTEM_LUA))
321 file(
322 COPY ${LUA_SOURCES_DIR}/src/
323 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
324 NO_SOURCE_PERMISSIONS
325 FILES_MATCHING
326 PATTERN "*.h"
327 )
328 endif()
329
330
331 if (OFF)
332 # These files are fully abstracted by the Orthanc Framework classes
333 if (ENABLE_PNG AND (STATIC_BUILD OR NOT USE_SYSTEM_LIBPNG))
334 file(
335 COPY ${LIBPNG_SOURCES_DIR}/
336 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
337 NO_SOURCE_PERMISSIONS
338 FILES_MATCHING
339 PATTERN "*.h"
340 )
341 endif()
342
343 if (ENABLE_ZLIB AND (STATIC_BUILD OR NOT USE_SYSTEM_ZLIB))
344 file(
345 COPY ${ZLIB_SOURCES_DIR}/
346 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
347 NO_SOURCE_PERMISSIONS
348 FILES_MATCHING
349 PATTERN "*.h"
350 )
351 endif()
352
353 if (ENABLE_JPEG AND (STATIC_BUILD OR NOT USE_SYSTEM_LIBJPEG))
354 file(
355 COPY ${LIBJPEG_SOURCES_DIR}/
356 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
357 NO_SOURCE_PERMISSIONS
358 FILES_MATCHING
359 PATTERN "*.h"
360 )
361 endif()
362
363 if (ENABLE_WEB_CLIENT AND (STATIC_BUILD OR NOT USE_SYSTEM_CURL))
364 file(
365 COPY ${CURL_SOURCES_DIR}/include/curl/
366 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/curl/
367 NO_SOURCE_PERMISSIONS
368 FILES_MATCHING
369 PATTERN "*.h"
370 )
371 endif()
372 endif()
373
374
375
376
377
378 include(ExternalProject)
379
380 if (CMAKE_TOOLCHAIN_FILE)
381 # Take absolute path to the toolchain
382 get_filename_component(TMP ${CMAKE_TOOLCHAIN_FILE} REALPATH BASE ${CMAKE_SOURCE_DIR}/..)
383 list(APPEND Flags -DCMAKE_TOOLCHAIN_FILE=${TMP})
384 endif()
385
386 # Build the unit tests, linking them against the just-created
387 # "OrthancFramework" library
388 externalproject_add(UnitTests
389 SOURCE_DIR "${CMAKE_SOURCE_DIR}/../UnitTestsSources"
390 CMAKE_ARGS
391 -DALLOW_DOWNLOADS:BOOL=ON
392 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
393 -DORTHANC_FRAMEWORK_LIBDIR:PATH=${CMAKE_CURRENT_BINARY_DIR}
394 -DORTHANC_FRAMEWORK_ROOT:PATH=${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
395 -DORTHANC_FRAMEWORK_SOURCE:STRING=system
396 -DORTHANC_FRAMEWORK_STATIC:BOOL=${STATIC_BUILD}
397 -DUNIT_TESTS_WITH_HTTP_CONNEXIONS:BOOL=${UNIT_TESTS_WITH_HTTP_CONNEXIONS}
398 -DUSE_SYSTEM_GOOGLE_TEST:BOOL=OFF
399 ${Flags}
400 )
401
402 add_dependencies(UnitTests OrthancFramework)
403
404
405 install(
406 TARGETS OrthancFramework
407 RUNTIME DESTINATION ${ORTHANC_INSTALL_DIR}/lib # Destination for Windows
408 LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib # Destination for Linux
409 )
410
411 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
412 install(FILES
413 ${CMAKE_CURRENT_BINARY_DIR}/OrthancFramework.wasm
414 LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib
415 )
416 endif()
417
418 install(
419 DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
420 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/orthanc-framework
421 )