FindImageMagick.cmake 11 KB

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