INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(PC_CM256 "libcm256")

FIND_PATH(CM256_INCLUDE_DIR
    NAMES cm256/cm256.h
    HINTS ${PC_CM256_INCLUDE_DIR}
    ${CMAKE_INSTALL_PREFIX}/include
    ${LIBCM256_INSTALL_PREFIX}/include
    PATHS
    /usr/local/include
    /usr/include
)

FIND_LIBRARY(CM256_LIBRARIES
    NAMES cm256 libcm256
    HINTS ${PC_CM256_LIBDIR}
    ${CMAKE_INSTALL_PREFIX}/lib
    ${CMAKE_INSTALL_PREFIX}/lib64
    PATHS
    ${CM256_INCLUDE_DIR}/../lib
    /usr/local/lib
    /usr/local/lib64
    /usr/lib
    /usr/lib64
)

if(CM256_INCLUDE_DIR AND CM256_LIBRARIES)
    set(CM256_FOUND TRUE CACHE INTERNAL "CM256 found")
    message(STATUS "Found CM256: ${CM256_INCLUDE_DIR}, ${CM256_LIBRARIES}")
else(CM256_INCLUDE_DIR AND CM256_LIBRARIES)
    set(CM256_FOUND FALSE CACHE INTERNAL "CM256 found")
    message(STATUS "CM256 not found")
endif(CM256_INCLUDE_DIR AND CM256_LIBRARIES)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CM256 DEFAULT_MSG CM256_LIBRARIES CM256_INCLUDE_DIR)
MARK_AS_ADVANCED(CM256_LIBRARIES CM256_INCLUDE_DIR)
