IF(JPEG_FOUND)
  ADD_DEFINITIONS(-DHasJPEG)
  INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
ENDIF(JPEG_FOUND)

IF(PNG_FOUND)
  ADD_DEFINITIONS(-DHasPNG)
  INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIR})
ENDIF(PNG_FOUND)

IF(TIFF_FOUND)
  ADD_DEFINITIONS(-DHasTIFF)
  INCLUDE_DIRECTORIES(${TIFF_INCLUDE_DIR})
ENDIF(TIFF_FOUND)

IF(OPENEXR_FOUND)
  ADD_DEFINITIONS(-DHasEXR)
  INCLUDE_DIRECTORIES(${OPENEXR_INCLUDE_DIR})
ENDIF(OPENEXR_FOUND)

IF(HDF5_FOUND)
  ADD_DEFINITIONS(-DHasHDF5 ${HDF5_CPPFLAGS})
  INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIR})
ENDIF(HDF5_FOUND)

IF (MSVC OR MINGW)
    IF(NOT VIGRA_STATIC_LIB)
        ADD_DEFINITIONS(-DVIGRA_DLL)
    ENDIF()
ELSEIF(CMAKE_COMPILER_IS_GNUCXX)
    IF(VIGRA_STATIC_LIB)
        ADD_DEFINITIONS(-fPIC -DPIC)
    ENDIF()
ENDIF ()

ADD_LIBRARY(vigraimpex ${LIBTYPE}
    bmp.cxx
    byteorder.cxx
    codecmanager.cxx
    exr.cxx
    gif.cxx
    hdr.cxx
    hdf5impex.cxx
    hdf5_rf_impex.cxx
    iccjpeg.c
    imageinfo.cxx
    jpeg.cxx
    png.cxx
    pnm.cxx
    rgbe.c
    sifImport.cxx
    sun.cxx
    tiff.cxx
    viff.cxx
    void_vector.cxx)

STRING(REGEX REPLACE "\\." "" LIBRARY_VERSION_STRING ${vigra_version})
SET_TARGET_PROPERTIES(vigraimpex PROPERTIES VERSION 4.${LIBRARY_VERSION_STRING} SOVERSION 4)

IF(JPEG_FOUND)
  TARGET_LINK_LIBRARIES(vigraimpex ${JPEG_LIBRARIES})
ENDIF(JPEG_FOUND)

IF(PNG_FOUND)
  TARGET_LINK_LIBRARIES(vigraimpex ${PNG_LIBRARIES})
ENDIF(PNG_FOUND)

IF(TIFF_FOUND)
  TARGET_LINK_LIBRARIES(vigraimpex ${TIFF_LIBRARIES})
ENDIF(TIFF_FOUND)

IF(OPENEXR_FOUND)
  TARGET_LINK_LIBRARIES(vigraimpex ${OPENEXR_LIBRARIES})
ENDIF(OPENEXR_FOUND)

IF(HDF5_FOUND)
  TARGET_LINK_LIBRARIES(vigraimpex ${HDF5_LIBRARIES})
ENDIF(HDF5_FOUND)

INSTALL(TARGETS vigraimpex
        EXPORT vigra-targets
        RUNTIME DESTINATION bin 
        LIBRARY DESTINATION lib${LIB_SUFFIX} 
        ARCHIVE DESTINATION lib${LIB_SUFFIX})
