Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Modules / FindImageMagick.cmake
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 #  ImageMagick_VERSION_STRING         - the version of ImageMagick found
28 #                                       (since CMake 2.8.8)
29 #
30 # ImageMagick_VERSION_STRING will not work for old versions like 5.2.3.
31 #
32 # There are also components for the following ImageMagick APIs:
33 #
34 #  Magick++
35 #  MagickWand
36 #  MagickCore
37 #
38 # For these components the following variables are set:
39 #
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.
46 #
47 # Example Usages:
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)
53 #
54 # Note that the standard FIND_PACKAGE features are supported
55 # (i.e., QUIET, REQUIRED, etc.).
56
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>
61 #
62 # Distributed under the OSI-approved BSD License (the "License");
63 # see accompanying file Copyright.txt for details.
64 #
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.)
71
72 #---------------------------------------------------------------------
73 # Helper functions
74 #---------------------------------------------------------------------
75 FUNCTION(FIND_IMAGEMAGICK_API component header)
76   SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
77
78   FIND_PATH(ImageMagick_${component}_INCLUDE_DIR
79     NAMES ${header}
80     PATHS
81       ${ImageMagick_INCLUDE_DIRS}
82       "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/include"
83     PATH_SUFFIXES
84       ImageMagick
85     DOC "Path to the ImageMagick include dir."
86     )
87   FIND_LIBRARY(ImageMagick_${component}_LIBRARY
88     NAMES ${ARGN}
89     PATHS
90       "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/lib"
91     DOC "Path to the ImageMagick Magick++ library."
92     )
93
94   IF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
95     SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
96
97     LIST(APPEND ImageMagick_INCLUDE_DIRS
98       ${ImageMagick_${component}_INCLUDE_DIR}
99       )
100     LIST(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS)
101     SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE)
102
103     LIST(APPEND ImageMagick_LIBRARIES
104       ${ImageMagick_${component}_LIBRARY}
105       )
106     SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE)
107   ENDIF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
108 ENDFUNCTION(FIND_IMAGEMAGICK_API)
109
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}
116        PARENT_SCOPE
117        )
118     SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
119   ELSE(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
120     SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
121   ENDIF(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
122 ENDFUNCTION(FIND_IMAGEMAGICK_EXE)
123
124 #---------------------------------------------------------------------
125 # Start Actual Work
126 #---------------------------------------------------------------------
127 # Try to find a ImageMagick installation binary path.
128 FIND_PATH(ImageMagick_EXECUTABLE_DIR
129   NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
130   PATHS
131     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]"
132   DOC "Path to the ImageMagick binary directory."
133   NO_DEFAULT_PATH
134   )
135 FIND_PATH(ImageMagick_EXECUTABLE_DIR
136   NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
137   )
138
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
147     )
148   IF(component STREQUAL "Magick++")
149     FIND_IMAGEMAGICK_API(Magick++ Magick++.h
150       Magick++ CORE_RL_Magick++_
151       )
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_
156       )
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_
161       )
162     LIST(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickCore_LIBRARY)
163   ELSE(component STREQUAL "Magick++")
164     IF(ImageMagick_EXECUTABLE_DIR)
165       FIND_IMAGEMAGICK_EXE(${component})
166     ENDIF(ImageMagick_EXECUTABLE_DIR)
167
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)
172       ENDIF(is_requested GREATER -1)
173     ELSEIF(ImageMagick_${component}_EXECUTABLE)
174       # if no components were requested explicitly put all (default) executables
175       # in the list
176       LIST(APPEND ImageMagick_DEFAULT_EXECUTABLES ImageMagick_${component}_EXECUTABLE)
177     ENDIF(ImageMagick_FIND_COMPONENTS)
178   ENDIF(component STREQUAL "Magick++")
179 ENDFOREACH(component)
180
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})
188 ENDIF()
189
190 SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS})
191 SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES})
192
193 IF(ImageMagick_mogrify_EXECUTABLE)
194   EXECUTE_PROCESS(COMMAND ${ImageMagick_mogrify_EXECUTABLE} -version
195                   OUTPUT_VARIABLE imagemagick_version
196                   ERROR_QUIET
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}")
200   ENDIF()
201   UNSET(imagemagick_version)
202 ENDIF(ImageMagick_mogrify_EXECUTABLE)
203
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
211   )
212 # Maintain consistency with all other variables.
213 SET(ImageMagick_FOUND ${IMAGEMAGICK_FOUND})
214
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.")
230 MARK_AS_ADVANCED(
231   IMAGEMAGICK_BINARY_PATH
232   IMAGEMAGICK_CONVERT_EXECUTABLE
233   IMAGEMAGICK_MOGRIFY_EXECUTABLE
234   IMAGEMAGICK_IMPORT_EXECUTABLE
235   IMAGEMAGICK_MONTAGE_EXECUTABLE
236   IMAGEMAGICK_COMPOSITE_EXECUTABLE
237   )