FindImageMagick.cmake 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # - Find the ImageMagick binary suite.
  2. # This module will search for a set of ImageMagick tools specified
  3. # as components in the FIND_PACKAGE call. Typical components include,
  4. # but are not limited to (future versions of ImageMagick might have
  5. # additional components not listed here):
  6. #
  7. # animate
  8. # compare
  9. # composite
  10. # conjure
  11. # convert
  12. # display
  13. # identify
  14. # import
  15. # mogrify
  16. # montage
  17. # stream
  18. #
  19. # If no component is specified in the FIND_PACKAGE call, then it only
  20. # searches for the ImageMagick executable directory. This code defines
  21. # the following variables:
  22. #
  23. # ImageMagick_FOUND - TRUE if all components are found.
  24. # ImageMagick_EXECUTABLE_DIR - Full path to executables directory.
  25. # ImageMagick_<component>_FOUND - TRUE if <component> is found.
  26. # ImageMagick_<component>_EXECUTABLE - Full path to <component> executable.
  27. #
  28. # There are also components for the following ImageMagick APIs:
  29. #
  30. # Magick++
  31. # MagickWand
  32. # MagickCore
  33. #
  34. # For these components the following variables are set:
  35. #
  36. # ImageMagick_FOUND - TRUE if all components are found.
  37. # ImageMagick_INCLUDE_DIRS - Full paths to all include dirs.
  38. # ImageMagick_LIBRARIES - Full paths to all libraries.
  39. # ImageMagick_<component>_FOUND - TRUE if <component> is found.
  40. # ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
  41. # ImageMagick_<component>_LIBRARIES - Full path to <component> libraries.
  42. #
  43. # Example Usages:
  44. # FIND_PACKAGE(ImageMagick)
  45. # FIND_PACKAGE(ImageMagick COMPONENTS convert)
  46. # FIND_PACKAGE(ImageMagick COMPONENTS convert mogrify display)
  47. # FIND_PACKAGE(ImageMagick COMPONENTS Magick++)
  48. # FIND_PACKAGE(ImageMagick COMPONENTS Magick++ convert)
  49. #
  50. # Note that the standard FIND_PACKAGE features are supported
  51. # (i.e., QUIET, REQUIRED, etc.).
  52. #=============================================================================
  53. # Copyright 2007-2009 Kitware, Inc.
  54. # Copyright 2007-2008 Miguel A. Figueroa-Villanueva <miguelf at ieee dot org>
  55. #
  56. # Distributed under the OSI-approved BSD License (the "License");
  57. # see accompanying file Copyright.txt for details.
  58. #
  59. # This software is distributed WITHOUT ANY WARRANTY; without even the
  60. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  61. # See the License for more information.
  62. #=============================================================================
  63. # (To distributed this file outside of CMake, substitute the full
  64. # License text for the above reference.)
  65. #---------------------------------------------------------------------
  66. # Helper functions
  67. #---------------------------------------------------------------------
  68. FUNCTION(FIND_IMAGEMAGICK_API component header)
  69. SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
  70. FIND_PATH(ImageMagick_${component}_INCLUDE_DIR
  71. NAMES ${header}
  72. PATHS
  73. ${ImageMagick_INCLUDE_DIRS}
  74. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/include"
  75. PATH_SUFFIXES
  76. ImageMagick
  77. DOC "Path to the ImageMagick include dir."
  78. )
  79. FIND_LIBRARY(ImageMagick_${component}_LIBRARY
  80. NAMES ${ARGN}
  81. PATHS
  82. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/lib"
  83. DOC "Path to the ImageMagick Magick++ library."
  84. )
  85. IF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
  86. SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
  87. LIST(APPEND ImageMagick_INCLUDE_DIRS
  88. ${ImageMagick_${component}_INCLUDE_DIR}
  89. )
  90. LIST(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS)
  91. SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE)
  92. LIST(APPEND ImageMagick_LIBRARIES
  93. ${ImageMagick_${component}_LIBRARY}
  94. )
  95. SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE)
  96. ENDIF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
  97. ENDFUNCTION(FIND_IMAGEMAGICK_API)
  98. FUNCTION(FIND_IMAGEMAGICK_EXE component)
  99. SET(_IMAGEMAGICK_EXECUTABLE
  100. ${ImageMagick_EXECUTABLE_DIR}/${component}${CMAKE_EXECUTABLE_SUFFIX})
  101. IF(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
  102. SET(ImageMagick_${component}_EXECUTABLE
  103. ${_IMAGEMAGICK_EXECUTABLE}
  104. PARENT_SCOPE
  105. )
  106. SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
  107. ELSE(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
  108. SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
  109. ENDIF(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
  110. ENDFUNCTION(FIND_IMAGEMAGICK_EXE)
  111. #---------------------------------------------------------------------
  112. # Start Actual Work
  113. #---------------------------------------------------------------------
  114. # Try to find a ImageMagick installation binary path.
  115. FIND_PATH(ImageMagick_EXECUTABLE_DIR
  116. NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
  117. PATHS
  118. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]"
  119. DOC "Path to the ImageMagick binary directory."
  120. NO_DEFAULT_PATH
  121. )
  122. FIND_PATH(ImageMagick_EXECUTABLE_DIR
  123. NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
  124. )
  125. # Find each component. Search for all tools in same dir
  126. # <ImageMagick_EXECUTABLE_DIR>; otherwise they should be found
  127. # independently and not in a cohesive module such as this one.
  128. SET(ImageMagick_FOUND TRUE)
  129. FOREACH(component ${ImageMagick_FIND_COMPONENTS}
  130. # DEPRECATED: forced components for backward compatibility
  131. convert mogrify import montage composite
  132. )
  133. IF(component STREQUAL "Magick++")
  134. FIND_IMAGEMAGICK_API(Magick++ Magick++.h
  135. Magick++ CORE_RL_Magick++_
  136. )
  137. ELSEIF(component STREQUAL "MagickWand")
  138. FIND_IMAGEMAGICK_API(MagickWand wand/MagickWand.h
  139. Wand MagickWand CORE_RL_wand_
  140. )
  141. ELSEIF(component STREQUAL "MagickCore")
  142. FIND_IMAGEMAGICK_API(MagickCore magick/MagickCore.h
  143. Magick MagickCore CORE_RL_magick_
  144. )
  145. ELSE(component STREQUAL "Magick++")
  146. IF(ImageMagick_EXECUTABLE_DIR)
  147. FIND_IMAGEMAGICK_EXE(${component})
  148. ENDIF(ImageMagick_EXECUTABLE_DIR)
  149. ENDIF(component STREQUAL "Magick++")
  150. IF(NOT ImageMagick_${component}_FOUND)
  151. LIST(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested)
  152. IF(is_requested GREATER -1)
  153. SET(ImageMagick_FOUND FALSE)
  154. ENDIF(is_requested GREATER -1)
  155. ENDIF(NOT ImageMagick_${component}_FOUND)
  156. ENDFOREACH(component)
  157. SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS})
  158. SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES})
  159. #---------------------------------------------------------------------
  160. # Standard Package Output
  161. #---------------------------------------------------------------------
  162. INCLUDE(FindPackageHandleStandardArgs)
  163. FIND_PACKAGE_HANDLE_STANDARD_ARGS(
  164. ImageMagick DEFAULT_MSG ImageMagick_FOUND
  165. )
  166. # Maintain consistency with all other variables.
  167. SET(ImageMagick_FOUND ${IMAGEMAGICK_FOUND})
  168. #---------------------------------------------------------------------
  169. # DEPRECATED: Setting variables for backward compatibility.
  170. #---------------------------------------------------------------------
  171. SET(IMAGEMAGICK_BINARY_PATH ${ImageMagick_EXECUTABLE_DIR}
  172. CACHE PATH "Path to the ImageMagick binary directory.")
  173. SET(IMAGEMAGICK_CONVERT_EXECUTABLE ${ImageMagick_convert_EXECUTABLE}
  174. CACHE FILEPATH "Path to ImageMagick's convert executable.")
  175. SET(IMAGEMAGICK_MOGRIFY_EXECUTABLE ${ImageMagick_mogrify_EXECUTABLE}
  176. CACHE FILEPATH "Path to ImageMagick's mogrify executable.")
  177. SET(IMAGEMAGICK_IMPORT_EXECUTABLE ${ImageMagick_import_EXECUTABLE}
  178. CACHE FILEPATH "Path to ImageMagick's import executable.")
  179. SET(IMAGEMAGICK_MONTAGE_EXECUTABLE ${ImageMagick_montage_EXECUTABLE}
  180. CACHE FILEPATH "Path to ImageMagick's montage executable.")
  181. SET(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE}
  182. CACHE FILEPATH "Path to ImageMagick's composite executable.")
  183. MARK_AS_ADVANCED(
  184. IMAGEMAGICK_BINARY_PATH
  185. IMAGEMAGICK_CONVERT_EXECUTABLE
  186. IMAGEMAGICK_MOGRIFY_EXECUTABLE
  187. IMAGEMAGICK_IMPORT_EXECUTABLE
  188. IMAGEMAGICK_MONTAGE_EXECUTABLE
  189. IMAGEMAGICK_COMPOSITE_EXECUTABLE
  190. )