# - Try to find libOPENJPEG
# Once done, this will define
#
#  OPENJPEG_FOUND - system has libopenjp2
#  OPENJPEG_INCLUDE_DIRS - the libopenjp2 include directories
#  OPENJPEG_LIBRARIES - link these to use libopenjp2

# Include dir
# Look from openjpeg-2.3 subdirectories first, then openjpeg, then finally check the generic include directories as well.
FIND_PATH(OPENJPEG_INCLUDE_DIR NAMES openjpeg.h PATHS
/usr/local/include/openjpeg-2.3
/usr/include/openjpeg-2.3
NO_DEFAULT_PATH
)
FIND_PATH(OPENJPEG_INCLUDE_DIR NAMES openjpeg.h PATHS
/usr/local/include/openjpeg
/usr/include/openjpeg
NO_DEFAULT_PATH
)
FIND_PATH(OPENJPEG_INCLUDE_DIR NAMES openjpeg.h PATHS
/usr/local/include
/usr/include
)

MESSAGE(STATUS ${OpenJPEG_VERSION})

SET(OPENJPEG_NAMES ${OPENJPEG_NAMES} openjp2)
FIND_LIBRARY(OPENJPEG_LIBRARY
  NAMES ${OPENJPEG_NAMES}
  PATHS /usr/lib /usr/local/lib
  )

IF (OPENJPEG_LIBRARY AND OPENJPEG_INCLUDE_DIR)
    SET(OPENJPEG_LIBRARIES ${OPENJPEG_LIBRARY})
    SET(OPENJPEG_FOUND "YES")
ELSE (OPENJPEG_LIBRARY AND OPENJPEG_INCLUDE_DIR)
    SET(OPENJPEG_FOUND "NO")
ENDIF (OPENJPEG_LIBRARY AND OPENJPEG_INCLUDE_DIR)


IF (OPENJPEG_FOUND)
   IF (NOT OPENJPEG_FIND_QUIETLY)
      MESSAGE(STATUS "Found OpenJPEG libraries: ${OPENJPEG_LIBRARIES}")
      MESSAGE(STATUS "Found OpenJPEG headers: ${OPENJPEG_INCLUDE_DIR}")
   ENDIF (NOT OPENJPEG_FIND_QUIETLY)
ELSE (OPENJPEG_FOUND)
   IF (OPENJPEG_FIND_REQUIRED)
      MESSAGE(FATAL_ERROR "Could not find OpenJPEG library")
   ENDIF (OPENJPEG_FIND_REQUIRED)
ENDIF (OPENJPEG_FOUND)

# Deprecated declarations.
SET (NATIVE_OPENJPEG_INCLUDE_PATH ${OPENJPEG_INCLUDE_DIR} )
GET_FILENAME_COMPONENT (NATIVE_OPENJPEG_LIB_PATH ${OPENJPEG_LIBRARY} PATH)

