1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindDCMTK
---------
Finds the DICOM ToolKit (DCMTK) libraries and applications:
.. code-block:: cmake
find_package(DCMTK [...])
DCMTK is a set of libraries and applications implementing large parts of
the DICOM Standard (Digital Imaging and Communications in Medicine).
.. versionadded:: 3.5
This module is now able to find a version of DCMTK that does or does not
export a ``DCMTKConfig.cmake`` file.
DCMTK since its version `3.6.1_20140617
<https://git.dcmtk.org/?p=dcmtk.git;a=commit;h=662ae187c493c6b9a73dd5e3875372cebd0c11fe>`_
supports and installs :ref:`package configuration file
<Config File Packages>` (``DCMTKConfig.cmake``) for use with the
:command:`find_package` command in *config mode*.
This module now applies a two-step process:
* Step 1: Attempts to find DCMTK version providing a ``DCMTKConfig.cmake``
file and, if found, returns the results without further action.
* Step 2: If step 1 failed, this module falls back to *module mode*
(it searches standard locations) and sets the ``DCMTK_*`` result
variables.
Until all clients update to the more recent DCMTK, build systems will need
to support different versions of DCMTK.
On any given system, the following combinations of DCMTK versions could
be considered for the DCMTK installed on the system (for example, via a
system package manager), or locally (for example, a custom installation,
or through the :module:`FetchContent` module):
===== ================== =================== ============
Case System DCMTK Local DCMTK Supported?
===== ================== =================== ============
A N/A [ ] DCMTKConfig YES
B N/A [X] DCMTKConfig YES
C [ ] DCMTKConfig N/A YES
D [X] DCMTKConfig N/A YES
E [ ] DCMTKConfig [ ] DCMTKConfig YES (*)
F [X] DCMTKConfig [ ] DCMTKConfig NO
G [ ] DCMTKConfig [X] DCMTKConfig YES
H [X] DCMTKConfig [X] DCMTKConfig YES
===== ================== =================== ============
Legend:
(*)
See the `Troubleshooting`_ section.
N/A
DCMTK is not available.
[ ] DCMTKConfig
DCMTK does NOT export a ``DCMTKConfig.cmake`` file.
[X] DCMTKConfig
DCMTK exports a ``DCMTKConfig.cmake`` file.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``DCMTK_FOUND``
Boolean indicating whether DCMTK was found.
``DCMTK_INCLUDE_DIRS``
Include directories containing headers needed to use DCMTK.
``DCMTK_LIBRARIES``
Libraries needed to link against to use DCMTK.
Hints
^^^^^
This module accepts the following variables:
``DCMTK_DIR``
(optional) Source directory for DCMTK.
Troubleshooting
^^^^^^^^^^^^^^^
.. rubric:: What to do if project finds a different version of DCMTK?
Remove DCMTK entry from the CMake cache per :command:`find_package`
documentation, and re-run configuration. To find DCMTK on custom location
use variables such as :variable:`CMAKE_PREFIX_PATH`, or ``DCMTK_DIR``.
Examples
^^^^^^^^
Example: Finding DCMTK
""""""""""""""""""""""
Finding DCMTK with this module:
.. code-block:: cmake
find_package(DCMTK)
Example: Finding DCMTK Without This Module
""""""""""""""""""""""""""""""""""""""""""
To explicitly use the ``DCMTKConfig.cmake`` package configuration file
(recommended when possible) and find DCMTK in *config mode* without using
this module, the ``NO_MODULE`` option can be given to
:command:`find_package`:
.. code-block:: cmake
find_package(DCMTK NO_MODULE)
Example: Creating Imported Target
"""""""""""""""""""""""""""""""""
In the following example, DCMTK is searched with this module and
an :ref:`imported target <Imported Targets>` is conditionally created to
provide DCMTK usage requirements which can be easily linked to project
targets. For example, if DCMTK is found in *config mode*, the
``DCMTK::DCMTK`` imported target will be available through the found config
files instead:
.. code-block:: cmake
find_package(DCMTK)
# Upstream DCMTKConfig.cmake already provides DCMTK::DCMTK imported target
if(DCMTK_FOUND AND NOT TARGET DCMTK::DCMTK)
add_library(DCMTK::DCMTK INTERFACE IMPORTED)
set_target_properties(
DCMTK:DCMTK
PROPERTIES
INTERFACE_LINK_LIBRARIES "${DCMTK_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${DCMTK_INCLUDE_DIRS}"
)
endif()
target_link_libraries(example PRIVATE DCMTK::DCMTK)
#]=======================================================================]
#
# Written for VXL by Amitha Perera.
# Upgraded for GDCM by Mathieu Malaterre.
# Modified for EasyViz by Thomas Sondergaard.
#
set(_dcmtk_dir_description "The directory of DCMTK build or install tree.")
# Ensure that DCMTK_DIR is set to a reasonable default value
# so that DCMTK libraries can be found on a standard Unix distribution.
# It also overwrite the value of DCMTK_DIR after this one has been
# set by a successful discovery of DCMTK by the unpatched FindDCMTK.cmake module
# distributed with CMake (as of 0167cea)
if(NOT DCMTK_DIR OR DCMTK_DIR STREQUAL "/usr/include/dcmtk")
set(DCMTK_DIR "/usr" CACHE PATH ${_dcmtk_dir_description} FORCE)
endif()
set(_SAVED_DCMTK_DIR ${DCMTK_DIR})
#
# Step1: Attempt to find a version of DCMTK providing a DCMTKConfig.cmake file.
#
if(NOT DCMTK_FIND_QUIETLY)
message(CHECK_START "Trying to find DCMTK expecting DCMTKConfig.cmake")
endif()
find_package(DCMTK QUIET NO_MODULE)
if(DCMTK_FOUND
AND NOT "x" STREQUAL "x${DCMTK_LIBRARIES}"
AND NOT "x" STREQUAL "x${DCMTK_INCLUDE_DIRS}")
if(NOT DCMTK_FIND_QUIETLY)
message(CHECK_PASS "ok")
endif()
return()
else()
if(NOT DCMTK_FIND_QUIETLY)
message(CHECK_FAIL "failed")
endif()
endif()
if(NOT DCMTK_FIND_QUIETLY)
message(STATUS "Trying to find DCMTK relying on FindDCMTK.cmake")
endif()
# Restore the value reset by the previous call to 'find_package(DCMTK QUIET NO_MODULE)'
set(DCMTK_DIR ${_SAVED_DCMTK_DIR} CACHE PATH ${_dcmtk_dir_description} FORCE)
#
# Step2: Attempt to find a version of DCMTK that does NOT provide a DCMTKConfig.cmake file.
#
# prefer DCMTK_DIR over default system paths like /usr/lib
if(DCMTK_DIR)
set(CMAKE_PREFIX_PATH ${DCMTK_DIR}/lib ${CMAKE_PREFIX_PATH}) # this is given to FIND_LIBRARY or FIND_PATH
endif()
# Find all libraries, store debug and release separately
foreach(lib
dcmpstat
dcmsr
dcmsign
dcmtls
dcmqrdb
dcmnet
dcmjpeg
dcmimage
dcmimgle
dcmdata
oflog
ofstd
ijg12
ijg16
ijg8
)
# Find Release libraries
find_library(DCMTK_${lib}_LIBRARY_RELEASE
${lib}
PATHS
${DCMTK_DIR}/${lib}/libsrc
${DCMTK_DIR}/${lib}/libsrc/Release
${DCMTK_DIR}/${lib}/Release
${DCMTK_DIR}/lib
${DCMTK_DIR}/lib/Release
${DCMTK_DIR}/dcmjpeg/lib${lib}/Release
NO_DEFAULT_PATH
)
# Find Debug libraries
find_library(DCMTK_${lib}_LIBRARY_DEBUG
${lib}${DCMTK_CMAKE_DEBUG_POSTFIX}
PATHS
${DCMTK_DIR}/${lib}/libsrc
${DCMTK_DIR}/${lib}/libsrc/Debug
${DCMTK_DIR}/${lib}/Debug
${DCMTK_DIR}/lib
${DCMTK_DIR}/lib/Debug
${DCMTK_DIR}/dcmjpeg/lib${lib}/Debug
NO_DEFAULT_PATH
)
mark_as_advanced(DCMTK_${lib}_LIBRARY_RELEASE)
mark_as_advanced(DCMTK_${lib}_LIBRARY_DEBUG)
# Add libraries to variable according to build type
if(DCMTK_${lib}_LIBRARY_RELEASE)
list(APPEND DCMTK_LIBRARIES optimized ${DCMTK_${lib}_LIBRARY_RELEASE})
endif()
if(DCMTK_${lib}_LIBRARY_DEBUG)
list(APPEND DCMTK_LIBRARIES debug ${DCMTK_${lib}_LIBRARY_DEBUG})
endif()
endforeach()
set(CMAKE_THREAD_LIBS_INIT)
if(DCMTK_oflog_LIBRARY_RELEASE OR DCMTK_oflog_LIBRARY_DEBUG)
# Hack - Not having a DCMTKConfig.cmake file to read the settings from, we will attempt to
# find the library in all cases.
# Ideally, pthread library should be discovered only if DCMTK_WITH_THREADS is enabled.
find_package(Threads)
endif()
if(CMAKE_THREAD_LIBS_INIT)
list(APPEND DCMTK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif()
#
# SPECIFIC CASE FOR DCMTK BUILD DIR as DCMTK_DIR
# (as opposed to a DCMTK install dir)
# Have to find the source directory.
if(EXISTS ${DCMTK_DIR}/CMakeCache.txt)
load_cache(${DCMTK_DIR} READ_WITH_PREFIX "EXT"
DCMTK_SOURCE_DIR)
if(NOT EXISTS ${EXTDCMTK_SOURCE_DIR})
message(FATAL_ERROR
"DCMTK build directory references
nonexistent DCMTK source directory ${EXTDCMTK_SOURCE_DIR}")
endif()
endif()
set(DCMTK_config_TEST_HEADER osconfig.h)
set(DCMTK_dcmdata_TEST_HEADER dctypes.h)
set(DCMTK_dcmimage_TEST_HEADER dicoimg.h)
set(DCMTK_dcmimgle_TEST_HEADER dcmimage.h)
set(DCMTK_dcmjpeg_TEST_HEADER djdecode.h)
set(DCMTK_dcmnet_TEST_HEADER assoc.h)
set(DCMTK_dcmpstat_TEST_HEADER dcmpstat.h)
set(DCMTK_dcmqrdb_TEST_HEADER dcmqrdba.h)
set(DCMTK_dcmsign_TEST_HEADER sicert.h)
set(DCMTK_dcmsr_TEST_HEADER dsrtree.h)
set(DCMTK_dcmtls_TEST_HEADER tlslayer.h)
set(DCMTK_ofstd_TEST_HEADER ofstdinc.h)
set(DCMTK_oflog_TEST_HEADER oflog.h)
set(DCMTK_dcmjpls_TEST_HEADER djlsutil.h)
set(DCMTK_INCLUDE_DIR_NAMES)
foreach(dir
config
dcmdata
dcmimage
dcmimgle
dcmjpeg
dcmjpls
dcmnet
dcmpstat
dcmqrdb
dcmsign
dcmsr
dcmtls
ofstd
oflog)
if(EXTDCMTK_SOURCE_DIR)
set(SOURCE_DIR_PATH
${EXTDCMTK_SOURCE_DIR}/${dir}/include/dcmtk/${dir})
endif()
find_path(DCMTK_${dir}_INCLUDE_DIR
${DCMTK_${dir}_TEST_HEADER}
PATHS
${DCMTK_DIR}/${dir}/include
${DCMTK_DIR}/${dir}
${DCMTK_DIR}/include/dcmtk/${dir}
${DCMTK_DIR}/${dir}/include/dcmtk/${dir}
${DCMTK_DIR}/include/${dir}
${SOURCE_DIR_PATH}
)
mark_as_advanced(DCMTK_${dir}_INCLUDE_DIR)
list(APPEND DCMTK_INCLUDE_DIR_NAMES DCMTK_${dir}_INCLUDE_DIR)
if(DCMTK_${dir}_INCLUDE_DIR)
# add the 'include' path so eg
#include "dcmtk/dcmimgle/dcmimage.h"
# works
get_filename_component(_include ${DCMTK_${dir}_INCLUDE_DIR} PATH)
get_filename_component(_include ${_include} PATH)
list(APPEND
DCMTK_INCLUDE_DIRS
${DCMTK_${dir}_INCLUDE_DIR}
${_include})
endif()
endforeach()
list(APPEND DCMTK_INCLUDE_DIRS ${DCMTK_DIR}/include)
if(WIN32)
list(APPEND DCMTK_LIBRARIES netapi32 wsock32)
endif()
if(DCMTK_ofstd_INCLUDE_DIR)
get_filename_component(DCMTK_dcmtk_INCLUDE_DIR
${DCMTK_ofstd_INCLUDE_DIR}
PATH
CACHE)
list(APPEND DCMTK_INCLUDE_DIRS ${DCMTK_dcmtk_INCLUDE_DIR})
mark_as_advanced(DCMTK_dcmtk_INCLUDE_DIR)
endif()
# Compatibility: This variable is deprecated
set(DCMTK_INCLUDE_DIR ${DCMTK_INCLUDE_DIRS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DCMTK
REQUIRED_VARS ${DCMTK_INCLUDE_DIR_NAMES} DCMTK_LIBRARIES
FAIL_MESSAGE "Please set DCMTK_DIR and re-run configure")
# Workaround bug in packaging of DCMTK 3.6.0 on Debian.
# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=637687
if(DCMTK_FOUND AND UNIX AND NOT APPLE)
include(${CMAKE_CURRENT_LIST_DIR}/CheckIncludeFiles.cmake)
set(CMAKE_REQUIRED_FLAGS )
set(CMAKE_REQUIRED_DEFINITIONS )
set(CMAKE_REQUIRED_INCLUDES ${DCMTK_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${DCMTK_LIBRARIES})
set(CMAKE_REQUIRED_QUIET ${DCMTK_FIND_QUIETLY})
check_include_files("dcmtk/config/osconfig.h;dcmtk/ofstd/ofstream.h" DCMTK_HAVE_CONFIG_H_OPTIONAL LANGUAGE CXX)
if(NOT DCMTK_HAVE_CONFIG_H_OPTIONAL)
set(DCMTK_DEFINITIONS "HAVE_CONFIG_H")
endif()
endif()
|