changeset 409:e25f4500b531

fix linking against system-wide Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 Apr 2023 14:55:21 +0200
parents ca6dc9bb8b79
children 614031f7a16d 07622792f862
files Resources/CMake/DatabasesFrameworkConfiguration.cmake Resources/CMake/DatabasesFrameworkParameters.cmake Resources/Orthanc/CMake/OpenSslConfiguration.cmake Resources/Orthanc/CMake/ProtobufConfiguration.cmake Resources/SyncOrthancFolder.py
diffstat 5 files changed, 167 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/CMake/DatabasesFrameworkConfiguration.cmake	Sat Apr 15 13:58:16 2023 +0200
+++ b/Resources/CMake/DatabasesFrameworkConfiguration.cmake	Sat Apr 15 14:55:21 2023 +0200
@@ -68,11 +68,21 @@
   if (ENABLE_SQLITE_BACKEND)
     add_definitions(-DORTHANC_ENABLE_SQLITE=1)
   endif()
-  
+
+  # These parameters should *NOT* be modified by the user: System-wide
+  # installations expect only dynamic linking
   set(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test")
+  set(USE_SYSTEM_OPENSSL ON CACHE BOOL "Use the system version of OpenSSL")
+  set(USE_SYSTEM_PROTOBUF ON CACHE BOOL "Use the system version of Google Protocol Buffers")
+
   set(USE_GOOGLE_TEST_DEBIAN_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)")
   mark_as_advanced(USE_GOOGLE_TEST_DEBIAN_PACKAGE)
+
+  set(ENABLE_OPENSSL_ENGINES ON CACHE INTERNAL "")
+
   include(${CMAKE_CURRENT_LIST_DIR}/../Orthanc/CMake/GoogleTestConfiguration.cmake)
+  include(${CMAKE_CURRENT_LIST_DIR}/../Orthanc/CMake/OpenSslConfiguration.cmake)
+  include(${CMAKE_CURRENT_LIST_DIR}/../Orthanc/CMake/ProtobufConfiguration.cmake)
   
 else()
   # Those modules of the Orthanc framework are not needed when dealing
--- a/Resources/CMake/DatabasesFrameworkParameters.cmake	Sat Apr 15 13:58:16 2023 +0200
+++ b/Resources/CMake/DatabasesFrameworkParameters.cmake	Sat Apr 15 14:55:21 2023 +0200
@@ -51,8 +51,6 @@
 set(ENABLE_MYSQL_BACKEND OFF)
 set(ENABLE_ODBC_BACKEND OFF)
 set(ENABLE_POSTGRESQL_BACKEND OFF)
-set(ENABLE_SQLITE_BACKEND OFF)
-
-# Interfacing with Orthanc 1.12.0
 set(ENABLE_PROTOBUF ON)
 set(ENABLE_PROTOBUF_COMPILER ON)
+set(ENABLE_SQLITE_BACKEND OFF)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Orthanc/CMake/OpenSslConfiguration.cmake	Sat Apr 15 14:55:21 2023 +0200
@@ -0,0 +1,68 @@
+# Orthanc - A Lightweight, RESTful DICOM Store
+# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+# Department, University Hospital of Liege, Belgium
+# Copyright (C) 2017-2023 Osimis S.A., Belgium
+# Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+
+
+if (STATIC_BUILD OR NOT USE_SYSTEM_OPENSSL)
+  if (OPENSSL_STATIC_VERSION STREQUAL "1.1.1")
+    # Still used by orthanc-gcp (Google Cloud Platform) as of its release 1.0
+    include(${CMAKE_CURRENT_LIST_DIR}/OpenSslConfigurationStatic-1.1.1.cmake)
+  elseif (OPENSSL_STATIC_VERSION STREQUAL "3.0")
+    include(${CMAKE_CURRENT_LIST_DIR}/OpenSslConfigurationStatic-3.0.cmake)
+  else()
+    message(FATAL_ERROR "Unsupported version of OpenSSL: ${OPENSSL_STATIC_VERSION}")
+  endif()
+
+  source_group(ThirdParty\\OpenSSL REGULAR_EXPRESSION ${OPENSSL_SOURCES_DIR}/.*)
+
+elseif (CMAKE_CROSSCOMPILING AND
+    "${CMAKE_SYSTEM_VERSION}" STREQUAL "CrossToolNg")
+
+  CHECK_INCLUDE_FILE_CXX(openssl/opensslv.h HAVE_OPENSSL_H)
+  if (NOT HAVE_OPENSSL_H)
+    message(FATAL_ERROR "Please install the libopenssl-dev package")
+  endif()
+
+  CHECK_LIBRARY_EXISTS(crypto "OPENSSL_init" "" HAVE_OPENSSL_CRYPTO_LIB)
+  if (NOT HAVE_OPENSSL_CRYPTO_LIB)
+    message(FATAL_ERROR "Please install the libopenssl package")
+  endif()  
+
+  # The "SSL_library_init" is for OpenSSL <= 1.0.2, whereas
+  # "OPENSSL_init_ssl" is for OpenSSL >= 1.1.0
+  CHECK_LIBRARY_EXISTS(ssl "SSL_library_init" "" HAVE_OPENSSL_SSL_LIB)
+  if (NOT HAVE_OPENSSL_SSL_LIB)
+    CHECK_LIBRARY_EXISTS(ssl "OPENSSL_init_ssl" "" HAVE_OPENSSL_SSL_LIB_2)
+    if (NOT HAVE_OPENSSL_SSL_LIB_2)
+      message(FATAL_ERROR "Please install the libopenssl package")
+    endif()  
+  endif()  
+  
+  link_libraries(crypto ssl)
+
+else()
+  include(FindOpenSSL)
+
+  if (NOT OPENSSL_FOUND)
+    message(FATAL_ERROR "Unable to find OpenSSL")
+  endif()
+
+  include_directories(${OPENSSL_INCLUDE_DIR})
+  link_libraries(${OPENSSL_LIBRARIES})
+endif()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Orthanc/CMake/ProtobufConfiguration.cmake	Sat Apr 15 14:55:21 2023 +0200
@@ -0,0 +1,85 @@
+# Orthanc - A Lightweight, RESTful DICOM Store
+# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+# Department, University Hospital of Liege, Belgium
+# Copyright (C) 2017-2023 Osimis S.A., Belgium
+# Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+
+
+if (STATIC_BUILD OR NOT USE_SYSTEM_PROTOBUF)
+  if (ENABLE_PROTOBUF_COMPILER)
+    include(ExternalProject)
+    externalproject_add(ProtobufCompiler
+      SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers"
+      BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ProtobufCompiler-build"
+      # this helps triggering build when changing the external project
+      BUILD_ALWAYS 1
+      CMAKE_ARGS
+      -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+      -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
+      )
+
+    # The "protoc" compiler is built using "externalproject_add",
+    # which builds for the host platform, not for the target platform
+    if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
+      set(Suffix ".exe")
+    else()
+      set(Suffix "")
+    endif()
+
+    set(PROTOC_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/protoc${Suffix})
+  endif()
+
+  include(${CMAKE_CURRENT_LIST_DIR}/../ProtocolBuffers/ProtobufLibrary.cmake)  
+  source_group(ThirdParty\\Protobuf REGULAR_EXPRESSION ${PROTOBUF_SOURCE_DIR}/.*)
+
+else()
+  if (CMAKE_CROSSCOMPILING)
+    message(FATAL_ERROR "If cross-compiling, the static version of Protocol Buffers should be used to avoid version mismatch")
+  endif()
+  
+  if (ENABLE_PROTOBUF_COMPILER)
+    find_program(PROTOC_EXECUTABLE protoc)
+    if (${PROTOC_EXECUTABLE} MATCHES "PROTOC_EXECUTABLE-NOTFOUND")
+      message(FATAL_ERROR "Please install the 'protoc' compiler for Protocol Buffers (package 'protobuf-compiler' on Debian/Ubuntu)")
+    endif()
+    add_custom_target(ProtobufCompiler)
+  endif()
+  
+  check_include_file_cxx(google/protobuf/any.h HAVE_PROTOBUF_H)
+  if (NOT HAVE_PROTOBUF_H)
+    message(FATAL_ERROR "Please install the libprotobuf-dev package")
+  endif()
+
+  set(CMAKE_REQUIRED_LIBRARIES "protobuf")
+
+  include(CheckCXXSourceCompiles) 
+  check_cxx_source_compiles(
+    "
+#include <google/protobuf/descriptor.h>
+int main()
+{
+  google::protobuf::FieldDescriptor::TypeName(google::protobuf::FieldDescriptor::TYPE_FLOAT);
+}
+"  HAVE_PROTOBUF_LIB)
+  if (NOT HAVE_PROTOBUF_LIB)
+    message(FATAL_ERROR "Cannot find the protobuf library")
+  endif()
+  
+  unset(CMAKE_REQUIRED_LIBRARIES)
+
+  link_libraries(protobuf)
+endif()
--- a/Resources/SyncOrthancFolder.py	Sat Apr 15 13:58:16 2023 +0200
+++ b/Resources/SyncOrthancFolder.py	Sat Apr 15 14:55:21 2023 +0200
@@ -27,6 +27,8 @@
     ('default', 'OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake', 'CMake'),
     ('default', 'OrthancFramework/Resources/CMake/DownloadPackage.cmake', 'CMake'),
     ('default', 'OrthancFramework/Resources/CMake/GoogleTestConfiguration.cmake', 'CMake'),
+    ('default', 'OrthancFramework/Resources/CMake/OpenSslConfiguration.cmake', 'CMake'),
+    ('default', 'OrthancFramework/Resources/CMake/ProtobufConfiguration.cmake', 'CMake'),
     ('default', 'OrthancFramework/Resources/EmbedResources.py', '.'),
     ('default', 'OrthancFramework/Resources/Toolchains/LinuxStandardBaseToolchain.cmake', '.'),
     ('default', 'OrthancFramework/Resources/Toolchains/MinGW-W64-Toolchain32.cmake', '.'),