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):
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:
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 # ImageMagick_VERSION_STRING - the version of ImageMagick found
30 # ImageMagick_VERSION_STRING will not work for old versions like 5.2.3.
32 # There are also components for the following ImageMagick APIs:
38 # For these components the following variables are set:
40 # ImageMagick_FOUND - TRUE if all components are found.
41 # ImageMagick_INCLUDE_DIRS - Full paths to all include dirs.
42 # ImageMagick_LIBRARIES - Full paths to all libraries.
43 # ImageMagick_<component>_FOUND - TRUE if <component> is found.
44 # ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
45 # ImageMagick_<component>_LIBRARIES - Full path to <component> libraries.
48 # find_package(ImageMagick)
49 # find_package(ImageMagick COMPONENTS convert)
50 # find_package(ImageMagick COMPONENTS convert mogrify display)
51 # find_package(ImageMagick COMPONENTS Magick++)
52 # find_package(ImageMagick COMPONENTS Magick++ convert)
54 # Note that the standard FIND_PACKAGE features are supported
55 # (i.e., QUIET, REQUIRED, etc.).
57 #=============================================================================
58 # Copyright 2007-2009 Kitware, Inc.
59 # Copyright 2007-2008 Miguel A. Figueroa-Villanueva <miguelf at ieee dot org>
60 # Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
62 # Distributed under the OSI-approved BSD License (the "License");
63 # see accompanying file Copyright.txt for details.
65 # This software is distributed WITHOUT ANY WARRANTY; without even the
66 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
67 # See the License for more information.
68 #=============================================================================
69 # (To distribute this file outside of CMake, substitute the full
70 # License text for the above reference.)
72 #---------------------------------------------------------------------
74 #---------------------------------------------------------------------
75 function(FIND_IMAGEMAGICK_API component header)
76 set(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
78 find_path(ImageMagick_${component}_INCLUDE_DIR
81 ${ImageMagick_INCLUDE_DIRS}
82 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/include"
85 DOC "Path to the ImageMagick include dir."
87 find_library(ImageMagick_${component}_LIBRARY
90 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/lib"
91 DOC "Path to the ImageMagick Magick++ library."
94 if(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
95 set(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
97 list(APPEND ImageMagick_INCLUDE_DIRS
98 ${ImageMagick_${component}_INCLUDE_DIR}
100 list(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS)
101 set(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE)
103 list(APPEND ImageMagick_LIBRARIES
104 ${ImageMagick_${component}_LIBRARY}
106 set(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE)
110 function(FIND_IMAGEMAGICK_EXE component)
111 set(_IMAGEMAGICK_EXECUTABLE
112 ${ImageMagick_EXECUTABLE_DIR}/${component}${CMAKE_EXECUTABLE_SUFFIX})
113 if(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
114 set(ImageMagick_${component}_EXECUTABLE
115 ${_IMAGEMAGICK_EXECUTABLE}
118 set(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
120 set(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
124 #---------------------------------------------------------------------
126 #---------------------------------------------------------------------
127 # Try to find a ImageMagick installation binary path.
128 find_path(ImageMagick_EXECUTABLE_DIR
129 NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
131 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]"
132 DOC "Path to the ImageMagick binary directory."
135 find_path(ImageMagick_EXECUTABLE_DIR
136 NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
139 # Find each component. Search for all tools in same dir
140 # <ImageMagick_EXECUTABLE_DIR>; otherwise they should be found
141 # independently and not in a cohesive module such as this one.
142 unset(ImageMagick_REQUIRED_VARS)
143 unset(ImageMagick_DEFAULT_EXECUTABLES)
144 foreach(component ${ImageMagick_FIND_COMPONENTS}
145 # DEPRECATED: forced components for backward compatibility
146 convert mogrify import montage composite
148 if(component STREQUAL "Magick++")
149 FIND_IMAGEMAGICK_API(Magick++ Magick++.h
150 Magick++ CORE_RL_Magick++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8
152 list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_Magick++_LIBRARY)
153 elseif(component STREQUAL "MagickWand")
154 FIND_IMAGEMAGICK_API(MagickWand wand/MagickWand.h
155 Wand MagickWand CORE_RL_wand_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8
157 list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickWand_LIBRARY)
158 elseif(component STREQUAL "MagickCore")
159 FIND_IMAGEMAGICK_API(MagickCore magick/MagickCore.h
160 Magick MagickCore CORE_RL_magick_ MagickCore-6.Q16 MagickCore-Q16 MagickCore-6.Q8 MagickCore-Q8
162 list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickCore_LIBRARY)
164 if(ImageMagick_EXECUTABLE_DIR)
165 FIND_IMAGEMAGICK_EXE(${component})
168 if(ImageMagick_FIND_COMPONENTS)
169 list(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested)
170 if(is_requested GREATER -1)
171 list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_${component}_EXECUTABLE)
173 elseif(ImageMagick_${component}_EXECUTABLE)
174 # if no components were requested explicitly put all (default) executables
176 list(APPEND ImageMagick_DEFAULT_EXECUTABLES ImageMagick_${component}_EXECUTABLE)
181 if(NOT ImageMagick_FIND_COMPONENTS AND NOT ImageMagick_DEFAULT_EXECUTABLES)
182 # No components were requested, and none of the default components were
183 # found. Just insert mogrify into the list of the default components to
184 # find so FPHSA below has something to check
185 list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_mogrify_EXECUTABLE)
186 elseif(ImageMagick_DEFAULT_EXECUTABLES)
187 list(APPEND ImageMagick_REQUIRED_VARS ${ImageMagick_DEFAULT_EXECUTABLES})
190 set(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS})
191 set(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES})
193 if(ImageMagick_mogrify_EXECUTABLE)
194 execute_process(COMMAND ${ImageMagick_mogrify_EXECUTABLE} -version
195 OUTPUT_VARIABLE imagemagick_version
197 OUTPUT_STRIP_TRAILING_WHITESPACE)
198 if(imagemagick_version MATCHES "^Version: ImageMagick [0-9]")
199 string(REGEX REPLACE "^Version: ImageMagick ([-0-9\\.]+).*" "\\1" ImageMagick_VERSION_STRING "${imagemagick_version}")
201 unset(imagemagick_version)
204 #---------------------------------------------------------------------
205 # Standard Package Output
206 #---------------------------------------------------------------------
207 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
208 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ImageMagick
209 REQUIRED_VARS ${ImageMagick_REQUIRED_VARS}
210 VERSION_VAR ImageMagick_VERSION_STRING
212 # Maintain consistency with all other variables.
213 set(ImageMagick_FOUND ${IMAGEMAGICK_FOUND})
215 #---------------------------------------------------------------------
216 # DEPRECATED: Setting variables for backward compatibility.
217 #---------------------------------------------------------------------
218 set(IMAGEMAGICK_BINARY_PATH ${ImageMagick_EXECUTABLE_DIR}
219 CACHE PATH "Path to the ImageMagick binary directory.")
220 set(IMAGEMAGICK_CONVERT_EXECUTABLE ${ImageMagick_convert_EXECUTABLE}
221 CACHE FILEPATH "Path to ImageMagick's convert executable.")
222 set(IMAGEMAGICK_MOGRIFY_EXECUTABLE ${ImageMagick_mogrify_EXECUTABLE}
223 CACHE FILEPATH "Path to ImageMagick's mogrify executable.")
224 set(IMAGEMAGICK_IMPORT_EXECUTABLE ${ImageMagick_import_EXECUTABLE}
225 CACHE FILEPATH "Path to ImageMagick's import executable.")
226 set(IMAGEMAGICK_MONTAGE_EXECUTABLE ${ImageMagick_montage_EXECUTABLE}
227 CACHE FILEPATH "Path to ImageMagick's montage executable.")
228 set(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE}
229 CACHE FILEPATH "Path to ImageMagick's composite executable.")
231 IMAGEMAGICK_BINARY_PATH
232 IMAGEMAGICK_CONVERT_EXECUTABLE
233 IMAGEMAGICK_MOGRIFY_EXECUTABLE
234 IMAGEMAGICK_IMPORT_EXECUTABLE
235 IMAGEMAGICK_MONTAGE_EXECUTABLE
236 IMAGEMAGICK_COMPOSITE_EXECUTABLE