FindImageMagick.cmake 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindImageMagick
  5. ---------------
  6. Find ImageMagick binary suite.
  7. This module will search for a set of ImageMagick tools specified as
  8. components in the :command:`find_package` call. Typical components include,
  9. but are not limited to (future versions of ImageMagick might have
  10. additional components not listed here):
  11. ::
  12. animate
  13. compare
  14. composite
  15. conjure
  16. convert
  17. display
  18. identify
  19. import
  20. mogrify
  21. montage
  22. stream
  23. If no component is specified in the :command:`find_package` call, then it only
  24. searches for the ImageMagick executable directory. This code defines
  25. the following variables:
  26. ::
  27. ImageMagick_FOUND - TRUE if all components are found.
  28. ImageMagick_EXECUTABLE_DIR - Full path to executables directory.
  29. ImageMagick_<component>_FOUND - TRUE if <component> is found.
  30. ImageMagick_<component>_EXECUTABLE - Full path to <component> executable.
  31. ImageMagick_VERSION_STRING - the version of ImageMagick found
  32. (since CMake 2.8.8)
  33. ``ImageMagick_VERSION_STRING`` will not work for old versions like 5.2.3.
  34. There are also components for the following ImageMagick APIs:
  35. ::
  36. Magick++
  37. MagickWand
  38. MagickCore
  39. For these components the following variables are set:
  40. ::
  41. ImageMagick_FOUND - TRUE if all components are found.
  42. ImageMagick_INCLUDE_DIRS - Full paths to all include dirs.
  43. ImageMagick_LIBRARIES - Full paths to all libraries.
  44. ImageMagick_<component>_FOUND - TRUE if <component> is found.
  45. ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
  46. ImageMagick_<component>_LIBRARIES - Full path to <component> libraries.
  47. Example Usages:
  48. ::
  49. find_package(ImageMagick)
  50. find_package(ImageMagick COMPONENTS convert)
  51. find_package(ImageMagick COMPONENTS convert mogrify display)
  52. find_package(ImageMagick COMPONENTS Magick++)
  53. find_package(ImageMagick COMPONENTS Magick++ convert)
  54. Note that the standard :command:`find_package` features are supported (i.e.,
  55. ``QUIET``, ``REQUIRED``, etc.).
  56. #]=======================================================================]
  57. find_package(PkgConfig QUIET)
  58. #---------------------------------------------------------------------
  59. # Helper functions
  60. #---------------------------------------------------------------------
  61. function(FIND_IMAGEMAGICK_API component header)
  62. set(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
  63. pkg_check_modules(PC_${component} QUIET ${component})
  64. find_path(ImageMagick_${component}_INCLUDE_DIR
  65. NAMES ${header}
  66. HINTS
  67. ${PC_${component}_INCLUDEDIR}
  68. ${PC_${component}_INCLUDE_DIRS}
  69. PATHS
  70. ${ImageMagick_INCLUDE_DIRS}
  71. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/include"
  72. PATH_SUFFIXES
  73. ImageMagick ImageMagick-6 ImageMagick-7
  74. DOC "Path to the ImageMagick arch-independent include dir."
  75. NO_DEFAULT_PATH
  76. )
  77. find_path(ImageMagick_${component}_ARCH_INCLUDE_DIR
  78. NAMES magick/magick-baseconfig.h
  79. HINTS
  80. ${PC_${component}_INCLUDEDIR}
  81. ${PC_${component}_INCLUDE_DIRS}
  82. PATHS
  83. ${ImageMagick_INCLUDE_DIRS}
  84. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/include"
  85. PATH_SUFFIXES
  86. ImageMagick ImageMagick-6 ImageMagick-7
  87. DOC "Path to the ImageMagick arch-specific include dir."
  88. NO_DEFAULT_PATH
  89. )
  90. find_library(ImageMagick_${component}_LIBRARY
  91. NAMES ${ARGN}
  92. HINTS
  93. ${PC_${component}_LIBDIR}
  94. ${PC_${component}_LIB_DIRS}
  95. PATHS
  96. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/lib"
  97. DOC "Path to the ImageMagick Magick++ library."
  98. NO_DEFAULT_PATH
  99. )
  100. # old version have only indep dir
  101. if(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
  102. set(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
  103. # Construct per-component include directories.
  104. set(ImageMagick_${component}_INCLUDE_DIRS
  105. ${ImageMagick_${component}_INCLUDE_DIR}
  106. )
  107. if(ImageMagick_${component}_ARCH_INCLUDE_DIR)
  108. list(APPEND ImageMagick_${component}_INCLUDE_DIRS
  109. ${ImageMagick_${component}_ARCH_INCLUDE_DIR})
  110. endif()
  111. list(REMOVE_DUPLICATES ImageMagick_${component}_INCLUDE_DIRS)
  112. set(ImageMagick_${component}_INCLUDE_DIRS
  113. ${ImageMagick_${component}_INCLUDE_DIRS} PARENT_SCOPE)
  114. # Add the per-component include directories to the full include dirs.
  115. list(APPEND ImageMagick_INCLUDE_DIRS ${ImageMagick_${component}_INCLUDE_DIRS})
  116. list(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS)
  117. set(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE)
  118. list(APPEND ImageMagick_LIBRARIES
  119. ${ImageMagick_${component}_LIBRARY}
  120. )
  121. set(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE)
  122. endif()
  123. endfunction()
  124. function(FIND_IMAGEMAGICK_EXE component)
  125. set(_IMAGEMAGICK_EXECUTABLE
  126. ${ImageMagick_EXECUTABLE_DIR}/${component}${CMAKE_EXECUTABLE_SUFFIX})
  127. if(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
  128. set(ImageMagick_${component}_EXECUTABLE
  129. ${_IMAGEMAGICK_EXECUTABLE}
  130. PARENT_SCOPE
  131. )
  132. set(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
  133. else()
  134. set(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
  135. endif()
  136. endfunction()
  137. #---------------------------------------------------------------------
  138. # Start Actual Work
  139. #---------------------------------------------------------------------
  140. # Try to find a ImageMagick installation binary path.
  141. find_path(ImageMagick_EXECUTABLE_DIR
  142. NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
  143. PATHS
  144. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]"
  145. DOC "Path to the ImageMagick binary directory."
  146. NO_DEFAULT_PATH
  147. )
  148. find_path(ImageMagick_EXECUTABLE_DIR
  149. NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
  150. )
  151. # Find each component. Search for all tools in same dir
  152. # <ImageMagick_EXECUTABLE_DIR>; otherwise they should be found
  153. # independently and not in a cohesive module such as this one.
  154. unset(ImageMagick_REQUIRED_VARS)
  155. unset(ImageMagick_DEFAULT_EXECUTABLES)
  156. foreach(component ${ImageMagick_FIND_COMPONENTS}
  157. # DEPRECATED: forced components for backward compatibility
  158. convert mogrify import montage composite
  159. )
  160. if(component STREQUAL "Magick++")
  161. FIND_IMAGEMAGICK_API(Magick++ Magick++.h
  162. Magick++ CORE_RL_Magick++_
  163. Magick++-6 Magick++-7
  164. Magick++-Q8 Magick++-Q16 Magick++-Q16HDRI Magick++-Q8HDRI
  165. Magick++-6.Q64 Magick++-6.Q32 Magick++-6.Q64HDRI Magick++-6.Q32HDRI
  166. Magick++-6.Q16 Magick++-6.Q8 Magick++-6.Q16HDRI Magick++-6.Q8HDRI
  167. Magick++-7.Q64 Magick++-7.Q32 Magick++-7.Q64HDRI Magick++-7.Q32HDRI
  168. Magick++-7.Q16 Magick++-7.Q8 Magick++-7.Q16HDRI Magick++-7.Q8HDRI
  169. )
  170. list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_Magick++_LIBRARY)
  171. elseif(component STREQUAL "MagickWand")
  172. FIND_IMAGEMAGICK_API(MagickWand "wand/MagickWand.h;MagickWand/MagickWand.h"
  173. Wand MagickWand CORE_RL_wand_ CORE_RL_MagickWand_
  174. MagickWand-6 MagickWand-7
  175. MagickWand-Q16 MagickWand-Q8 MagickWand-Q16HDRI MagickWand-Q8HDRI
  176. MagickWand-6.Q64 MagickWand-6.Q32 MagickWand-6.Q64HDRI MagickWand-6.Q32HDRI
  177. MagickWand-6.Q16 MagickWand-6.Q8 MagickWand-6.Q16HDRI MagickWand-6.Q8HDRI
  178. MagickWand-7.Q64 MagickWand-7.Q32 MagickWand-7.Q64HDRI MagickWand-7.Q32HDRI
  179. MagickWand-7.Q16 MagickWand-7.Q8 MagickWand-7.Q16HDRI MagickWand-7.Q8HDRI
  180. )
  181. list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickWand_LIBRARY)
  182. elseif(component STREQUAL "MagickCore")
  183. FIND_IMAGEMAGICK_API(MagickCore "magick/MagickCore.h;MagickCore/MagickCore.h"
  184. Magick MagickCore CORE_RL_magick_ CORE_RL_MagickCore_
  185. MagickCore-6 MagickCore-7
  186. MagickCore-Q16 MagickCore-Q8 MagickCore-Q16HDRI MagickCore-Q8HDRI
  187. MagickCore-6.Q64 MagickCore-6.Q32 MagickCore-6.Q64HDRI MagickCore-6.Q32HDRI
  188. MagickCore-6.Q16 MagickCore-6.Q8 MagickCore-6.Q16HDRI MagickCore-6.Q8HDRI
  189. MagickCore-7.Q64 MagickCore-7.Q32 MagickCore-7.Q64HDRI MagickCore-7.Q32HDRI
  190. MagickCore-7.Q16 MagickCore-7.Q8 MagickCore-7.Q16HDRI MagickCore-7.Q8HDRI
  191. )
  192. list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickCore_LIBRARY)
  193. else()
  194. if(ImageMagick_EXECUTABLE_DIR)
  195. FIND_IMAGEMAGICK_EXE(${component})
  196. endif()
  197. if(ImageMagick_FIND_COMPONENTS)
  198. list(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested)
  199. if(is_requested GREATER -1)
  200. list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_${component}_EXECUTABLE)
  201. endif()
  202. elseif(ImageMagick_${component}_EXECUTABLE)
  203. # if no components were requested explicitly put all (default) executables
  204. # in the list
  205. list(APPEND ImageMagick_DEFAULT_EXECUTABLES ImageMagick_${component}_EXECUTABLE)
  206. endif()
  207. endif()
  208. endforeach()
  209. if(NOT ImageMagick_FIND_COMPONENTS AND NOT ImageMagick_DEFAULT_EXECUTABLES)
  210. # No components were requested, and none of the default components were
  211. # found. Just insert mogrify into the list of the default components to
  212. # find so FPHSA below has something to check
  213. list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_mogrify_EXECUTABLE)
  214. elseif(ImageMagick_DEFAULT_EXECUTABLES)
  215. list(APPEND ImageMagick_REQUIRED_VARS ${ImageMagick_DEFAULT_EXECUTABLES})
  216. endif()
  217. set(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS})
  218. set(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES})
  219. if(ImageMagick_mogrify_EXECUTABLE)
  220. execute_process(COMMAND ${ImageMagick_mogrify_EXECUTABLE} -version
  221. OUTPUT_VARIABLE imagemagick_version
  222. ERROR_QUIET
  223. OUTPUT_STRIP_TRAILING_WHITESPACE)
  224. if(imagemagick_version MATCHES "^Version: ImageMagick ([-0-9\\.]+)")
  225. set(ImageMagick_VERSION_STRING "${CMAKE_MATCH_1}")
  226. endif()
  227. unset(imagemagick_version)
  228. endif()
  229. #---------------------------------------------------------------------
  230. # Standard Package Output
  231. #---------------------------------------------------------------------
  232. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  233. FIND_PACKAGE_HANDLE_STANDARD_ARGS(ImageMagick
  234. REQUIRED_VARS ${ImageMagick_REQUIRED_VARS}
  235. VERSION_VAR ImageMagick_VERSION_STRING
  236. )
  237. # Maintain consistency with all other variables.
  238. set(ImageMagick_FOUND ${IMAGEMAGICK_FOUND})
  239. #---------------------------------------------------------------------
  240. # DEPRECATED: Setting variables for backward compatibility.
  241. #---------------------------------------------------------------------
  242. set(IMAGEMAGICK_BINARY_PATH ${ImageMagick_EXECUTABLE_DIR}
  243. CACHE PATH "Path to the ImageMagick binary directory.")
  244. set(IMAGEMAGICK_CONVERT_EXECUTABLE ${ImageMagick_convert_EXECUTABLE}
  245. CACHE FILEPATH "Path to ImageMagick's convert executable.")
  246. set(IMAGEMAGICK_MOGRIFY_EXECUTABLE ${ImageMagick_mogrify_EXECUTABLE}
  247. CACHE FILEPATH "Path to ImageMagick's mogrify executable.")
  248. set(IMAGEMAGICK_IMPORT_EXECUTABLE ${ImageMagick_import_EXECUTABLE}
  249. CACHE FILEPATH "Path to ImageMagick's import executable.")
  250. set(IMAGEMAGICK_MONTAGE_EXECUTABLE ${ImageMagick_montage_EXECUTABLE}
  251. CACHE FILEPATH "Path to ImageMagick's montage executable.")
  252. set(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE}
  253. CACHE FILEPATH "Path to ImageMagick's composite executable.")
  254. mark_as_advanced(
  255. IMAGEMAGICK_BINARY_PATH
  256. IMAGEMAGICK_CONVERT_EXECUTABLE
  257. IMAGEMAGICK_MOGRIFY_EXECUTABLE
  258. IMAGEMAGICK_IMPORT_EXECUTABLE
  259. IMAGEMAGICK_MONTAGE_EXECUTABLE
  260. IMAGEMAGICK_COMPOSITE_EXECUTABLE
  261. )