Imported Upstream version 2.8.11.2
[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()
108 endfunction()
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()
120     set(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
121   endif()
122 endfunction()
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++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8
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_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8
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_ MagickCore-6.Q16 MagickCore-Q16 MagickCore-6.Q8 MagickCore-Q8
161       )
162     list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickCore_LIBRARY)
163   else()
164     if(ImageMagick_EXECUTABLE_DIR)
165       FIND_IMAGEMAGICK_EXE(${component})
166     endif()
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()
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()
178   endif()
179 endforeach()
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()
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   )