changeset 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
files OrthancFramework/Resources/CMake/Compiler.cmake OrthancFramework/SharedLibrary/CMakeLists.txt OrthancFramework/SharedLibrary/NOTES.txt
diffstat 3 files changed, 141 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Resources/CMake/Compiler.cmake	Thu Jun 11 18:04:28 2020 +0200
+++ b/OrthancFramework/Resources/CMake/Compiler.cmake	Thu Jun 11 18:43:14 2020 +0200
@@ -212,7 +212,7 @@
 
 elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
   message("Building using Emscripten (for WebAssembly or asm.js targets)")
-  include(EmscriptenParameters.cmake)
+  include(${CMAKE_CURRENT_LIST_DIR}/EmscriptenParameters.cmake)
   
 elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
 
--- a/OrthancFramework/SharedLibrary/CMakeLists.txt	Thu Jun 11 18:04:28 2020 +0200
+++ b/OrthancFramework/SharedLibrary/CMakeLists.txt	Thu Jun 11 18:43:14 2020 +0200
@@ -11,12 +11,24 @@
 cmake_minimum_required(VERSION 2.8)
 project(OrthancFramework)
 
+
+
+#####################################################################
+## Additional parameters
+#####################################################################
+
 # *Do not* use CMAKE_INSTALL_PREFIX, otherwise CMake automatically
-# *adds CMAKE_INSTALL_PREFIX to the include_directories()!
+# adds CMAKE_INSTALL_PREFIX to the include_directories(), which causes
+# issues if re-building the shared library after install!
 set(ORTHANC_INSTALL_DIR "/tmp/install" CACHE PATH "")
 SET(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests")
 
 
+
+#####################################################################
+## Configuration of the Orthanc framework
+#####################################################################
+
 # This must be before inclusion of "OrthancFrameworkParameters.cmake" to take effect
 if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
     CMAKE_COMPILER_IS_GNUCXX) # MinGW
@@ -61,6 +73,13 @@
 
 include(${CMAKE_SOURCE_DIR}/../Resources/CMake/OrthancFrameworkConfiguration.cmake)
 
+
+
+#####################################################################
+## Configuration the visibility of the third-party libraries in the
+## shared library
+#####################################################################
+
 if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP)
   set(ORTHANC_STATIC_JSONCPP ON)
 else()
@@ -157,6 +176,16 @@
 endif()
 
 
+add_definitions(
+  -DCIVETWEB_API=    # Don't export the public symbols from CivetWeb
+  )
+
+
+
+#####################################################################
+## Building the shared library
+#####################################################################
+
 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
   execute_process(
     COMMAND 
@@ -174,24 +203,19 @@
 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
+# Those two files collide 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
@@ -210,9 +234,20 @@
     )
 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)
+
+if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  # By default, hide all the symbols
+  set_target_properties(OrthancFramework PROPERTIES C_VISIBILITY_PRESET hidden)
+  set_target_properties(OrthancFramework PROPERTIES CXX_VISIBILITY_PRESET hidden)
+
+  # Configure the version of the shared library
+  set_target_properties(
+    OrthancFramework PROPERTIES 
+    VERSION ${ORTHANC_VERSION} 
+    SOVERSION ${ORTHANC_VERSION}
+    )
+endif()
+
 
 target_link_libraries(OrthancFramework ${DCMTK_LIBRARIES})
 
@@ -225,14 +260,11 @@
 endif()
 
 
-if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
-  set_target_properties(
-    OrthancFramework PROPERTIES 
-    VERSION ${ORTHANC_VERSION} 
-    SOVERSION ${ORTHANC_VERSION}
-    )
-endif()
 
+#####################################################################
+## Publish the headers into the "Include" folder of the build
+## directory
+#####################################################################
 
 file(
   COPY ${CMAKE_SOURCE_DIR}/../Sources/
@@ -386,34 +418,9 @@
 
 
 
-
-
-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)
-
+#####################################################################
+## Possibly install the headers and the binaries
+#####################################################################
 
 install(
   TARGETS OrthancFramework
@@ -424,11 +431,45 @@
 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
   install(FILES
     ${CMAKE_CURRENT_BINARY_DIR}/OrthancFramework.wasm
-    LIBRARY DESTINATION ${ORTHANC_INSTALL_DIR}/lib
+    DESTINATION ${ORTHANC_INSTALL_DIR}/lib
     )
 endif()
 
 install(
-  DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Include/orthanc-framework
-  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/orthanc-framework
+  DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Include/
+  DESTINATION ${ORTHANC_INSTALL_DIR}/include/
   )
+
+
+
+#####################################################################
+## Compile the unit tests
+#####################################################################
+
+if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  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)
+endif()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/SharedLibrary/NOTES.txt	Thu Jun 11 18:43:14 2020 +0200
@@ -0,0 +1,50 @@
+
+
+NB: CMake option "ORTHANC_INSTALL_DIR" can be used to specify an
+installation directory (to be used with "ninja install").
+
+
+Dynamic linking under Ubuntu 18.04
+==================================
+
+$ cd i
+$ cmake .. -DCMAKE_BUILD_TYPE=Debug -DALLOW_DOWNLOADS=ON \
+           -DUSE_SYSTEM_CIVETWEB=OFF -DUSE_SYSTEM_GOOGLE_TEST=OFF -G Ninja
+$ ninja -j4
+$ ./UnitTests
+
+
+
+Static linking under GNU/Linux
+==============================
+
+$ cd s
+$ cmake .. -DCMAKE_BUILD_TYPE=Debug -DSTATIC_BUILD=ON -G Ninja
+$ ninja -j4
+$ ./UnitTests
+
+
+
+Cross-compilation to Windows 32 (using MinGW)
+===============================
+
+$ cd w32
+$ cmake .. -DCMAKE_BUILD_TYPE=Release -DSTATIC_BUILD=ON -DUSE_LEGACY_LIBICU=ON -G Ninja \
+        -DCMAKE_TOOLCHAIN_FILE=/home/jodogne/Subversion/orthanc/Resources/MinGW-W64-Toolchain32.cmake
+$ ninja -j4
+
+$ cp /usr/i686-w64-mingw32/lib/libwinpthread-1.dll .
+$ cp /usr/lib/gcc/i686-w64-mingw32/7.3-win32/libgcc_s_sjlj-1.dll .
+$ wine ./UnitTests.exe
+
+
+
+WebAssembly (for the "upstream" version of emscripten)
+===========
+
+$ cd wasm
+$ source ~/Downloads/emsdk/emsdk_env.sh
+$ cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja \
+        -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
+$ ninja -j4
+