# - Find the ImageMagick binary suite.
# This module will search for a set of ImageMagick tools specified
# as components in the FIND_PACKAGE call. Typical components include,
# but are not limited to (future versions of ImageMagick might have
# additional components not listed here):
#
#  animate
#  compare
#  composite
#  conjure
#  convert
#  display
#  identify
#  import
#  mogrify
#  montage
#  stream
#
# If no component is specified in the FIND_PACKAGE call, then it only
# searches for the ImageMagick executable directory. This code defines
# the following variables:
#
#  ImageMagick_FOUND                  - TRUE if all components are found.
#  ImageMagick_EXECUTABLE_DIR         - Full path to executables directory.
#  ImageMagick_<component>_FOUND      - TRUE if <component> is found.
#  ImageMagick_<component>_EXECUTABLE - Full path to <component> executable.
#
# Example Usages:
#  FIND_PACKAGE(ImageMagick)
#  FIND_PACKAGE(ImageMagick COMPONENTS latex dvips ps2pdf bibtex)
#  FIND_PACKAGE(ImageMagick COMPONENTS pdflatex bibtex)
#
# Note that the standard FIND_PACKAGE features are supported
# (i.e., QUIET, REQUIRED, etc.).

# Copyright (c) 2007,
#  Miguel A. Figueroa-Villanueva, <miguelf at ieee dot org>.
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

# Try to find a ImageMagick installation binary path.
FIND_PATH(ImageMagick_EXECUTABLE_DIR
  NAMES mogrify mogrify.exe
  PATHS
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]"
    $ENV{ProgramFiles}
  PATH_SUFFIXES
    "ImageMagick/bin"
  DOC "Path to the ImageMagick binary directory."
  )
IF(ImageMagick_EXECUTABLE_DIR)
  SET(ImageMagick_FOUND TRUE)
ENDIF(ImageMagick_EXECUTABLE_DIR)

# Find each component. Search for all tools in same dir
# <ImageMagick_EXECUTABLE_DIR>; otherwise they should be found
# independently and not in a cohesive module such as this one.
SET(ImageMagick_FOUND TRUE)
FOREACH(component ${ImageMagick_FIND_COMPONENTS})
  IF(EXISTS ${ImageMagick_EXECUTABLE_DIR}/${component})
    SET(ImageMagick_${component}_EXECUTABLE
      ${ImageMagick_EXECUTABLE_DIR}/${component})
    SET(ImageMagick_${component}_FOUND TRUE)
  ELSEIF(EXISTS ${ImageMagick_EXECUTABLE_DIR}/${component}.exe)
    SET(ImageMagick_${component}_EXECUTABLE
      ${ImageMagick_EXECUTABLE_DIR}/${component}.exe)
    SET(ImageMagick_${component}_FOUND TRUE)
  ELSE(EXISTS ${ImageMagick_EXECUTABLE_DIR}/${component})
    SET(ImageMagick_${component}_FOUND FALSE)
    SET(ImageMagick_FOUND FALSE)
  ENDIF(EXISTS ${ImageMagick_EXECUTABLE_DIR}/${component})
ENDFOREACH(component)

#---------------------------------------------------------------------
# Setting deprecated variables for backward compatibility.
SET(IMAGEMAGICK_BINARY_PATH          ${ImageMagick_EXECUTABLE_DIR})
SET(IMAGEMAGICK_CONVERT_EXECUTABLE   ${ImageMagick_convert_EXECUTABLE})
SET(IMAGEMAGICK_MOGRIFY_EXECUTABLE   ${ImageMagick_mogrify_EXECUTABLE})
SET(IMAGEMAGICK_IMPORT_EXECUTABLE    ${ImageMagick_import_EXECUTABLE})
SET(IMAGEMAGICK_MONTAGE_EXECUTABLE   ${ImageMagick_montage_EXECUTABLE})
SET(IMAGEMAGICK_COMPOSITE_EXECUTABLE ${ImageMagick_composite_EXECUTABLE})

#---------------------------------------------------------------------
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
  ImageMagick DEFAULT_MSG ImageMagick_EXECUTABLE_DIR ImageMagick_FOUND
  )

#IF(ImageMagick_FOUND)
#  IF(NOT ImageMagick_FIND_QUIETLY)
#    MESSAGE(STATUS "Found ImageMagick: ${ImageMagick_EXECUTABLE_DIR}")
#  ENDIF(NOT ImageMagick_FIND_QUIETLY)
#ELSE(ImageMagick_FOUND)
#  IF(ImageMagick_FIND_REQUIRED)
#    MESSAGE(FATAL_ERROR "Could not find ImageMagick installation.")
#  ELSE(ImageMagick_FIND_REQUIRED)
#    IF(NOT ImageMagick_FIND_QUIETLY)
#      MESSAGE(STATUS "Could not find ImageMagick installation.")
#    ENDIF(NOT ImageMagick_FIND_QUIETLY)
#  ENDIF(ImageMagick_FIND_REQUIRED)
#ENDIF(ImageMagick_FOUND)
