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# 28# There are also components for the following ImageMagick APIs: 29# 30# Magick++ 31# MagickWand 32# MagickCore 33# 34# For these components the following variables are set: 35# 36# 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. 42# 43# Example Usages: 44# 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) 49# 50# Note that the standard FIND_PACKAGE features are supported 51# (i.e., QUIET, REQUIRED, etc.). 52 53#============================================================================= 54# Copyright 2007-2009 Kitware, Inc. 55# Copyright 2007-2008 Miguel A. Figueroa-Villanueva <miguelf at ieee dot org> 56# 57# Distributed under the OSI-approved BSD License (the "License"); 58# see accompanying file Copyright_cmake.txt for details. 59# 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#============================================================================= 64# (To distributed this file outside of CMake, substitute the full 65# License text for the above reference.) 66 67find_package(PkgConfig QUIET) 68 69function(FIND_REGISTRY) 70 if (WIN32) 71 72 # If a 64-bit compile, it can only appear in "[HKLM]\\software\\ImageMagick" 73 if (CMAKE_CL_64) 74 75 GET_FILENAME_COMPONENT(IM_BIN_PATH 76 [HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath] 77 ABSOLUTE CACHE) 78 79 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 88 # If the WOW6432Node reg string returns empty, assume 32-bit OS, and look in the standard reg path. 89 if (TESTING STREQUAL "") 90 91 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. 96 else() 97 98 GET_FILENAME_COMPONENT(IM_BIN_PATH 99 [HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\ImageMagick\\Current;BinPath] 100 ABSOLUTE CACHE) 101 102 endif() 103 104 endif() 105 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 110 else() 111 112 # No registry exists for Linux. So, just set these to empty strings. 113 set (IMAGEMAGIC_REG_PATH "" PARENT_SCOPE) 114 set (IMAGEMAGIC_REGINCLUDE_PATH "" PARENT_SCOPE) 115 set (IMAGEMAGIC_REGLIB_PATH "" PARENT_SCOPE) 116 117 endif() 118 119endfunction() 120 121 122#--------------------------------------------------------------------- 123# Helper functions 124#--------------------------------------------------------------------- 125FUNCTION(FIND_IMAGEMAGICK_API component path header) 126 SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE) 127 128 # NOTE: My experience is that Windows uses the PATHs 129 # variables, while Linux uses the PATH_SUFFIXES. 130 # You can't add sub-directories to the PATH_SUFFIXES 131 # because it messes up the ImageMagick Include 132 # paths that are returned. Instead, you have to 133 # call this FIND_IMAGEMAGICK_API for each separate 134 # possible sub-folder. 135 FIND_PATH(ImageMagick_${component}_INCLUDE_DIR 136 NAMES ${header} 137 PATHS 138 ${ImageMagick_INCLUDE_DIRS} 139 ${IMAGEMAGIC_REGINCLUDE_PATH} 140 PATH_SUFFIXES 141 ImageMagick ImageMagick-6 ImageMagick-7 142 DOC "Path to the ImageMagick include dir." 143 ) 144 FIND_PATH(ImageMagick_${component}_ARCH_INCLUDE_DIR 145 NAMES magick/magick-baseconfig.h 146 PATHS 147 ${ImageMagick_INCLUDE_DIRS} 148 ${IMAGEMAGIC_REGINCLUDE_PATH} 149 PATH_SUFFIXES 150 ImageMagick ImageMagick-6 ImageMagick-7 151 DOC "Path to the ImageMagick arch-specific include dir." 152 ) 153 FIND_LIBRARY(ImageMagick_${component}_LIBRARY 154 NAMES ${ARGN} 155 PATHS 156 ${IMAGEMAGIC_REGLIB_PATH} 157 DOC "Path to the ImageMagick Magick++ library." 158 ) 159 160 161 IF (ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY) 162 SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE) 163 164 LIST(APPEND ImageMagick_INCLUDE_DIRS 165 ${ImageMagick_${component}_INCLUDE_DIR} 166 ) 167 168 # Only add the path if it's not the special string "<NONE>" 169 IF(NOT path STREQUAL "<NONE>") 170 LIST(APPEND ImageMagick_INCLUDE_DIRS 171 ${ImageMagick_${component}_INCLUDE_DIR}/${path} 172 ) 173 ENDIF() 174 175 # Add the architecture include path if it exists 176 IF (ImageMagick_${component}_ARCH_INCLUDE_DIR) 177 LIST(APPEND ImageMagick_INCLUDE_DIRS 178 ${ImageMagick_${component}_ARCH_INCLUDE_DIR} 179 ) 180 ENDIF() 181 182 LIST(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS) 183 SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE) 184 185 LIST(APPEND ImageMagick_LIBRARIES 186 ${ImageMagick_${component}_LIBRARY} 187 ) 188 SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE) 189 ENDIF() 190 191ENDFUNCTION(FIND_IMAGEMAGICK_API) 192 193FUNCTION(FIND_IMAGEMAGICK_EXE component) 194 SET(_IMAGEMAGICK_EXECUTABLE 195 ${ImageMagick_EXECUTABLE_DIR}/${component}${CMAKE_EXECUTABLE_SUFFIX}) 196 IF(EXISTS ${_IMAGEMAGICK_EXECUTABLE}) 197 SET(ImageMagick_${component}_EXECUTABLE 198 ${_IMAGEMAGICK_EXECUTABLE} 199 PARENT_SCOPE 200 ) 201 SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE) 202 ELSE(EXISTS ${_IMAGEMAGICK_EXECUTABLE}) 203 SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE) 204 ENDIF(EXISTS ${_IMAGEMAGICK_EXECUTABLE}) 205ENDFUNCTION(FIND_IMAGEMAGICK_EXE) 206 207#--------------------------------------------------------------------- 208# Start Actual Work 209#--------------------------------------------------------------------- 210FIND_REGISTRY() 211 212# Try to find a ImageMagick installation binary path. 213FIND_PATH(ImageMagick_EXECUTABLE_DIR 214 NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX} 215 PATHS 216 ${IMAGEMAGIC_REG_PATH} 217 DOC "Path to the ImageMagick binary directory." 218 NO_DEFAULT_PATH 219 ) 220FIND_PATH(ImageMagick_EXECUTABLE_DIR 221 NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX} 222 ) 223 224# Find each component. Search for all tools in same dir 225# <ImageMagick_EXECUTABLE_DIR>; otherwise they should be found 226# independently and not in a cohesive module such as this one. 227SET(ImageMagick_FOUND TRUE) 228FOREACH(component ${ImageMagick_FIND_COMPONENTS} 229 # DEPRECATED: forced components for backward compatibility 230 convert mogrify import montage composite 231 ) 232 233 IF(component STREQUAL "Magick++") 234 # unset cached variable that assumes header parameter never changes 235 UNSET(ImageMagick_MagickWand_INCLUDE_DIR CACHE) 236 237 # Try top folder first 238 FIND_IMAGEMAGICK_API(Magick++ <NONE> Magick++.h 239 Magick++ CORE_RL_Magick++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8 Magick++-6.Q16HDRI Magick++-Q16HDRI Magick++-6.Q8HDRI Magick++-Q8HDRI 240 ) 241 242 IF(NOT ImageMagick_Magick++_INCLUDE_DIR OR NOT ImageMagick_Magick++_LIBRARY) 243 # Look for Magick++.h, in the magick++ sub-folder 244 FIND_IMAGEMAGICK_API(Magick++ magick++ magick++/Magick++.h 245 Magick++ CORE_RL_Magick++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8 Magick++-6.Q16HDRI Magick++-Q16HDRI Magick++-6.Q8HDRI Magick++-Q8HDRI 246 ) 247 ENDIF() 248 249 IF(NOT ImageMagick_Magick++_INCLUDE_DIR OR NOT ImageMagick_Magick++_LIBRARY) 250 # Look for Magick++.h, in the magick sub-folder 251 FIND_IMAGEMAGICK_API(Magick++ magick magick/Magick++.h 252 Magick++ CORE_RL_Magick++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8 Magick++-6.Q16HDRI Magick++-Q16HDRI Magick++-6.Q8HDRI Magick++-Q8HDRI 253 ) 254 ENDIF() 255 256 ELSEIF(component STREQUAL "MagickWand") 257 # unset cached variable that assumes header parameter never changes 258 UNSET(ImageMagick_MagickWand_INCLUDE_DIR CACHE) 259 260 # Try top folder first 261 FIND_IMAGEMAGICK_API(MagickWand <NONE> MagickWand.h 262 Wand MagickWand CORE_RL_wand_ CORE_RL_MagickWand_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8 MagickWand-6.Q16HDRI MagickWand-Q16HDRI MagickWand-6.Q8HDRI MagickWand-Q8HDRI 263 ) 264 265 IF(NOT ImageMagick_MagickWand_INCLUDE_DIR OR NOT ImageMagick_MagickWand_LIBRARY) 266 # Look for MagickWand.h in the wand sub-folder 267 FIND_IMAGEMAGICK_API(MagickWand wand wand/MagickWand.h 268 Wand MagickWand CORE_RL_wand_ CORE_RL_MagickWand_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8 MagickWand-6.Q16HDRI MagickWand-Q16HDRI MagickWand-6.Q8HDRI MagickWand-Q8HDRI 269 ) 270 ENDIF() 271 272 IF(NOT ImageMagick_MagickWand_INCLUDE_DIR OR NOT ImageMagick_MagickWand_LIBRARY) 273 # Look for MagickWand.h he MagickWand sub-folder 274 FIND_IMAGEMAGICK_API(MagickWand MagickWand MagickWand/MagickWand.h 275 Wand MagickWand CORE_RL_wand_ CORE_RL_MagickWand_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8 MagickWand-6.Q16HDRI MagickWand-Q16HDRI MagickWand-6.Q8HDRI MagickWand-Q8HDRI 276 ) 277 ENDIF() 278 279 IF(NOT ImageMagick_MagickWand_INCLUDE_DIR OR NOT ImageMagick_MagickWand_LIBRARY) 280 # Look for MagickWand.h he magick sub-folder 281 FIND_IMAGEMAGICK_API(MagickWand magick magick/MagickWand.h 282 Wand MagickWand CORE_RL_wand_ CORE_RL_MagickWand_ MagickWand-6.Q16 MagickWand-Q16 MagickWand-6.Q8 MagickWand-Q8 MagickWand-6.Q16HDRI MagickWand-Q16HDRI MagickWand-6.Q8HDRI MagickWand-Q8HDRI 283 ) 284 ENDIF() 285 286 ELSEIF(component STREQUAL "MagickCore") 287 288 # Try top folder first 289 FIND_IMAGEMAGICK_API(MagickCore <NONE> MagickCore.h 290 Magick MagickCore CORE_RL_magick_ CORE_RL_MagickCore_ MagickCore-6.Q16 MagickCore-Q16 MagickCore-6.Q8 MagickCore-Q8 MagickCore-6.Q16HDRI MagickCore-Q16HDRI MagickCore-6.Q8HDRI MagickCore-Q8HDRI 291 ) 292 293 IF(NOT ImageMagick_MagickCore_INCLUDE_DIR OR NOT ImageMagick_MagickCore_LIBRARY) 294 # Look for MagickCore.h, in the MagickCore sub-folder 295 FIND_IMAGEMAGICK_API(MagickCore MagickCore MagickCore/MagickCore.h 296 Magick MagickCore CORE_RL_magick_ CORE_RL_MagickCore_ MagickCore-6.Q16 MagickCore-Q16 MagickCore-6.Q8 MagickCore-Q8 MagickCore-6.Q16HDRI MagickCore-Q16HDRI MagickCore-6.Q8HDRI MagickCore-Q8HDRI 297 ) 298 ENDIF() 299 300 IF(NOT ImageMagick_MagickCore_INCLUDE_DIR OR NOT ImageMagick_MagickCore_LIBRARY) 301 # Look for MagickCore.h, in the magick sub-folder 302 FIND_IMAGEMAGICK_API(MagickCore magick magick/MagickCore.h 303 Magick MagickCore CORE_RL_magick_ CORE_RL_MagickCore_ MagickCore-6.Q16 MagickCore-Q16 MagickCore-6.Q8 MagickCore-Q8 MagickCore-6.Q16HDRI MagickCore-Q16HDRI MagickCore-6.Q8HDRI MagickCore-Q8HDRI 304 ) 305 ENDIF() 306 307 ENDIF() 308 309 IF(NOT ImageMagick_${component}_FOUND) 310 311 LIST(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested) 312 IF(is_requested GREATER -1) 313 SET(ImageMagick_FOUND FALSE) 314 ENDIF(is_requested GREATER -1) 315 316 ENDIF(NOT ImageMagick_${component}_FOUND) 317ENDFOREACH(component) 318 319#--------------------------------------------------------------------- 320# Standard Package Output 321#--------------------------------------------------------------------- 322INCLUDE(FindPackageHandleStandardArgs) 323FIND_PACKAGE_HANDLE_STANDARD_ARGS( 324 ImageMagick DEFAULT_MSG ImageMagick_FOUND 325 ) 326# Maintain consistency with all other variables. 327SET(ImageMagick_FOUND ${IMAGEMAGICK_FOUND}) 328 329#--------------------------------------------------------------------- 330# DEPRECATED: Setting variables for backward compatibility. 331#--------------------------------------------------------------------- 332SET(IMAGEMAGICK_BINARY_PATH ${ImageMagick_EXECUTABLE_DIR} 333 CACHE PATH "Path to the ImageMagick binary directory.") 334SET(IMAGEMAGICK_CONVERT_EXECUTABLE ${ImageMagick_convert_EXECUTABLE} 335 CACHE FILEPATH "Path to ImageMagick's convert executable.") 336SET(IMAGEMAGICK_MOGRIFY_EXECUTABLE ${ImageMagick_mogrify_EXECUTABLE} 337 CACHE FILEPATH "Path to ImageMagick's mogrify executable.") 338SET(IMAGEMAGICK_IMPORT_EXECUTABLE ${ImageMagick_import_EXECUTABLE} 339 CACHE FILEPATH "Path to ImageMagick's import executable.") 340SET(IMAGEMAGICK_MONTAGE_EXECUTABLE ${ImageMagick_montage_EXECUTABLE} 341 CACHE FILEPATH "Path to ImageMagick's montage executable.") 342SET(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE} 343 CACHE FILEPATH "Path to ImageMagick's composite executable.") 344 345MARK_AS_ADVANCED( 346 IMAGEMAGICK_BINARY_PATH 347 IMAGEMAGICK_CONVERT_EXECUTABLE 348 IMAGEMAGICK_MOGRIFY_EXECUTABLE 349 IMAGEMAGICK_IMPORT_EXECUTABLE 350 IMAGEMAGICK_MONTAGE_EXECUTABLE 351 IMAGEMAGICK_COMPOSITE_EXECUTABLE 352 ) 353