FindDCMTK.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # adapted version of FindDCMTK, better suited for super-builds
  2. # - find DCMTK libraries and applications
  3. #
  4. # DCMTK_INCLUDE_DIRS - Directories to include to use DCMTK
  5. # DCMTK_LIBRARIES - Files to link against to use DCMTK
  6. # DCMTK_FOUND - If false, don't try to use DCMTK
  7. # DCMTK_DIR - (optional) Source directory for DCMTK
  8. #
  9. # DCMTK_DIR can be used to make it simpler to find the various include
  10. # directories and compiled libraries if you've just compiled it in the
  11. # source tree. Just set it to the root of the tree where you extracted
  12. # the source (default to /usr/include/dcmtk/)
  13. #=============================================================================
  14. # Copyright 2004-2009 Kitware, Inc.
  15. # Copyright 2009-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
  16. # Copyright 2010 Thomas Sondergaard <ts@medical-insight.com>
  17. #
  18. # Distributed under the OSI-approved BSD License (the "License");
  19. # see accompanying file Copyright.txt for details.
  20. #
  21. # This software is distributed WITHOUT ANY WARRANTY; without even the
  22. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  23. # See the License for more information.
  24. #=============================================================================
  25. # (To distributed this file outside of CMake, substitute the full
  26. # License text for the above reference.)
  27. #
  28. # Written for VXL by Amitha Perera.
  29. # Upgraded for GDCM by Mathieu Malaterre.
  30. # Modified for EasyViz by Thomas Sondergaard.
  31. #
  32. # prefer DCMTK_DIR over default system paths like /usr/lib
  33. set(CMAKE_PREFIX_PATH ${DCMTK_DIR}/lib ${CMAKE_PREFIX_PATH}) # this is given to FIND_LIBRARY or FIND_PATH
  34. if(NOT DCMTK_FOUND AND NOT DCMTK_DIR)
  35. set(DCMTK_DIR
  36. "/usr/include/dcmtk/"
  37. CACHE
  38. PATH
  39. "Root of DCMTK source tree (optional).")
  40. mark_as_advanced(DCMTK_DIR)
  41. endif()
  42. # Find all libraries, store debug and release separately
  43. foreach(lib
  44. dcmpstat
  45. dcmsr
  46. dcmsign
  47. dcmtls
  48. dcmqrdb
  49. dcmnet
  50. dcmjpeg
  51. dcmimage
  52. dcmimgle
  53. dcmdata
  54. oflog
  55. ofstd
  56. ijg12
  57. ijg16
  58. ijg8
  59. )
  60. # Find Release libraries
  61. find_library(DCMTK_${lib}_LIBRARY_RELEASE
  62. ${lib}
  63. PATHS
  64. ${DCMTK_DIR}/${lib}/libsrc
  65. ${DCMTK_DIR}/${lib}/libsrc/Release
  66. ${DCMTK_DIR}/${lib}/Release
  67. ${DCMTK_DIR}/lib
  68. ${DCMTK_DIR}/lib/Release
  69. ${DCMTK_DIR}/dcmjpeg/lib${lib}/Release
  70. NO_DEFAULT_PATH
  71. )
  72. # Find Debug libraries
  73. find_library(DCMTK_${lib}_LIBRARY_DEBUG
  74. ${lib}
  75. PATHS
  76. ${DCMTK_DIR}/${lib}/libsrc
  77. ${DCMTK_DIR}/${lib}/libsrc/Debug
  78. ${DCMTK_DIR}/${lib}/Debug
  79. ${DCMTK_DIR}/lib
  80. ${DCMTK_DIR}/lib/Debug
  81. ${DCMTK_DIR}/dcmjpeg/lib${lib}/Debug
  82. NO_DEFAULT_PATH
  83. )
  84. mark_as_advanced(DCMTK_${lib}_LIBRARY_RELEASE)
  85. mark_as_advanced(DCMTK_${lib}_LIBRARY_DEBUG)
  86. # Add libraries to variable according to build type
  87. if(DCMTK_${lib}_LIBRARY_RELEASE)
  88. list(APPEND DCMTK_LIBRARIES optimized ${DCMTK_${lib}_LIBRARY_RELEASE})
  89. endif()
  90. if(DCMTK_${lib}_LIBRARY_DEBUG)
  91. list(APPEND DCMTK_LIBRARIES debug ${DCMTK_${lib}_LIBRARY_DEBUG})
  92. endif()
  93. endforeach()
  94. set(CMAKE_THREAD_LIBS_INIT)
  95. if(DCMTK_oflog_LIBRARY_RELEASE OR DCMTK_oflog_LIBRARY_DEBUG)
  96. # Hack - Not having a DCMTKConfig.cmake file to read the settings from, we will attempt to
  97. # find the library in all cases.
  98. # Ideally, pthread library should be discovered only if DCMTK_WITH_THREADS is enabled.
  99. set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  100. find_package(Threads)
  101. endif()
  102. if(CMAKE_THREAD_LIBS_INIT)
  103. list(APPEND DCMTK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  104. endif()
  105. set(DCMTK_config_TEST_HEADER osconfig.h)
  106. set(DCMTK_dcmdata_TEST_HEADER dctypes.h)
  107. set(DCMTK_dcmimage_TEST_HEADER dicoimg.h)
  108. set(DCMTK_dcmimgle_TEST_HEADER dcmimage.h)
  109. set(DCMTK_dcmjpeg_TEST_HEADER djdecode.h)
  110. set(DCMTK_dcmnet_TEST_HEADER assoc.h)
  111. set(DCMTK_dcmpstat_TEST_HEADER dcmpstat.h)
  112. set(DCMTK_dcmqrdb_TEST_HEADER dcmqrdba.h)
  113. set(DCMTK_dcmsign_TEST_HEADER sicert.h)
  114. set(DCMTK_dcmsr_TEST_HEADER dsrtree.h)
  115. set(DCMTK_dcmtls_TEST_HEADER tlslayer.h)
  116. set(DCMTK_ofstd_TEST_HEADER ofstdinc.h)
  117. foreach(dir
  118. config
  119. dcmdata
  120. dcmimage
  121. dcmimgle
  122. dcmjpeg
  123. dcmnet
  124. dcmpstat
  125. dcmqrdb
  126. dcmsign
  127. dcmsr
  128. dcmtls
  129. ofstd)
  130. find_path(DCMTK_${dir}_INCLUDE_DIR
  131. ${DCMTK_${dir}_TEST_HEADER}
  132. PATHS
  133. ${DCMTK_DIR}/${dir}/include
  134. ${DCMTK_DIR}/${dir}
  135. ${DCMTK_DIR}/include/dcmtk/${dir}
  136. ${DCMTK_DIR}/include/${dir})
  137. mark_as_advanced(DCMTK_${dir}_INCLUDE_DIR)
  138. #message("** DCMTKs ${dir} found at ${DCMTK_${dir}_INCLUDE_DIR}")
  139. if(DCMTK_${dir}_INCLUDE_DIR)
  140. list(APPEND
  141. DCMTK_INCLUDE_DIRS
  142. ${DCMTK_${dir}_INCLUDE_DIR})
  143. endif()
  144. endforeach()
  145. list(APPEND DCMTK_INCLUDE_DIRS ${DCMTK_DIR}/include)
  146. if(WIN32)
  147. list(APPEND DCMTK_LIBRARIES netapi32 wsock32)
  148. endif()
  149. if(DCMTK_ofstd_INCLUDE_DIR)
  150. get_filename_component(DCMTK_dcmtk_INCLUDE_DIR
  151. ${DCMTK_ofstd_INCLUDE_DIR}
  152. PATH
  153. CACHE)
  154. list(APPEND DCMTK_INCLUDE_DIRS ${DCMTK_dcmtk_INCLUDE_DIR})
  155. mark_as_advanced(DCMTK_dcmtk_INCLUDE_DIR)
  156. endif()
  157. # Compatibility: This variable is deprecated
  158. set(DCMTK_INCLUDE_DIR ${DCMTK_INCLUDE_DIRS})