IF(ZLIB_FOUND)
  ADD_DEFINITIONS(-DHasZLIB)
  INCLUDE_DIRECTORIES(${SUPPRESS_WARNINGS} ${ZLIB_INCLUDE_DIR})
ENDIF(ZLIB_FOUND)

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

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

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

IF(OpenEXR_FOUND)
  ADD_DEFINITIONS(-DHasEXR ${OPENEXR_CPPFLAGS})
  INCLUDE_DIRECTORIES(${SUPPRESS_WARNINGS} ${OPENEXR_INCLUDE_DIR})
ENDIF(OpenEXR_FOUND)

IF(HDF5_FOUND)
  ADD_DEFINITIONS(-DHasHDF5 ${HDF5_CPPFLAGS})
  INCLUDE_DIRECTORIES(${SUPPRESS_WARNINGS} ${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 OR CMAKE_COMPILER_IS_CLANGXX)
    IF(VIGRA_STATIC_LIB)
        ADD_DEFINITIONS(-fPIC -DPIC)
    ENDIF()
ENDIF ()




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

set(SOVERSION 11)  # increment this after changing the vigraimpex library
IF(MACOSX)
    SET_TARGET_PROPERTIES(vigraimpex PROPERTIES VERSION ${SOVERSION}.${vigra_version}
                          SOVERSION ${SOVERSION} INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}"
                          CXX_STANDARD 11)
ELSE()
    SET_TARGET_PROPERTIES(vigraimpex PROPERTIES VERSION ${SOVERSION}.${vigra_version}
                          SOVERSION ${SOVERSION}
                          CXX_STANDARD 11)
ENDIF()

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)
  cmake_policy(SET CMP0028 NEW)
  TARGET_LINK_LIBRARIES(vigraimpex ${OPENEXR_LIBRARIES})
ENDIF(OPENEXR_FOUND)

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

IF(ZLIB_FOUND)
  TARGET_LINK_LIBRARIES(vigraimpex ${ZLIB_LIBRARIES})
ENDIF(ZLIB_FOUND)


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