# We set:
# - HARU_INCLUDE_DIRS
# - HARU_LIBRARIES
# - HARU_FOUND
# Taking into account:
# - HARU_PREFIX

FIND_PATH(HARU_INCLUDE_DIR
    hpdf.h
  PATHS
    ${HARU_PREFIX}/include
    /usr/include
    /usr/local/include
    /usr/local/include/hpdf
)

IF(WIN32)
  FIND_LIBRARY(HARU_LIB_RELEASE
    NAMES
      libhpdf
      libhpdfs
    PATHS
      ${HARU_PREFIX}/lib
  )
  FIND_LIBRARY(HARU_LIB_DEBUG
    NAMES
      libhpdfd
      libhpdfsd
    PATHS
      ${HARU_PREFIX}/lib
  )
  FIND_LIBRARY(PNG_LIB_RELEASE
    NAMES
      libpng
    PATHS
      ${HARU_PREFIX}/lib
  )
  FIND_LIBRARY(PNG_LIB_DEBUG
    NAMES
      libpngd
    PATHS
      ${HARU_PREFIX}/lib
  )
  FIND_LIBRARY(Z_LIB
    NAMES
      zlib
    PATHS
      ${HARU_PREFIX}/lib
      ${USERLIB_PREFIX}/lib
  )
  IF(HARU_LIB_RELEASE AND HARU_LIB_DEBUG)
    SET(HARU_LIB optimized ${HARU_LIB_RELEASE} debug ${HARU_LIB_DEBUG})
    SET(HARU_SUPPORT_LIBS "")
    IF(PNG_LIB_RELEASE AND PNG_LIB_DEBUG)
      SET(HARU_SUPPORT_LIBS ${HARU_SUPPORT_LIBS} optimized ${PNG_LIB_RELEASE} debug ${PNG_LIB_DEBUG})
    ENDIF(PNG_LIB_RELEASE AND PNG_LIB_DEBUG)
    IF(Z_LIB)
      SET(HARU_SUPPORT_LIBS ${HARU_SUPPORT_LIBS} ${Z_LIB})
    ENDIF(Z_LIB)
  ENDIF(HARU_LIB_RELEASE AND HARU_LIB_DEBUG)
  SET(HARU_SUPPORT_LIBS_FOUND TRUE)
ELSE(WIN32)
  FIND_LIBRARY(HARU_LIB
    NAMES
      hpdf
    PATHS
      ${HARU_PREFIX}/lib
  )

  FIND_LIBRARY(PNG_LIB
    NAMES
      png png12 png14
    PATHS
      ${HARU_PREFIX}/lib
      ${USERLIB_PREFIX}/lib
  )

  FIND_LIBRARY(M_LIB
    NAMES
      m
    PATHS
      ${HARU_PREFIX}/lib
      ${USERLIB_PREFIX}/lib
      /lib/x86_64-linux-gnu
  )

  FIND_LIBRARY(Z_LIB
    NAMES
      z
    PATHS
      ${HARU_PREFIX}/lib
      ${USERLIB_PREFIX}/lib
  )

  SET(HARU_SUPPORT_LIBS_FOUND FALSE)

  IF (PNG_LIB AND M_LIB AND Z_LIB)
    SET(HARU_SUPPORT_LIBS_FOUND TRUE)
    SET(HARU_SUPPORT_LIBS ${PNG_LIB} ${M_LIB} ${Z_LIB})
  ENDIF (PNG_LIB AND M_LIB AND Z_LIB)
ENDIF(WIN32)

IF(HARU_LIB AND HARU_INCLUDE_DIR AND HARU_SUPPORT_LIBS_FOUND)
  SET(HARU_FOUND TRUE)
  SET(HARU_INCLUDE_DIRS ${HARU_INCLUDE_DIR})
  SET(HARU_LIBRARIES ${HARU_LIB} ${HARU_SUPPORT_LIBS})
  MESSAGE(STATUS "Found libharu libraries")
ELSE(HARU_LIB AND HARU_INCLUDE_DIR AND HARU_SUPPORT_LIBS_FOUND)
  SET(HARU_FOUND FALSE)
  MESSAGE(STATUS "libharu libraries not found - set HARU_PREFIX")
ENDIF(HARU_LIB AND HARU_INCLUDE_DIR AND HARU_SUPPORT_LIBS_FOUND)



