diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/SharedLibrary/CMakeLists.txt	Thu Jun 11 16:40:34 2020 +0200
@@ -0,0 +1,421 @@
+
+## To see all the exported symbols in the DLL:
+##
+##  $ i686-w64-mingw32-objdump -p ./libOrthancFramework.dll
+##
+## IMPORTANT: "-static-libgcc" prevents catching exception in the
+## .EXE, which makes throwing exceptions crash the software!
+##
+
+
+cmake_minimum_required(VERSION 2.8)
+project(OrthancFramework)
+
+# *Do not* use CMAKE_INSTALL_PREFIX, otherwise CMake automatically
+# *adds CMAKE_INSTALL_PREFIX to the include_directories()!
+set(ORTHANC_INSTALL_DIR "/tmp/install" CACHE PATH "")
+SET(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests")
+
+
+# This must be before inclusion of "OrthancFrameworkParameters.cmake" to take effect
+if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
+    CMAKE_COMPILER_IS_GNUCXX) # MinGW
+  set(DYNAMIC_MINGW_STDLIB ON)   # Disable static linking against libc (to throw exceptions)
+  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
+endif()
+
+include(${CMAKE_SOURCE_DIR}/../Resources/CMake/OrthancFrameworkParameters.cmake)
+
+set(ENABLE_DCMTK ON)
+set(ENABLE_DCMTK_TRANSCODING ON)
+set(ENABLE_GOOGLE_TEST ON)
+set(ENABLE_JPEG ON)
+set(ENABLE_LOCALE ON)
+set(ENABLE_LUA ON)
+set(ENABLE_PNG ON)
+set(ENABLE_PUGIXML ON)
+set(ENABLE_ZLIB ON)
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  # WebAssembly or asm.js
+  set(BOOST_LOCALE_BACKEND "libiconv")
+  set(ORTHANC_SANDBOXED ON)
+
+else()
+  # Enable all the remaining modules for other targets
+  set(ENABLE_CRYPTO_OPTIONS ON)
+  set(ENABLE_DCMTK_NETWORKING ON)
+  set(ENABLE_OPENSSL_ENGINES ON)
+  set(ENABLE_SQLITE ON)
+  set(ENABLE_WEB_CLIENT ON)
+  set(ENABLE_WEB_SERVER ON)
+
+  set(BOOST_LOCALE_BACKEND "icu")
+endif()
+
+
+set(ORTHANC_BUILDING_FRAMEWORK_LIBRARY ON)
+
+# Don't use the version script that is reserved for plugins
+set(ENABLE_PLUGINS_VERSION_SCRIPT OFF)
+
+include(${CMAKE_SOURCE_DIR}/../Resources/CMake/OrthancFrameworkConfiguration.cmake)
+
+if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP)
+  set(ORTHANC_STATIC_JSONCPP ON)
+else()
+  set(ORTHANC_STATIC_JSONCPP OFF)
+endif()
+
+if (STATIC_BUILD OR NOT USE_SYSTEM_BOOST)
+  set(ORTHANC_STATIC_BOOST ON)
+else()
+  set(ORTHANC_STATIC_BOOST OFF)
+endif()
+
+if (STATIC_BUILD OR NOT USE_SYSTEM_SQLITE)
+  set(ORTHANC_STATIC_SQLITE ON)
+else()
+  set(ORTHANC_STATIC_SQLITE OFF)
+endif()
+
+if (STATIC_BUILD OR NOT USE_SYSTEM_PUGIXML)
+  set(ORTHANC_STATIC_PUGIXML ON)
+else()
+  set(ORTHANC_STATIC_PUGIXML OFF)
+endif()
+
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
+    CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+
+  # Control the visibility of JsonCpp
+  if (ORTHANC_STATIC_JSONCPP)
+    if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+      set_source_files_properties(${JSONCPP_SOURCES}
+        PROPERTIES COMPILE_DEFINITIONS "JSON_API=__declspec(dllexport)"
+        )
+      set(ORTHANC_JSON_API "__declspec(dllimport)")
+    else()
+      set(ORTHANC_JSON_API "__attribute__((visibility(\"default\")))")
+      set_source_files_properties(${JSONCPP_SOURCES}
+        PROPERTIES COMPILE_DEFINITIONS "JSON_API=${ORTHANC_JSON_API}"
+        )
+    endif()
+  endif()
+
+  # Control the visibility of SQLite
+  if (ORTHANC_STATIC_SQLITE)
+    if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+      set_source_files_properties(${SQLITE_SOURCES}
+        PROPERTIES COMPILE_DEFINITIONS "SQLITE_API=__declspec(dllexport)"
+        )
+      set(ORTHANC_SQLITE_API "__declspec(dllimport)")
+    else()
+      set(ORTHANC_SQLITE_API "__attribute__((visibility(\"default\")))")
+      set_source_files_properties(${SQLITE_SOURCES}
+        PROPERTIES COMPILE_DEFINITIONS "SQLITE_API=${ORTHANC_SQLITE_API}"
+        )
+    endif()
+  endif()
+
+  # Control the visibility of Boost
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND
+      ORTHANC_STATIC_BOOST)
+    set_source_files_properties(${ORTHANC_CORE_SOURCES_INTERNAL}
+      PROPERTIES COMPILE_DEFINITIONS "BOOST_DATE_TIME_SOURCE;BOOST_FILESYSTEM_SOURCE;BOOST_LOCALE_SOURCE;BOOST_REGEX_SOURCE"
+      )
+  endif()
+
+  # Control the visibility of Pugixml
+  if (ORTHANC_STATIC_PUGIXML)
+    if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+      set_source_files_properties(${PUGIXML_SOURCES}
+        PROPERTIES COMPILE_DEFINITIONS "PUGIXML_API=__declspec(dllexport)"
+        )
+      set(ORTHANC_PUGIXML_API "__declspec(dllimport)")
+    else()
+      set(ORTHANC_PUGIXML_API "__attribute__((visibility(\"default\")))")
+      set_source_files_properties(${PUGIXML_SOURCES}
+        PROPERTIES COMPILE_DEFINITIONS "PUGIXML_API=${ORTHANC_PUGIXML_API}"
+        )
+    endif()
+  endif()
+endif()
+
+
+if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+  execute_process(
+    COMMAND 
+    ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/../Resources/WindowsResources.py
+    ${ORTHANC_VERSION} "OrthancFramework" OrthancFramework.dll "Shared library containing the Orthanc framework"
+    ERROR_VARIABLE Failure
+    OUTPUT_FILE ${AUTOGENERATED_DIR}/Version.rc
+    )
+
+  if (Failure)
+    message(FATAL_ERROR "Error while computing the version information: ${Failure}")
+  endif()
+
+  list(APPEND AUTOGENERATED_SOURCES  ${AUTOGENERATED_DIR}/Version.rc)
+endif()
+
+
+add_definitions(
+  -DCIVETWEB_API=    # Don't export the public symbols from CivetWeb
+  )
+
+# Those two files collided with each other, and thus are merged into a
+# single "DllMain.cpp"
+list(REMOVE_ITEM ORTHANC_CORE_SOURCES
+  ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_dll.cpp
+  ${OPENSSL_SOURCES_DIR}/crypto/dllmain.c
+  )
+    
+if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  # In WebAssembly, a SIDE_MODULE is an executable
+  add_executable(OrthancFramework
+    ${AUTOGENERATED_SOURCES}
+    ${ORTHANC_CORE_SOURCES}
+    ${ORTHANC_DICOM_SOURCES}
+    DllMain.cpp
+    )
+
+  # CMake does not natively handle SIDE_MODULE, and believes that
+  # Emscripten produces a ".js" file (whereas it creates only the
+  # ".wasm"). Create a dummy ".js" for target to work.
+  add_custom_command(
+    TARGET OrthancFramework POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/OrthancFramework.js
+    )
+else()
+  add_library(OrthancFramework SHARED
+    ${AUTOGENERATED_SOURCES}
+    ${ORTHANC_CORE_SOURCES}
+    ${ORTHANC_DICOM_SOURCES}
+    DllMain.cpp
+    )
+endif()
+
+# By default, hide all the symbols
+set_target_properties(OrthancFramework PROPERTIES C_VISIBILITY_PRESET hidden)
+set_target_properties(OrthancFramework PROPERTIES CXX_VISIBILITY_PRESET hidden)
+
+target_link_libraries(OrthancFramework ${DCMTK_LIBRARIES})
+
+if (LIBICU_LIBRARIES)
+  target_link_libraries(OrthancFramework ${LIBICU_LIBRARIES})
+endif()
+
+if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+  target_link_libraries(OrthancFramework winpthread)
+endif()
+
+
+if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  set_target_properties(
+    OrthancFramework PROPERTIES 
+    VERSION ${ORTHANC_VERSION} 
+    SOVERSION ${ORTHANC_VERSION}
+    )
+endif()
+
+
+file(
+  COPY ${CMAKE_SOURCE_DIR}/../Sources/
+  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
+  NO_SOURCE_PERMISSIONS
+  FILES_MATCHING
+  PATTERN "*.h"
+  PATTERN OrthancFramework.h EXCLUDE
+  )
+
+configure_file(
+  ${CMAKE_SOURCE_DIR}/OrthancFramework.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework/OrthancFramework.h
+  )
+
+
+if (ORTHANC_STATIC_BOOST)
+  file(
+    COPY ${BOOST_SOURCES_DIR}/boost/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/boost/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    PATTERN "*.hpp"
+    PATTERN "*.ipp"
+    )
+endif()
+
+
+if (ENABLE_SQLITE AND ORTHANC_STATIC_SQLITE)
+  file(
+    COPY ${SQLITE_SOURCES_DIR}/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    )
+endif()
+
+
+if (ORTHANC_STATIC_JSONCPP)
+  file(
+    COPY ${JSONCPP_SOURCES_DIR}/include/json/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/json/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    )
+endif()
+
+
+if (ENABLE_DCMTK AND (STATIC_BUILD OR NOT USE_SYSTEM_DCMTK))
+  file(
+    COPY ${DCMTK_SOURCES_DIR}/dcmdata/include/dcmtk/dcmdata/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/dcmdata/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    )
+
+  file(
+    COPY ${DCMTK_SOURCES_DIR}/config/include/dcmtk/config/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/config/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    )
+
+  file(
+    COPY ${DCMTK_SOURCES_DIR}/ofstd/include/dcmtk/ofstd/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/ofstd/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    )
+
+  file(
+    COPY ${DCMTK_SOURCES_DIR}/oflog/include/dcmtk/oflog/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/dcmtk/oflog/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    )
+endif()
+
+
+if (ENABLE_PUGIXML AND (STATIC_BUILD OR NOT USE_SYSTEM_PUGIXML))
+  file(
+    COPY ${PUGIXML_SOURCES_DIR}/src/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.hpp"
+    )
+endif()
+
+
+if (ENABLE_LUA AND (STATIC_BUILD OR NOT USE_SYSTEM_LUA))
+  file(
+    COPY ${LUA_SOURCES_DIR}/src/
+    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
+    NO_SOURCE_PERMISSIONS
+    FILES_MATCHING
+    PATTERN "*.h"
+    )
+endif()
+
+
+if (OFF)
+  # These files are fully abstracted by the Orthanc Framework classes
+  if (ENABLE_PNG AND (STATIC_BUILD OR NOT USE_SYSTEM_LIBPNG))
+    file(
+      COPY ${LIBPNG_SOURCES_DIR}/
+      DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
+      NO_SOURCE_PERMISSIONS
+      FILES_MATCHING
+      PATTERN "*.h"
+      )
+  endif()
+
+  if (ENABLE_ZLIB AND (STATIC_BUILD OR NOT USE_SYSTEM_ZLIB))
+    file(
+      COPY ${ZLIB_SOURCES_DIR}/
+      DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
+      NO_SOURCE_PERMISSIONS
+      FILES_MATCHING
+      PATTERN "*.h"
+      )
+  endif()
+
+  if (ENABLE_JPEG AND (STATIC_BUILD OR NOT USE_SYSTEM_LIBJPEG))
+    file(
+      COPY ${LIBJPEG_SOURCES_DIR}/
+      DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/
+      NO_SOURCE_PERMISSIONS
+      FILES_MATCHING
+      PATTERN "*.h"
+      )
+  endif()
+
+  if (ENABLE_WEB_CLIENT AND (STATIC_BUILD OR NOT USE_SYSTEM_CURL))
+    file(
+      COPY ${CURL_SOURCES_DIR}/include/curl/
+      DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Include/curl/
+      NO_SOURCE_PERMISSIONS
+      FILES_MATCHING
+      PATTERN "*.h"
+      )
+  endif()
+endif()
+
+
+
+
+
+include(ExternalProject)
+
+if (CMAKE_TOOLCHAIN_FILE)
+  # Take absolute path to the toolchain
+  get_filename_component(TMP ${CMAKE_TOOLCHAIN_FILE} REALPATH BASE ${CMAKE_SOURCE_DIR}/..)
+  list(APPEND Flags -DCMAKE_TOOLCHAIN_FILE=${TMP})
+endif()
+
+# Build the unit tests, linking them against the just-created
+# "OrthancFramework" library
+externalproject_add(UnitTests
+  SOURCE_DIR "${CMAKE_SOURCE_DIR}/../UnitTestsSources"
+  CMAKE_ARGS
+  -DALLOW_DOWNLOADS:BOOL=ON
+  -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+  -DORTHANC_FRAMEWORK_LIBDIR:PATH=${CMAKE_CURRENT_BINARY_DIR}
+  -DORTHANC_FRAMEWORK_ROOT:PATH=${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
+  -DORTHANC_FRAMEWORK_SOURCE:STRING=system
+  -DORTHANC_FRAMEWORK_STATIC:BOOL=${STATIC_BUILD}
+  -DUNIT_TESTS_WITH_HTTP_CONNEXIONS:BOOL=${UNIT_TESTS_WITH_HTTP_CONNEXIONS}
+  -DUSE_SYSTEM_GOOGLE_TEST:BOOL=OFF
+  ${Flags}
+  )
+
+add_dependencies(UnitTests OrthancFramework)
+
+
+install(
+  TARGETS OrthancFramework
+  RUNTIME DESTINATION ${ORTHANC_INSTALL_DIR}/lib    # Destination for Windows
+  LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib    # Destination for Linux
+  )
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  install(FILES
+    ${CMAKE_CURRENT_BINARY_DIR}/OrthancFramework.wasm
+    LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib
+    )
+endif()
+
+install(
+  DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
+  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/orthanc-framework
+  )