comparison OrthancFramework/SharedLibrary/CMakeLists.txt @ 4066:3a59a021b5de framework

build instructions for the library
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 18:43:14 +0200
parents d6362b2c4b61
children 3d7afb01dc14
comparison
equal deleted inserted replaced
4065:d6362b2c4b61 4066:3a59a021b5de
9 9
10 10
11 cmake_minimum_required(VERSION 2.8) 11 cmake_minimum_required(VERSION 2.8)
12 project(OrthancFramework) 12 project(OrthancFramework)
13 13
14
15
16 #####################################################################
17 ## Additional parameters
18 #####################################################################
19
14 # *Do not* use CMAKE_INSTALL_PREFIX, otherwise CMake automatically 20 # *Do not* use CMAKE_INSTALL_PREFIX, otherwise CMake automatically
15 # *adds CMAKE_INSTALL_PREFIX to the include_directories()! 21 # adds CMAKE_INSTALL_PREFIX to the include_directories(), which causes
22 # issues if re-building the shared library after install!
16 set(ORTHANC_INSTALL_DIR "/tmp/install" CACHE PATH "") 23 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") 24 SET(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests")
18 25
26
27
28 #####################################################################
29 ## Configuration of the Orthanc framework
30 #####################################################################
19 31
20 # This must be before inclusion of "OrthancFrameworkParameters.cmake" to take effect 32 # This must be before inclusion of "OrthancFrameworkParameters.cmake" to take effect
21 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND 33 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
22 CMAKE_COMPILER_IS_GNUCXX) # MinGW 34 CMAKE_COMPILER_IS_GNUCXX) # MinGW
23 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions) 35 set(DYNAMIC_MINGW_STDLIB ON) # Disable static linking against libc (to throw exceptions)
59 # Don't use the version script that is reserved for plugins 71 # Don't use the version script that is reserved for plugins
60 set(ENABLE_PLUGINS_VERSION_SCRIPT OFF) 72 set(ENABLE_PLUGINS_VERSION_SCRIPT OFF)
61 73
62 include(${CMAKE_SOURCE_DIR}/../Resources/CMake/OrthancFrameworkConfiguration.cmake) 74 include(${CMAKE_SOURCE_DIR}/../Resources/CMake/OrthancFrameworkConfiguration.cmake)
63 75
76
77
78 #####################################################################
79 ## Configuration the visibility of the third-party libraries in the
80 ## shared library
81 #####################################################################
82
64 if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP) 83 if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP)
65 set(ORTHANC_STATIC_JSONCPP ON) 84 set(ORTHANC_STATIC_JSONCPP ON)
66 else() 85 else()
67 set(ORTHANC_STATIC_JSONCPP OFF) 86 set(ORTHANC_STATIC_JSONCPP OFF)
68 endif() 87 endif()
154 PROPERTIES COMPILE_DEFINITIONS "DCMTK_BUILD_IN_PROGRESS;DCMTK_BUILD_SINGLE_SHARED_LIBRARY;DCMTK_SHARED;HAVE_HIDDEN_VISIBILITY;dcmdata_EXPORTS" 173 PROPERTIES COMPILE_DEFINITIONS "DCMTK_BUILD_IN_PROGRESS;DCMTK_BUILD_SINGLE_SHARED_LIBRARY;DCMTK_SHARED;HAVE_HIDDEN_VISIBILITY;dcmdata_EXPORTS"
155 ) 174 )
156 endif() 175 endif()
157 endif() 176 endif()
158 177
178
179 add_definitions(
180 -DCIVETWEB_API= # Don't export the public symbols from CivetWeb
181 )
182
183
184
185 #####################################################################
186 ## Building the shared library
187 #####################################################################
159 188
160 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 189 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
161 execute_process( 190 execute_process(
162 COMMAND 191 COMMAND
163 ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/../Resources/WindowsResources.py 192 ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/../Resources/WindowsResources.py
172 201
173 list(APPEND AUTOGENERATED_SOURCES ${AUTOGENERATED_DIR}/Version.rc) 202 list(APPEND AUTOGENERATED_SOURCES ${AUTOGENERATED_DIR}/Version.rc)
174 endif() 203 endif()
175 204
176 205
177 add_definitions( 206 # Those two files collide with each other, and thus are merged into a
178 -DCIVETWEB_API= # Don't export the public symbols from CivetWeb
179 )
180
181 # Those two files collided with each other, and thus are merged into a
182 # single "DllMain.cpp" 207 # single "DllMain.cpp"
183 list(REMOVE_ITEM ORTHANC_CORE_SOURCES 208 list(REMOVE_ITEM ORTHANC_CORE_SOURCES
184 ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_dll.cpp 209 ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_dll.cpp
185 ${OPENSSL_SOURCES_DIR}/crypto/dllmain.c 210 ${OPENSSL_SOURCES_DIR}/crypto/dllmain.c
186 ) 211 )
187 212
188 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") 213 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
189 # In WebAssembly, a SIDE_MODULE is an executable 214 # In WebAssembly, a SIDE_MODULE is an executable
190 add_executable(OrthancFramework 215 add_executable(OrthancFramework
191 ${AUTOGENERATED_SOURCES} 216 ${AUTOGENERATED_SOURCES}
192 ${ORTHANC_CORE_SOURCES} 217 ${ORTHANC_CORE_SOURCES}
193 ${ORTHANC_DICOM_SOURCES} 218 ${ORTHANC_DICOM_SOURCES}
194 DllMain.cpp
195 ) 219 )
196 220
197 # CMake does not natively handle SIDE_MODULE, and believes that 221 # CMake does not natively handle SIDE_MODULE, and believes that
198 # Emscripten produces a ".js" file (whereas it creates only the 222 # Emscripten produces a ".js" file (whereas it creates only the
199 # ".wasm"). Create a dummy ".js" for target to work. 223 # ".wasm"). Create a dummy ".js" for target to work.
208 ${ORTHANC_DICOM_SOURCES} 232 ${ORTHANC_DICOM_SOURCES}
209 DllMain.cpp 233 DllMain.cpp
210 ) 234 )
211 endif() 235 endif()
212 236
213 # By default, hide all the symbols
214 set_target_properties(OrthancFramework PROPERTIES C_VISIBILITY_PRESET hidden)
215 set_target_properties(OrthancFramework PROPERTIES CXX_VISIBILITY_PRESET hidden)
216
217 target_link_libraries(OrthancFramework ${DCMTK_LIBRARIES})
218
219 if (LIBICU_LIBRARIES)
220 target_link_libraries(OrthancFramework ${LIBICU_LIBRARIES})
221 endif()
222
223 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
224 target_link_libraries(OrthancFramework winpthread)
225 endif()
226
227 237
228 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") 238 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
239 # By default, hide all the symbols
240 set_target_properties(OrthancFramework PROPERTIES C_VISIBILITY_PRESET hidden)
241 set_target_properties(OrthancFramework PROPERTIES CXX_VISIBILITY_PRESET hidden)
242
243 # Configure the version of the shared library
229 set_target_properties( 244 set_target_properties(
230 OrthancFramework PROPERTIES 245 OrthancFramework PROPERTIES
231 VERSION ${ORTHANC_VERSION} 246 VERSION ${ORTHANC_VERSION}
232 SOVERSION ${ORTHANC_VERSION} 247 SOVERSION ${ORTHANC_VERSION}
233 ) 248 )
234 endif() 249 endif()
235 250
251
252 target_link_libraries(OrthancFramework ${DCMTK_LIBRARIES})
253
254 if (LIBICU_LIBRARIES)
255 target_link_libraries(OrthancFramework ${LIBICU_LIBRARIES})
256 endif()
257
258 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
259 target_link_libraries(OrthancFramework winpthread)
260 endif()
261
262
263
264 #####################################################################
265 ## Publish the headers into the "Include" folder of the build
266 ## directory
267 #####################################################################
236 268
237 file( 269 file(
238 COPY ${CMAKE_SOURCE_DIR}/../Sources/ 270 COPY ${CMAKE_SOURCE_DIR}/../Sources/
239 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework 271 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
240 NO_SOURCE_PERMISSIONS 272 NO_SOURCE_PERMISSIONS
384 endif() 416 endif()
385 endif() 417 endif()
386 418
387 419
388 420
389 421 #####################################################################
390 422 ## Possibly install the headers and the binaries
391 include(ExternalProject) 423 #####################################################################
392
393 if (CMAKE_TOOLCHAIN_FILE)
394 # Take absolute path to the toolchain
395 get_filename_component(TMP ${CMAKE_TOOLCHAIN_FILE} REALPATH BASE ${CMAKE_SOURCE_DIR}/..)
396 list(APPEND Flags -DCMAKE_TOOLCHAIN_FILE=${TMP})
397 endif()
398
399 # Build the unit tests, linking them against the just-created
400 # "OrthancFramework" library
401 externalproject_add(UnitTests
402 SOURCE_DIR "${CMAKE_SOURCE_DIR}/../UnitTestsSources"
403 CMAKE_ARGS
404 -DALLOW_DOWNLOADS:BOOL=ON
405 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
406 -DORTHANC_FRAMEWORK_LIBDIR:PATH=${CMAKE_CURRENT_BINARY_DIR}
407 -DORTHANC_FRAMEWORK_ROOT:PATH=${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
408 -DORTHANC_FRAMEWORK_SOURCE:STRING=system
409 -DORTHANC_FRAMEWORK_STATIC:BOOL=${STATIC_BUILD}
410 -DUNIT_TESTS_WITH_HTTP_CONNEXIONS:BOOL=${UNIT_TESTS_WITH_HTTP_CONNEXIONS}
411 -DUSE_SYSTEM_GOOGLE_TEST:BOOL=OFF
412 ${Flags}
413 )
414
415 add_dependencies(UnitTests OrthancFramework)
416
417 424
418 install( 425 install(
419 TARGETS OrthancFramework 426 TARGETS OrthancFramework
420 RUNTIME DESTINATION ${ORTHANC_INSTALL_DIR}/lib # Destination for Windows 427 RUNTIME DESTINATION ${ORTHANC_INSTALL_DIR}/lib # Destination for Windows
421 LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib # Destination for Linux 428 LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib # Destination for Linux
422 ) 429 )
423 430
424 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") 431 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
425 install(FILES 432 install(FILES
426 ${CMAKE_CURRENT_BINARY_DIR}/OrthancFramework.wasm 433 ${CMAKE_CURRENT_BINARY_DIR}/OrthancFramework.wasm
427 LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib 434 DESTINATION ${ORTHANC_INSTALL_DIR}/lib
428 ) 435 )
429 endif() 436 endif()
430 437
431 install( 438 install(
432 DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework 439 DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Include/
433 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/orthanc-framework 440 DESTINATION ${ORTHANC_INSTALL_DIR}/include/
434 ) 441 )
442
443
444
445 #####################################################################
446 ## Compile the unit tests
447 #####################################################################
448
449 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
450 include(ExternalProject)
451
452 if (CMAKE_TOOLCHAIN_FILE)
453 # Take absolute path to the toolchain
454 get_filename_component(TMP ${CMAKE_TOOLCHAIN_FILE} REALPATH BASE ${CMAKE_SOURCE_DIR}/..)
455 list(APPEND Flags -DCMAKE_TOOLCHAIN_FILE=${TMP})
456 endif()
457
458 # Build the unit tests, linking them against the just-created
459 # "OrthancFramework" library
460 externalproject_add(UnitTests
461 SOURCE_DIR "${CMAKE_SOURCE_DIR}/../UnitTestsSources"
462 CMAKE_ARGS
463 -DALLOW_DOWNLOADS:BOOL=ON
464 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
465 -DORTHANC_FRAMEWORK_LIBDIR:PATH=${CMAKE_CURRENT_BINARY_DIR}
466 -DORTHANC_FRAMEWORK_ROOT:PATH=${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
467 -DORTHANC_FRAMEWORK_SOURCE:STRING=system
468 -DORTHANC_FRAMEWORK_STATIC:BOOL=${STATIC_BUILD}
469 -DUNIT_TESTS_WITH_HTTP_CONNEXIONS:BOOL=${UNIT_TESTS_WITH_HTTP_CONNEXIONS}
470 -DUSE_SYSTEM_GOOGLE_TEST:BOOL=OFF
471 ${Flags}
472 )
473
474 add_dependencies(UnitTests OrthancFramework)
475 endif()