Problem building with OpenSSl support on macOS

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
konis
Posts: 28
Joined: Mon, 2015-11-23, 16:05

Problem building with OpenSSl support on macOS

#1 Post by konis » Fri, 2018-10-26, 10:06

Hi,

The version of OpenSSL that comes bundled with macOS is quite old (0.9.7 or something, Apple has switched to using its own Security Frameworks a couple of years ago). So I built OpenSSl from source and I tried to guide DCMTK to use this version without much luck.

I am using the latest snapshot of DCMTK and CMake keeps telling me that:
Info: DCMTK OPENSSL support will be disabled: DCMTK requires OpenSSL version 1.0.1 or newer
Here are the related settings from CMake:

OPENSSL_CRYPTO_LIBRARY is set to: /Users/konis/Desktop/app_dev/openssl_111/lib/libcrypto.dylib
OPENSSL_INCLUDE_DIR is set to: /Users/konis/Desktop/app_dev/openssl_111/include
OPENSSL_SSL_LIBRARY is set to: /Users/konis/Desktop/app_dev/openssl_111/lib/libssl.dylib

I have also tried with versions 1.0.2p and 1.1.0h of OpenSSL with the same result. Is there anything else I need to do to use OpenSSL ?

- Christos Konidaris

konis
Posts: 28
Joined: Mon, 2015-11-23, 16:05

Re: Problem building with OpenSSl support on macOS

#2 Post by konis » Tue, 2018-10-30, 14:17

After some more testing, I see that the problem is with the dcmtk 3.6.3 snapshots.

Running Cmake on the sources from dcmtk-3.6.2_snapshot-e0b0223.tar.gz dated 02/11/2017 works OK, but using either the latest dcmtk-3.6.3_snapshot-e27f8cb.tar.gz dated 12/10/2018, or the older, dcmtk-3.6.3_snapshot-5926741.tar.gz dated 05/06/2018 produce the 'DCMTK OPENSSL support will be disabled' message.

I have tried with both Xcode v9.4.1 and v10, and Cmake 3.9.5 and 3.12.3.

The problem comes from changes related to Open SSL support in the 3rdparty.cmake file between the dcmtk 3.6.2 and 3.6.3 sources.

From 3rdparty.cmake in dcmtk 3.6.2

Code: Select all

  IF(DCMTK_WITH_OPENSSL)
    FIND_PACKAGE(OpenSSL QUIET)
    IF(NOT OPENSSL_FOUND)
      MESSAGE(STATUS "Warning: OPENSSL support will be disabled because openssl was not found.")
      SET(WITH_OPENSSL "")
      SET(DCMTK_WITH_OPENSSL OFF CACHE BOOL "" FORCE)
    ELSE(NOT OPENSSL_FOUND)
      MESSAGE(STATUS "Info: DCMTK OPENSSL support will be enabled")
      SET(WITH_OPENSSL 1)
      INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
      SET(OPENSSL_LIBS ${OPENSSL_LIBRARIES})
    ENDIF(NOT OPENSSL_FOUND)
  ENDIF(DCMTK_WITH_OPENSSL)
From 3rdparty.cmake in dcmtk 3.6.3

Code: Select all

  if(DCMTK_WITH_OPENSSL)
    find_package(OpenSSL QUIET)
    if(NOT OPENSSL_FOUND)
      message(STATUS "Warning: OPENSSL support will be disabled because openssl was not found.")
      set(WITH_OPENSSL "")
      set(DCMTK_WITH_OPENSSL OFF CACHE BOOL "" FORCE)
    else()
      include(CheckLibraryExists)
      include(CheckCXXSourceCompiles)
      CHECK_CXX_SOURCE_COMPILES("extern \"C\" {\n#include <openssl/ssl.h>\n}\nint main(){\n#if OPENSSL_VERSION_NUMBER < 0x10001000L\n#error OpenSSL too old\n#endif\n}\n" OPENSSL_VERSION_CHECK)
      if(OPENSSL_VERSION_CHECK)
        message(STATUS "Info: DCMTK OPENSSL support will be enabled")
        set(WITH_OPENSSL 1)
        include_directories(${OPENSSL_INCLUDE_DIR})
        set(OPENSSL_LIBS ${OPENSSL_LIBRARIES})
        CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
        if(HAVE_LIBDL)
          set(OPENSSL_LIBS ${OPENSSL_LIBS} dl)
        endif()
      else()
        message(STATUS "Info: DCMTK OPENSSL support will be disabled: DCMTK requires OpenSSL version 1.0.1 or newer")
        set(DCMTK_WITH_OPENSSL OFF CACHE BOOL "" FORCE)
        set(WITH_OPENSSL "")
      endif()
    endif()
  endif()
I also noticed that the dcmtk 3.6.3 sources have the same problem with iconv support.

- Christos Konidaris

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Problem building with OpenSSl support on macOS

#3 Post by Jan Schlamelcher » Tue, 2018-10-30, 17:01

Thanks for inspecting this further. My guess would be that, although you installed an own version of OpenSSL, the one that comes bundled with macOS still has its headers in the default include search paths, leading to the tests #include <openssl/ssl.h> command including an old version of this header and then giving you the error message.

