1# Orthanc - A Lightweight, RESTful DICOM Store 2# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3# Department, University Hospital of Liege, Belgium 4# Copyright (C) 2017-2021 Osimis S.A., Belgium 5# 6# This program is free software: you can redistribute it and/or 7# modify it under the terms of the GNU Lesser General Public License 8# as published by the Free Software Foundation, either version 3 of 9# the License, or (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, but 12# WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14# Lesser General Public License for more details. 15# 16# You should have received a copy of the GNU Lesser General Public 17# License along with this program. If not, see 18# <http://www.gnu.org/licenses/>. 19 20 21SET(DCMTK_VERSION_NUMBER 362) 22SET(DCMTK_PACKAGE_VERSION "3.6.2") 23SET(DCMTK_SOURCES_DIR ${CMAKE_BINARY_DIR}/dcmtk-3.6.2) 24SET(DCMTK_URL "http://orthanc.osimis.io/ThirdPartyDownloads/dcmtk-3.6.2.tar.gz") 25SET(DCMTK_MD5 "d219a4152772985191c9b89d75302d12") 26 27macro(DCMTK_UNSET) 28endmacro() 29 30macro(DCMTK_UNSET_CACHE) 31endmacro() 32 33set(DCMTK_BINARY_DIR ${DCMTK_SOURCES_DIR}/) 34set(DCMTK_CMAKE_INCLUDE ${DCMTK_SOURCES_DIR}/) 35 36if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") 37 set(DCMTK_WITH_THREADS OFF) # Disable thread support in wasm/asm.js 38else() 39 set(DCMTK_WITH_THREADS ON) 40endif() 41 42add_definitions(-DDCMTK_INSIDE_LOG4CPLUS=1) 43 44if (IS_DIRECTORY "${DCMTK_SOURCES_DIR}") 45 set(FirstRun OFF) 46else() 47 set(FirstRun ON) 48endif() 49 50DownloadPackage(${DCMTK_MD5} ${DCMTK_URL} "${DCMTK_SOURCES_DIR}") 51 52 53if (FirstRun) 54 # "3.6.2 CXX11 fails on Linux; patch suggestions included" 55 # https://forum.dcmtk.org/viewtopic.php?f=3&t=4637 56 message("Applying patch to detect mathematic primitives in DCMTK 3.6.2 with C++11") 57 execute_process( 58 COMMAND ${PATCH_EXECUTABLE} -p0 -N -i 59 ${CMAKE_CURRENT_LIST_DIR}/../Patches/dcmtk-3.6.2.patch 60 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 61 RESULT_VARIABLE Failure 62 ) 63 64 if (Failure) 65 message(FATAL_ERROR "Error while patching a file") 66 endif() 67 68 configure_file( 69 ${CMAKE_CURRENT_LIST_DIR}/../Patches/dcmtk-dcdict_orthanc.cc 70 ${DCMTK_SOURCES_DIR}/dcmdata/libsrc/dcdict_orthanc.cc 71 COPYONLY) 72else() 73 message("The patches for DCMTK have already been applied") 74endif() 75 76 77# C_CHAR_UNSIGNED *must* be set before calling "GenerateDCMTKConfigure.cmake" 78IF (CMAKE_CROSSCOMPILING) 79 if (CMAKE_COMPILER_IS_GNUCXX AND 80 CMAKE_SYSTEM_NAME STREQUAL "Windows") # MinGW 81 SET(C_CHAR_UNSIGNED 1 CACHE INTERNAL "Whether char is unsigned.") 82 83 elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # WebAssembly or asm.js 84 85 # Check out "../WebAssembly/ArithmeticTests/" to regenerate the 86 # "arith.h" file 87 configure_file( 88 ${CMAKE_CURRENT_LIST_DIR}/WebAssembly/arith.h 89 ${DCMTK_SOURCES_DIR}/config/include/dcmtk/config/arith.h 90 COPYONLY) 91 92 UNSET(C_CHAR_UNSIGNED CACHE) 93 SET(C_CHAR_UNSIGNED 0 CACHE INTERNAL "") 94 95 else() 96 message(FATAL_ERROR "Support your platform here") 97 endif() 98ENDIF() 99 100 101if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase") 102 SET(DCMTK_ENABLE_CHARSET_CONVERSION "iconv" CACHE STRING "") 103 SET(HAVE_SYS_GETTID 0 CACHE INTERNAL "") 104 105 if (FirstRun) 106 execute_process( 107 COMMAND ${PATCH_EXECUTABLE} -p0 -N -i 108 ${CMAKE_CURRENT_LIST_DIR}/../Patches/dcmtk-3.6.2-linux-standard-base.patch 109 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 110 RESULT_VARIABLE Failure 111 ) 112 113 if (Failure) 114 message(FATAL_ERROR "Error while patching a file") 115 endif() 116 endif() 117endif() 118 119 120SET(DCMTK_SOURCE_DIR ${DCMTK_SOURCES_DIR}) 121include(${DCMTK_SOURCES_DIR}/CMake/CheckFunctionWithHeaderExists.cmake) 122include(${DCMTK_SOURCES_DIR}/CMake/GenerateDCMTKConfigure.cmake) 123 124 125if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # WebAssembly or 126 # asm.js The macros below are not properly discovered by DCMTK 127 # when using WebAssembly. Check out "../WebAssembly/arith.h" for 128 # how we produced these values. This step MUST be after 129 # "GenerateDCMTKConfigure" and before the generation of 130 # "osconfig.h". 131 UNSET(SIZEOF_VOID_P CACHE) 132 UNSET(SIZEOF_CHAR CACHE) 133 UNSET(SIZEOF_DOUBLE CACHE) 134 UNSET(SIZEOF_FLOAT CACHE) 135 UNSET(SIZEOF_INT CACHE) 136 UNSET(SIZEOF_LONG CACHE) 137 UNSET(SIZEOF_SHORT CACHE) 138 UNSET(SIZEOF_VOID_P CACHE) 139 140 SET(SIZEOF_VOID_P 4 CACHE INTERNAL "") 141 SET(SIZEOF_CHAR 1 CACHE INTERNAL "") 142 SET(SIZEOF_DOUBLE 8 CACHE INTERNAL "") 143 SET(SIZEOF_FLOAT 4 CACHE INTERNAL "") 144 SET(SIZEOF_INT 4 CACHE INTERNAL "") 145 SET(SIZEOF_LONG 4 CACHE INTERNAL "") 146 SET(SIZEOF_SHORT 2 CACHE INTERNAL "") 147 SET(SIZEOF_VOID_P 4 CACHE INTERNAL "") 148endif() 149 150 151set(DCMTK_PACKAGE_VERSION_SUFFIX "") 152set(DCMTK_PACKAGE_VERSION_NUMBER ${DCMTK_VERSION_NUMBER}) 153 154CONFIGURE_FILE( 155 ${DCMTK_SOURCES_DIR}/CMake/osconfig.h.in 156 ${DCMTK_SOURCES_DIR}/config/include/dcmtk/config/osconfig.h) 157 158if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 159 link_libraries(netapi32) # For NetWkstaUserGetInfo@12 160 link_libraries(iphlpapi) # For GetAdaptersInfo@8 161 162 # Configure Wine if cross-compiling for Windows 163 if (CMAKE_COMPILER_IS_GNUCXX) 164 include(${DCMTK_SOURCES_DIR}/CMake/dcmtkUseWine.cmake) 165 FIND_PROGRAM(WINE_WINE_PROGRAM wine) 166 FIND_PROGRAM(WINE_WINEPATH_PROGRAM winepath) 167 list(APPEND DCMTK_TRY_COMPILE_REQUIRED_CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=-static") 168 endif() 169endif() 170 171# This step must be after the generation of "osconfig.h" 172if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") 173 INSPECT_FUNDAMENTAL_ARITHMETIC_TYPES() 174endif() 175 176 177# Source for the logging facility of DCMTK 178AUX_SOURCE_DIRECTORY(${DCMTK_SOURCES_DIR}/oflog/libsrc DCMTK_SOURCES) 179if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR 180 ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR 181 ${CMAKE_SYSTEM_NAME} STREQUAL "DragonFly" OR 182 ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR 183 ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" OR 184 ${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten") 185 list(REMOVE_ITEM DCMTK_SOURCES 186 ${DCMTK_SOURCES_DIR}/oflog/libsrc/clfsap.cc 187 ${DCMTK_SOURCES_DIR}/oflog/libsrc/windebap.cc 188 ${DCMTK_SOURCES_DIR}/oflog/libsrc/winsock.cc 189 ) 190 191elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") 192 list(REMOVE_ITEM DCMTK_SOURCES 193 ${DCMTK_SOURCES_DIR}/oflog/libsrc/unixsock.cc 194 ${DCMTK_SOURCES_DIR}/oflog/libsrc/clfsap.cc 195 ) 196endif() 197 198 199#set_source_files_properties(${DCMTK_SOURCES} 200# PROPERTIES COMPILE_DEFINITIONS 201# "PACKAGE_VERSION=\"${DCMTK_PACKAGE_VERSION}\";PACKAGE_VERSION_NUMBER=\"${DCMTK_VERSION_NUMBER}\"") 202 203 204# Starting with DCMTK 3.6.2, the Nagle algorithm is not disabled by 205# default since this does not seem to be appropriate (anymore) for 206# most modern operating systems. In order to change this default, the 207# environment variable NO_TCPDELAY can be set to "1" (see envvars.txt 208# for details). Alternatively, the macro DISABLE_NAGLE_ALGORITHM can 209# be defined to change this setting at compilation time (see 210# macros.txt for details). 211# https://forum.dcmtk.org/viewtopic.php?t=4632 212add_definitions( 213 -DDISABLE_NAGLE_ALGORITHM=1 214 ) 215