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 67 find_package(PkgConfig QUIET) 68 69 function(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 endfunction() 119 120 121 #--------------------------------------------------------------------- 122 # Helper functions 123 #--------------------------------------------------------------------- 124 FUNCTION(FIND_IMAGEMAGICK_API component header) 125 SET(ImageMagick_${component}_FOUND FALSE PARENT_SCOPE) 126 127 FIND_PATH(ImageMagick_${component}_INCLUDE_DIR 128 NAMES ${header} 129 PATHS 130 ${ImageMagick_INCLUDE_DIRS} 131 ${IMAGEMAGIC_REGINCLUDE_PATH} 132 PATH_SUFFIXES 133 ImageMagick ImageMagick-6 134 DOC "Path to the ImageMagick include dir." 135 ) 136 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 ) 145 FIND_LIBRARY(ImageMagick_${component}_LIBRARY 146 NAMES ${ARGN} 147 PATHS 148 ${IMAGEMAGIC_REGLIB_PATH} 149 DOC "Path to the ImageMagick Magick++ library." 150 ) 151 152 IF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY) 153 154 SET(ImageMagick_${component}_FOUND TRUE PARENT_SCOPE) 155 LIST(APPEND ImageMagick_INCLUDE_DIRS 156 ${ImageMagick_${component}_INCLUDE_DIR} 157 ) 158 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}) 163 LIST(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS) 164 SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS} PARENT_SCOPE) 165 166 LIST(APPEND ImageMagick_LIBRARIES 167 ${ImageMagick_${component}_LIBRARY} 168 ) 169 SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE) 170 ENDIF(ImageMagick_${component}_INCLUDE_DIR AND ImageMagick_${component}_LIBRARY) 171 172 ENDFUNCTION(FIND_IMAGEMAGICK_API) 173 174 FUNCTION(FIND_IMAGEMAGICK_EXE component) 175 SET(_IMAGEMAGICK_EXECUTABLE 176 ${ImageMagick_EXECUTABLE_DIR}/${component}${CMAKE_EXECUTABLE_SUFFIX}) 177 IF(EXISTS ${_IMAGEMAGICK_EXECUTABLE}) 178 SET(ImageMagick_${component}_EXECUTABLE 179 ${_IMAGEMAGICK_EXECUTABLE} 180 PARENT_SCOPE 181 ) 182 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}) 186 ENDFUNCTION(FIND_IMAGEMAGICK_EXE) 187 188 #--------------------------------------------------------------------- 189 # Start Actual Work 190 #--------------------------------------------------------------------- 191 FIND_REGISTRY() 192 193 # Try to find a ImageMagick installation binary path. 194 FIND_PATH(ImageMagick_EXECUTABLE_DIR 195 NAMES mogrify${CMAKE_EXECUTABLE_SUFFIX} 196 PATHS 197 ${IMAGEMAGIC_REG_PATH} 198 DOC "Path to the ImageMagick binary directory." 199 NO_DEFAULT_PATH 200 ) 201 FIND_PATH(ImageMagick_EXECUTABLE_DIR 202 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. 208 SET(ImageMagick_FOUND TRUE) 209 FOREACH(component ${ImageMagick_FIND_COMPONENTS} 210 # DEPRECATED: forced components for backward compatibility 211 convert mogrify import montage composite 212 ) 213 IF(component STREQUAL "Magick++") 214 FIND_IMAGEMAGICK_API(Magick++ Magick++.h 215 Magick++ CORE_RL_Magick++_ Magick++-6.Q16 Magick++-Q16 Magick++-6.Q8 Magick++-Q8 Magick++-6.Q16HDRI Magick++-Q16HDRI Magick++-6.Q8HDRI Magick++-Q8HDRI 216 ) 217 ELSEIF(component STREQUAL "MagickWand") 218 FIND_IMAGEMAGICK_API(MagickWand wand/MagickWand.h 219 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 220 ) 221 ELSEIF(component STREQUAL "MagickCore") 222 FIND_IMAGEMAGICK_API(MagickCore magick/MagickCore.h 223 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 224 ) 225 ELSE(component STREQUAL "Magick++") 226 IF(ImageMagick_EXECUTABLE_DIR) 227 FIND_IMAGEMAGICK_EXE(${component}) 228 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) 237 ENDFOREACH(component) 238 239 SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS}) 240 SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES}) 241 242 #--------------------------------------------------------------------- 243 # Standard Package Output 244 #--------------------------------------------------------------------- 245 INCLUDE(FindPackageHandleStandardArgs) 246 FIND_PACKAGE_HANDLE_STANDARD_ARGS( 247 ImageMagick DEFAULT_MSG ImageMagick_FOUND 248 ) 249 # Maintain consistency with all other variables. 250 SET(ImageMagick_FOUND ${IMAGEMAGICK_FOUND}) 251 252 #--------------------------------------------------------------------- 253 # DEPRECATED: Setting variables for backward compatibility. 254 #--------------------------------------------------------------------- 255 SET(IMAGEMAGICK_BINARY_PATH ${ImageMagick_EXECUTABLE_DIR} 256 CACHE PATH "Path to the ImageMagick binary directory.") 257 SET(IMAGEMAGICK_CONVERT_EXECUTABLE ${ImageMagick_convert_EXECUTABLE} 258 CACHE FILEPATH "Path to ImageMagick's convert executable.") 259 SET(IMAGEMAGICK_MOGRIFY_EXECUTABLE ${ImageMagick_mogrify_EXECUTABLE} 260 CACHE FILEPATH "Path to ImageMagick's mogrify executable.") 261 SET(IMAGEMAGICK_IMPORT_EXECUTABLE ${ImageMagick_import_EXECUTABLE} 262 CACHE FILEPATH "Path to ImageMagick's import executable.") 263 SET(IMAGEMAGICK_MONTAGE_EXECUTABLE ${ImageMagick_montage_EXECUTABLE} 264 CACHE FILEPATH "Path to ImageMagick's montage executable.") 265 SET(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE} 266 CACHE FILEPATH "Path to ImageMagick's composite executable.") 267 268 MARK_AS_ADVANCED( 269 IMAGEMAGICK_BINARY_PATH 270 IMAGEMAGICK_CONVERT_EXECUTABLE 271 IMAGEMAGICK_MOGRIFY_EXECUTABLE 272 IMAGEMAGICK_IMPORT_EXECUTABLE 273 IMAGEMAGICK_MONTAGE_EXECUTABLE 274 IMAGEMAGICK_COMPOSITE_EXECUTABLE 275 ) 276