konis
Posts: 28
Joined: Mon, 2015-11-23, 16:05

Re: Problem building with OpenSSl support on macOS

#4 Post by konis » Wed, 2018-10-31, 14:02

Here is the related segment from CMakeError.log. I think it does not find any openssl headers.

Code: Select all

Check dependencies

Write auxiliary files
/bin/mkdir -p /Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/Objects-normal/x86_64
write-file /Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/Objects-normal/x86_64/cmTC_09a15.LinkFileList

CompileC CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/Objects-normal/x86_64/src.o src.cxx normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR=\"Debug\" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.14 -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/Debug/include -I/Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/DerivedSources/x86_64 -I/Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/Debug -D_XOPEN_SOURCE_EXTENDED -D_BSD_SOURCE -D_BSD_COMPAT -D_OSF_SOURCE -D_DARWIN_C_SOURCE -DOPENSSL_VERSION_CHECK -MMD -MT dependencies -MF /Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/Objects-normal/x86_64/src.d --serialize-diagnostics /Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/Objects-normal/x86_64/src.dia -c /Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/src.cxx -o /Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_09a15.build/Objects-normal/x86_64/src.o
/Users/konis/Desktop/EMV5_dev/dcmtk/CMakeFiles/CMakeTmp/src.cxx:2:10: fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h>
         ^~~~~~~~~~~~~~~
1 error generated.

** BUILD FAILED **


Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1280
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Problem building with OpenSSl support on macOS

#5 Post by Marco Eichelberg » Thu, 2018-11-01, 12:48

It is true that DCMTK up to release 3.6.2 compiled with very old OpenSSL releases. The TLS code in DCMTK has been completely revised recently, implementing newer security profiles meanwhile defined in the DICOM standard. In particular, we now require TLS 1.2 which in turn needs OpenSSL 1.0.2.

DCMTK uses the standard CMake macro named FindOpenSSL to detect OpenSSL on the system where it compiles. You can use the OPENSSL_ROOT_DIR variable to influence the behavior of that macro. Try

Code: Select all

cmake -DOPENSSL_ROOT_DIR=/Users/konis/Desktop/app_dev/openssl_111
.

konis
Posts: 28
Joined: Mon, 2015-11-23, 16:05

Re: Problem building with OpenSSl support on macOS

#6 Post by konis » Thu, 2018-11-01, 17:45

Marco,

I got the same result ('openssl/ssl.h' file not found) when I defined the OPENSSL_ROOT_DIR. The OPENSSL_CRYPTO_LIBRARY, OPENSSL_INCLUDE_DIR and OPENSSL_SSL_LIBRARY are automatically set to their correct values but no joy. I can send you the CMakeError.log file if you like.

Let me know if you want me to try anything else.

One question: If I comment out the check for OpenSSL version in the 3rdparty.cmake file, and provided I set the OPENSSL_ROOT_DIR variable to my version of OpenSSL, will CMake produce a proper/correct version of toolkit sources that use OpenSSL?

That way I can work with the toolkit while we find out how to correct this problem.

- Christos

konis
Posts: 28
Joined: Mon, 2015-11-23, 16:05

Re: Problem building with OpenSSl support on macOS

#7 Post by konis » Thu, 2018-11-01, 17:58

Marco,

Two more notes:

1) I am trying to generate the apps and not the shared libs.
2) I don't see any call to FindOpenSSL in the snapshot sources.

Regards,

- Christos

konis
Posts: 28
Joined: Mon, 2015-11-23, 16:05

Re: Problem building with OpenSSl support on macOS

#8 Post by konis » Tue, 2018-11-13, 18:02

An update for anyone having the same problem:

The following workaround works for me in order to build the latest DCMTK 3.6.3 snapshot with OpenSSL support on macOS:

1) I comment out line #201 in 3rdparty.cmake and manually set OPENSSL_VERSION_CHECK to 1, since I know I have OpenSSL installed:

Code: Select all

#   CHECK_CXX_SOURCE_COMPILES("extern \"C\" {\n#include <openssl/ssl.h>\n}\nint main(){\n#if OPENSSL_VERSION_NUMBER < 0x10001000L\n#error OpenSSL too old\n#endif\n}\n" OPENSSL_VERSION_CHECK)
     set(OPENSSL_VERSION_CHECK 1)
2) In Cmake I add the following PATH entry, as Marco Eichelberg suggested:

Code: Select all

cmake -DOPENSSL_ROOT_DIR=directory containing my OpenSSL installation
With these two changes Cmake is able to generate the toolkit sources with OpenSSL support that build correctly. It is a hack I know, but it will do until I have a better solution.

- Christos

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Problem building with OpenSSl support on macOS

#9 Post by Jan Schlamelcher » Wed, 2018-11-14, 11:41

I just looked at the code fragment from 3rdparty.cmake you've posted. Is it possible (perhaps a question for Marco) that the OpenSSL version check does not use the previously detected include directory of OpenSSL, therefore fails if OpenSSL does not exist in the standard include search paths? I noticed INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) only comes after / once the version check already succeeded.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest