blob: ccf0a012c3a418b38afec2b6d7b92b11f198a45c [file] [log] [blame]
Mark Youngb5ed9852016-01-25 16:02:08 -07001# - 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
Mark Young93ecb1d2016-01-13 13:47:16 -07005# additional components not listed here):
6#
Mark Youngb5ed9852016-01-25 16:02:08 -07007# animate
8# compare
9# composite
10# conjure
11# convert
12# display
13# identify
14# import
15# mogrify
16# montage
17# stream
Mark Young93ecb1d2016-01-13 13:47:16 -070018#
19# If no component is specified in the FIND_PACKAGE call, then it only
Mark Youngb5ed9852016-01-25 16:02:08 -070020# searches for the ImageMagick executable directory. This code defines
Mark Young93ecb1d2016-01-13 13:47:16 -070021# the following variables:
22#
Mark Youngb5ed9852016-01-25 16:02:08 -070023# 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.
Mark Young93ecb1d2016-01-13 13:47:16 -070027#
28# There are also components for the following ImageMagick APIs:
29#
Mark Youngb5ed9852016-01-25 16:02:08 -070030# Magick++
31# MagickWand
32# MagickCore
Mark Young93ecb1d2016-01-13 13:47:16 -070033#
34# For these components the following variables are set:
35#
Mark Youngb5ed9852016-01-25 16:02:08 -070036# ImageMagick_FOUND - TRUE if all components are found.
37# ImageMagick_INCLUDE_DIRS - Full paths to all include dirs.
38# ImageMagick_LIBRARIES - Full paths to all libraries.
39# ImageMagick_<component>_FOUND - TRUE if <component> is found.
40# ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
41# ImageMagick_<component>_LIBRARIES - Full path to <component> libraries.
Mark Young93ecb1d2016-01-13 13:47:16 -070042#
43# Example Usages:
Mark Youngb5ed9852016-01-25 16:02:08 -070044# FIND_PACKAGE(ImageMagick)
45# FIND_PACKAGE(ImageMagick COMPONENTS convert)
46# FIND_PACKAGE(ImageMagick COMPONENTS convert mogrify display)
47# FIND_PACKAGE(ImageMagick COMPONENTS Magick++)
48# FIND_PACKAGE(ImageMagick COMPONENTS Magick++ convert)
Mark Young93ecb1d2016-01-13 13:47:16 -070049#
Mark Youngb5ed9852016-01-25 16:02:08 -070050# Note that the standard FIND_PACKAGE features are supported
51# (i.e., QUIET, REQUIRED, etc.).
Mark Young93ecb1d2016-01-13 13:47:16 -070052
53#=============================================================================
54# Copyright 2007-2009 Kitware, Inc.
55# Copyright 2007-2008 Miguel A. Figueroa-Villanueva <miguelf at ieee dot org>
Mark Young93ecb1d2016-01-13 13:47:16 -070056#
57# Distributed under the OSI-approved BSD License (the "License");
Mark Youngb5ed9852016-01-25 16:02:08 -070058# see accompanying file Copyright_cmake.txt for details.
Mark Young93ecb1d2016-01-13 13:47:16 -070059#
60# This software is distributed WITHOUT ANY WARRANTY; without even the
61# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
62# See the License for more information.
63#=============================================================================
Mark Youngb5ed9852016-01-25 16:02:08 -070064# (To distributed this file outside of CMake, substitute the full
Mark Young93ecb1d2016-01-13 13:47:16 -070065# License text for the above reference.)
66
67find_package(PkgConfig QUIET)
68
69function(FIND_REGISTRY)
70 if (WIN32)
Mark Youngb5ed9852016-01-25 16:02:08 -070071
Mark Young93ecb1d2016-01-13 13:47:16 -070072 # If a 64-bit compile, it can only appear in "[HKLM]\\software\\ImageMagick"
73 if (CMAKE_CL_64)
Mark Younge91eee52016-01-22 15:06:43 -070074
75 GET_FILENAME_COMPONENT(IM_BIN_PATH
76 [HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]
77 ABSOLUTE CACHE)
Mark Youngb5ed9852016-01-25 16:02:08 -070078
Mark Young93ecb1d2016-01-13 13:47:16 -070079 else()
80
81 # This is dumb, but it's the only way I've been able to get this to work. CMake has no knowledge of the systems architecture.
82 # So, if we want to detect if we're running a 32-bit compile on a 64-bit OS, we need to manually check for the existence of
83 # ImageMagick in the WOW6432Node of the registry first. If that fails, assume they want the 64-bit version.
84 GET_FILENAME_COMPONENT(TESTING
85 [HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\ImageMagick\\Current;BinPath]
86 PATH)
87
Mark Younge91eee52016-01-22 15:06:43 -070088 # If the WOW6432Node reg string returns empty, assume 32-bit OS, and look in the standard reg path.
89 if (TESTING STREQUAL "")
Mark Young93ecb1d2016-01-13 13:47:16 -070090
Mark Younge91eee52016-01-22 15:06:43 -070091 GET_FILENAME_COMPONENT(IM_BIN_PATH
92 [HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]
93 ABSOLUTE CACHE)
94
95 # Otherwise, the WOW6432Node returned a string, assume 32-bit build on 64-bit OS and use that string.
Mark Young93ecb1d2016-01-13 13:47:16 -070096 else()
Mark Younge91eee52016-01-22 15:06:43 -070097
98 GET_FILENAME_COMPONENT(IM_BIN_PATH
99 [HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\ImageMagick\\Current;BinPath]
100 ABSOLUTE CACHE)
Mark Young93ecb1d2016-01-13 13:47:16 -0700101
102 endif()
103
104 endif()
Mark Younge91eee52016-01-22 15:06:43 -0700105
106 set (IMAGEMAGIC_REG_PATH ${IM_BIN_PATH} PARENT_SCOPE)
107 set (IMAGEMAGIC_REGINCLUDE_PATH ${IM_BIN_PATH}/include PARENT_SCOPE)
108 set (IMAGEMAGIC_REGLIB_PATH ${IM_BIN_PATH}/lib PARENT_SCOPE)
109
Mark Young93ecb1d2016-01-13 13:47:16 -0700110 else()
Mark Young3f9e9d12016-01-26 09:29:29 -0700111
112 # No registry exists for Linux. So, just set these to empty strings.
Mark Young93ecb1d2016-01-13 13:47:16 -0700113 set (IMAGEMAGIC_REG_PATH "" PARENT_SCOPE)
114 set (IMAGEMAGIC_REGINCLUDE_PATH "" PARENT_SCOPE)
115 set (IMAGEMAGIC_REGLIB_PATH "" PARENT_SCOPE)
116
117 endif()
118endfunction()
119
120
121#---------------------------------------------------------------------
122# Helper functions
123#---------------------------------------------------------------------
Mark Youngb5ed9852016-01-25 16:02:08 -0700124FUNCTION(FIND_IMAGEMAGICK_API component header)
125 SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
Mark Young93ecb1d2016-01-13 13:47:16 -0700126
Mark Youngb5ed9852016-01-25 16:02:08 -0700127 FIND_PATH(ImageMagick_${component}_INCLUDE_DIR
Mark Young93ecb1d2016-01-13 13:47:16 -0700128 NAMES ${header}
Mark Young93ecb1d2016-01-13 13:47:16 -0700129 PATHS
130 ${ImageMagick_INCLUDE_DIRS}
131 ${IMAGEMAGIC_REGINCLUDE_PATH}
132 PATH_SUFFIXES
Mark Young3f9e9d12016-01-26 09:29:29 -0700133 ImageMagick ImageMagick-6
Mark Youngb5ed9852016-01-25 16:02:08 -0700134 DOC "Path to the ImageMagick include dir."
Mark Young93ecb1d2016-01-13 13:47:16 -0700135 )
Mark Young3f9e9d12016-01-26 09:29:29 -0700136 FIND_PATH(ImageMagick_${component}_ARCH_INCLUDE_DIR
137 NAMES magick/magick-baseconfig.h
138 PATHS
139 ${ImageMagick_INCLUDE_DIRS}
140 ${IMAGEMAGIC_REGINCLUDE_PATH}
141 PATH_SUFFIXES
142 ImageMagick ImageMagick-6
143 DOC "Path to the ImageMagick arch-specific include dir."
144 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700145 FIND_LIBRARY(ImageMagick_${component}_LIBRARY
Mark Young93ecb1d2016-01-13 13:47:16 -0700146 NAMES ${ARGN}
Mark Young93ecb1d2016-01-13 13:47:16 -0700147 PATHS
148 ${IMAGEMAGIC_REGLIB_PATH}
149 DOC "Path to the ImageMagick Magick++ library."
150 )
151
Mark Youngb5ed9852016-01-25 16:02:08 -0700152 IF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
Mark Young93ecb1d2016-01-13 13:47:16 -0700153
Mark Young3f9e9d12016-01-26 09:29:29 -0700154 SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
Mark Youngb5ed9852016-01-25 16:02:08 -0700155 LIST(APPEND ImageMagick_INCLUDE_DIRS
Mark Young93ecb1d2016-01-13 13:47:16 -0700156 ${ImageMagick_${component}_INCLUDE_DIR}
157 )
Mark Young93450962016-01-26 11:27:09 -0700158 IF(EXISTS ${ImageMagick_${component}_ARCH_INCLUDE_DIR})
159 LIST(APPEND ImageMagick_INCLUDE_DIRS
160 ${ImageMagick_${component}_ARCH_INCLUDE_DIR}
161 )
162 ENDIF(EXISTS ${ImageMagick_${component}_ARCH_INCLUDE_DIR})
Mark Youngb5ed9852016-01-25 16:02:08 -0700163 LIST(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS)
164 SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE)
Mark Young93ecb1d2016-01-13 13:47:16 -0700165
Mark Youngb5ed9852016-01-25 16:02:08 -0700166 LIST(APPEND ImageMagick_LIBRARIES
Mark Young93ecb1d2016-01-13 13:47:16 -0700167 ${ImageMagick_${component}_LIBRARY}
168 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700169 SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE)
170 ENDIF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY)
Mark Young3f9e9d12016-01-26 09:29:29 -0700171
Mark Youngb5ed9852016-01-25 16:02:08 -0700172ENDFUNCTION(FIND_IMAGEMAGICK_API)
Mark Young93ecb1d2016-01-13 13:47:16 -0700173
Mark Youngb5ed9852016-01-25 16:02:08 -0700174FUNCTION(FIND_IMAGEMAGICK_EXE component)
175 SET(_IMAGEMAGICK_EXECUTABLE
Mark Young93ecb1d2016-01-13 13:47:16 -0700176 ${ImageMagick_EXECUTABLE_DIR}/${component}${CMAKE_EXECUTABLE_SUFFIX})
Mark Youngb5ed9852016-01-25 16:02:08 -0700177 IF(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
178 SET(ImageMagick_${component}_EXECUTABLE
Mark Young93ecb1d2016-01-13 13:47:16 -0700179 ${_IMAGEMAGICK_EXECUTABLE}
180 PARENT_SCOPE
181 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700182 SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE)
183 ELSE(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
184 SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE)
185 ENDIF(EXISTS ${_IMAGEMAGICK_EXECUTABLE})
186ENDFUNCTION(FIND_IMAGEMAGICK_EXE)
Mark Young93ecb1d2016-01-13 13:47:16 -0700187
188#---------------------------------------------------------------------
189# Start Actual Work
190#---------------------------------------------------------------------
191FIND_REGISTRY()
192
193# Try to find a ImageMagick installation binary path.
Mark Youngb5ed9852016-01-25 16:02:08 -0700194FIND_PATH(ImageMagick_EXECUTABLE_DIR
Mark Young93ecb1d2016-01-13 13:47:16 -0700195 NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
196 PATHS
197 ${IMAGEMAGIC_REG_PATH}
198 DOC "Path to the ImageMagick binary directory."
199 NO_DEFAULT_PATH
200 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700201FIND_PATH(ImageMagick_EXECUTABLE_DIR
Mark Young93ecb1d2016-01-13 13:47:16 -0700202 NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX}
203 )
204
205# Find each component. Search for all tools in same dir
206# <ImageMagick_EXECUTABLE_DIR>; otherwise they should be found
207# independently and not in a cohesive module such as this one.
Mark Youngb5ed9852016-01-25 16:02:08 -0700208SET(ImageMagick_FOUND TRUE)
209FOREACH(component ${ImageMagick_FIND_COMPONENTS}
Mark Young93ecb1d2016-01-13 13:47:16 -0700210 # DEPRECATED: forced components for backward compatibility
211 convert mogrify import montage composite
212 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700213 IF(component STREQUAL "Magick++")
Mark Young93ecb1d2016-01-13 13:47:16 -0700214 FIND_IMAGEMAGICK_API(Magick++ Magick++.h
Mark Young3f9e9d12016-01-26 09:29:29 -0700215 Magick++ CORE_RL_Magick++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8 Magick++-6.Q16HDRI Magick++-Q16HDRI Magick++-6.Q8HDRI Magick++-Q8HDRI
Mark Young93ecb1d2016-01-13 13:47:16 -0700216 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700217 ELSEIF(component STREQUAL "MagickWand")
Mark Young93ecb1d2016-01-13 13:47:16 -0700218 FIND_IMAGEMAGICK_API(MagickWand wand/MagickWand.h
Mark Young3f9e9d12016-01-26 09:29:29 -0700219 Wand MagickWand CORE_RL_wand_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8 MagickWand-6.Q16HDRI MagickWand-Q16HDRI MagickWand-6.Q8HDRI MagickWand-Q8HDRI
Mark Young93ecb1d2016-01-13 13:47:16 -0700220 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700221 ELSEIF(component STREQUAL "MagickCore")
Mark Young93ecb1d2016-01-13 13:47:16 -0700222 FIND_IMAGEMAGICK_API(MagickCore magick/MagickCore.h
Mark Young3f9e9d12016-01-26 09:29:29 -0700223 Magick MagickCore CORE_RL_magick_ MagickCore-6.Q16 MagickCore-Q16 MagickCore-6.Q8 MagickCore-Q8 MagickCore-6.Q16HDRI MagickCore-Q16HDRI MagickCore-6.Q8HDRI MagickCore-Q8HDRI
Mark Young93ecb1d2016-01-13 13:47:16 -0700224 )
Mark Youngb5ed9852016-01-25 16:02:08 -0700225 ELSE(component STREQUAL "Magick++")
226 IF(ImageMagick_EXECUTABLE_DIR)
Mark Young93ecb1d2016-01-13 13:47:16 -0700227 FIND_IMAGEMAGICK_EXE(${component})
Mark Youngb5ed9852016-01-25 16:02:08 -0700228 ENDIF(ImageMagick_EXECUTABLE_DIR)
229 ENDIF(component STREQUAL "Magick++")
230
231 IF(NOT ImageMagick_${component}_FOUND)
232 LIST(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested)
233 IF(is_requested GREATER -1)
234 SET(ImageMagick_FOUND FALSE)
235 ENDIF(is_requested GREATER -1)
236 ENDIF(NOT ImageMagick_${component}_FOUND)
237ENDFOREACH(component)
Mark Young93ecb1d2016-01-13 13:47:16 -0700238
Mark Youngb5ed9852016-01-25 16:02:08 -0700239SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS})
240SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES})
Mark Young93ecb1d2016-01-13 13:47:16 -0700241
242#---------------------------------------------------------------------
243# Standard Package Output
244#---------------------------------------------------------------------
Mark Youngb5ed9852016-01-25 16:02:08 -0700245INCLUDE(FindPackageHandleStandardArgs)
246FIND_PACKAGE_HANDLE_STANDARD_ARGS(
247 ImageMagick DEFAULT_MSG ImageMagick_FOUND
Mark Young93ecb1d2016-01-13 13:47:16 -0700248 )
249# Maintain consistency with all other variables.
Mark Youngb5ed9852016-01-25 16:02:08 -0700250SET(ImageMagick_FOUND ${IMAGEMAGICK_FOUND})
Mark Young93ecb1d2016-01-13 13:47:16 -0700251
252#---------------------------------------------------------------------
253# DEPRECATED: Setting variables for backward compatibility.
254#---------------------------------------------------------------------
Mark Youngb5ed9852016-01-25 16:02:08 -0700255SET(IMAGEMAGICK_BINARY_PATH ${ImageMagick_EXECUTABLE_DIR}
Mark Young93ecb1d2016-01-13 13:47:16 -0700256 CACHE PATH "Path to the ImageMagick binary directory.")
Mark Youngb5ed9852016-01-25 16:02:08 -0700257SET(IMAGEMAGICK_CONVERT_EXECUTABLE ${ImageMagick_convert_EXECUTABLE}
Mark Young93ecb1d2016-01-13 13:47:16 -0700258 CACHE FILEPATH "Path to ImageMagick's convert executable.")
Mark Youngb5ed9852016-01-25 16:02:08 -0700259SET(IMAGEMAGICK_MOGRIFY_EXECUTABLE ${ImageMagick_mogrify_EXECUTABLE}
Mark Young93ecb1d2016-01-13 13:47:16 -0700260 CACHE FILEPATH "Path to ImageMagick's mogrify executable.")
Mark Youngb5ed9852016-01-25 16:02:08 -0700261SET(IMAGEMAGICK_IMPORT_EXECUTABLE ${ImageMagick_import_EXECUTABLE}
Mark Young93ecb1d2016-01-13 13:47:16 -0700262 CACHE FILEPATH "Path to ImageMagick's import executable.")
Mark Youngb5ed9852016-01-25 16:02:08 -0700263SET(IMAGEMAGICK_MONTAGE_EXECUTABLE ${ImageMagick_montage_EXECUTABLE}
Mark Young93ecb1d2016-01-13 13:47:16 -0700264 CACHE FILEPATH "Path to ImageMagick's montage executable.")
Mark Youngb5ed9852016-01-25 16:02:08 -0700265SET(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE}
Mark Young93ecb1d2016-01-13 13:47:16 -0700266 CACHE FILEPATH "Path to ImageMagick's composite executable.")
Mark Youngb5ed9852016-01-25 16:02:08 -0700267
268MARK_AS_ADVANCED(
Mark Young93ecb1d2016-01-13 13:47:16 -0700269 IMAGEMAGICK_BINARY_PATH
270 IMAGEMAGICK_CONVERT_EXECUTABLE
271 IMAGEMAGICK_MOGRIFY_EXECUTABLE
272 IMAGEMAGICK_IMPORT_EXECUTABLE
273 IMAGEMAGICK_MONTAGE_EXECUTABLE
274 IMAGEMAGICK_COMPOSITE_EXECUTABLE
275 )