CMake/Modules/FindDCMTK.cmake

158 lines
4.1 KiB
CMake
Raw Normal View History

#.rst:
# FindDCMTK
# ---------
#
# find DCMTK libraries and applications
# DCMTK_INCLUDE_DIRS - Directories to include to use DCMTK
# DCMTK_LIBRARIES - Files to link against to use DCMTK
# DCMTK_FOUND - If false, don't try to use DCMTK
# DCMTK_DIR - (optional) Source directory for DCMTK
#
# DCMTK_DIR can be used to make it simpler to find the various include
# directories and compiled libraries if you've just compiled it in the
# source tree. Just set it to the root of the tree where you extracted
# the source (default to /usr/include/dcmtk/)
#=============================================================================
# Copyright 2004-2009 Kitware, Inc.
# Copyright 2009-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
# Copyright 2010 Thomas Sondergaard <ts@medical-insight.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
#
# Written for VXL by Amitha Perera.
# Upgraded for GDCM by Mathieu Malaterre.
# Modified for EasyViz by Thomas Sondergaard.
#
if(NOT DCMTK_FOUND AND NOT DCMTK_DIR)
set(DCMTK_DIR
"/usr/include/dcmtk/"
CACHE
PATH
"Root of DCMTK source tree (optional).")
mark_as_advanced(DCMTK_DIR)
endif()
foreach(lib
dcmdata
dcmimage
dcmimgle
dcmjpeg
dcmnet
dcmpstat
dcmqrdb
dcmsign
dcmsr
dcmtls
ijg12
ijg16
ijg8
ofstd)
find_library(DCMTK_${lib}_LIBRARY
${lib}
PATHS
${DCMTK_DIR}/${lib}/libsrc
${DCMTK_DIR}/${lib}/libsrc/Release
${DCMTK_DIR}/${lib}/libsrc/Debug
${DCMTK_DIR}/${lib}/Release
${DCMTK_DIR}/${lib}/Debug
${DCMTK_DIR}/lib)
mark_as_advanced(DCMTK_${lib}_LIBRARY)
if(DCMTK_${lib}_LIBRARY)
list(APPEND DCMTK_LIBRARIES ${DCMTK_${lib}_LIBRARY})
endif()
endforeach()
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)
foreach(dir
config
dcmdata
dcmimage
dcmimgle
dcmjpeg
dcmnet
dcmpstat
dcmqrdb
dcmsign
dcmsr
dcmtls
ofstd)
find_path(DCMTK_${dir}_INCLUDE_DIR
${DCMTK_${dir}_TEST_HEADER}
PATHS
${DCMTK_DIR}/${dir}/include
${DCMTK_DIR}/${dir}
${DCMTK_DIR}/include/${dir}
${DCMTK_DIR}/include/dcmtk/${dir}
${DCMTK_DIR}/${dir}/include/dcmtk/${dir}
)
mark_as_advanced(DCMTK_${dir}_INCLUDE_DIR)
if(DCMTK_${dir}_INCLUDE_DIR)
list(APPEND
DCMTK_INCLUDE_DIRS
${DCMTK_${dir}_INCLUDE_DIR})
endif()
endforeach()
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()
Modules: Include builtin FindPackageHandleStandardArgs directly The FindPackageHandleStandardArgs module was originally created outside of CMake. It was added for CMake 2.6.0 by commit e118a627 (add a macro FIND_PACKAGE_HANDLE_STANDARD_ARGS..., 2007-07-18). However, it also proliferated into a number of other projects that at the time required only CMake 2.4 and thus could not depend on CMake to provide the module. CMake's own find modules started using the module in commit b5f656e0 (use the new FIND_PACKAGE_HANDLE_STANDARD_ARGS in some of the FindXXX modules..., 2007-07-18). Then commit d358cf5c (add 2nd, more powerful mode to find_package_handle_standard_args, 2010-07-29) added a new feature to the interface of the module that was fully optional and backward compatible with all existing users of the module. Later commit 5f183caa (FindZLIB: use the FPHSA version mode, 2010-08-04) and others shortly thereafter started using the new interface in CMake's own find modules. This change was also backward compatible because it was only an implementation detail within each module. Unforutnately these changes introduced a problem for projects that still have an old copy of FindPackageHandleStandardArgs in CMAKE_MODULE_PATH. When any such project uses one of CMake's builtin find modules the line include(FindPackageHandleStandardArgs) loads the copy from the project which does not have the new interface! Then the including find module tries to use the new interface with the old module and fails. Whether this breakage can be considered a backward incompatible change in CMake is debatable. The situation is analagous to copying a standard library header from one version of a compiler into a project and then observing problems when the next version of the compiler reports errors in its other headers that depend on its new version of the original header. Nevertheless it is a change to CMake that causes problems for projects that worked with previous versions. This problem was discovered during the 2.8.3 release candidate cycle. It is an instance of a more general problem with projects that provide their own versions of CMake modules when other CMake modules depend on them. At the time we resolved this instance of the problem with commit b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake everywhere, 2010-09-28) for the 2.8.3 release. In order to address the more general problem we introduced policy CMP0017 in commit db44848f (Prefer files from CMAKE_ROOT when including from CMAKE_ROOT, 2010-11-17). That change was followed by commit ce28737c (Remove usage of CMAKE_CURRENT_LIST_DIR now that we have CMP0017, 2010-12-20) which reverted the original workaround in favor of using the policy. However, existing project releases do not set the policy behavior to NEW and therefore still exhibit the problem. We introduced in commit a364daf1 (Allow users to specify defaults for unset policies, 2011-01-03) an option for users to build existing projects by adding -DCMAKE_POLICY_DEFAULT_CMP0017=NEW to the command line. Unfortunately this solution still does not allow such projects to build out of the box, and there is no good way to suggest the use of the new option. The only remaining solution to keep existing projects that exhibit this problem building is to restore the change originally made in commit b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake everywhere, 2010-09-28). This also avoids policy CMP0017 warnings for this particular instance of the problem the policy addresses.
2011-01-20 18:56:49 +03:00
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(DCMTK DEFAULT_MSG
DCMTK_config_INCLUDE_DIR
DCMTK_ofstd_INCLUDE_DIR
DCMTK_ofstd_LIBRARY
DCMTK_dcmdata_INCLUDE_DIR
DCMTK_dcmdata_LIBRARY
DCMTK_dcmimgle_INCLUDE_DIR
DCMTK_dcmimgle_LIBRARY)
# Compatibility: This variable is deprecated
set(DCMTK_INCLUDE_DIR ${DCMTK_INCLUDE_DIRS})
foreach(executable dcmdump dcmdjpeg dcmdrle)
string(TOUPPER ${executable} EXECUTABLE)
find_program(DCMTK_${EXECUTABLE}_EXECUTABLE ${executable} ${DCMTK_DIR}/bin)
mark_as_advanced(DCMTK_${EXECUTABLE}_EXECUTABLE)
endforeach()