find_path(IMAGE_ROOT NAMES image HINTS ${BOLT_ROOT} $ENV{BOLT_ROOT})
set(IMAGE_ROOT "${IMAGE_ROOT}/image")

set(IMAGE_INCLUDE_DIR "${IMAGE_ROOT}/include")
if (USE_DYNAMIC_LIBRARY)
    set(IMAGE_LIBRARY "${IMAGE_ROOT}/lib/libimage.so")
else (USE_DYNAMIC_LIBRARY)
    set(IMAGE_LIBRARY "${IMAGE_ROOT}/lib/libimage.a")
endif (USE_DYNAMIC_LIBRARY)

if (IMAGE_INCLUDE_DIR AND IMAGE_LIBRARY)
    set(IMAGE_FOUND true)
endif (IMAGE_INCLUDE_DIR AND IMAGE_LIBRARY)

find_package(CImg)
find_package(png)
find_package(jpeg)
find_package(X11)
find_package(xcb)
find_package(Xau)
find_package(z)

if (IMAGE_FOUND)
    set(IMAGE_LIBRARIES "${IMAGE_LIBRARY};${PNG_LIBRARY};${JPEG_LIBRARY};${X11_LIBRARY};${XCB_LIBRARY};${ZLIB_LIBRARY};${XAU_LIBRARY};-lpthread;-ldl")
    include_directories(include ${IMAGE_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${JPEG_INCLUDE_DIR}  ${X11_INCLUDE_DIR} ${XCB_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${XAU_INCLUDE_DIR} ${CImg_INCLUDE_DIR})
    message(STATUS "Found image.h: ${IMAGE_INCLUDE_DIR}")
    message(STATUS "Found image: ${IMAGE_LIBRARY}")
else (IMAGE_FOUND)
    message(FATAL_ERROR "Could not find image library")
endif (IMAGE_FOUND)
