# --- dependencies ---

# --- variables ---

# --- normal modules ---
IF( LCMS_FOUND )
  SET( OY_MODULE lcms )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
  TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} )
# ${LCMS_LIBRARIES}
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${LCMS_LIBRARIES} )
ENDIF()

IF( LCMS2_FOUND )
  SET( OY_MODULE lcm2 )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
  TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} )
# ${LCMS2_LIBRARIES}
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${LCMS2_LIBRARIES} )
ENDIF()


IF( HAVE_LIBRAW_PLUGIN )
  SET( OY_MODULE lraw )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.cpp )
  TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${LIBRAW_LIBRARIES} ${EXIF_LIBRARIES} )
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${LIBRAW_LIBRARIES} ${EXIF_LIBRARIES} )
ENDIF()


SET( OY_MODULE oicc )
SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
ADD_LIBRARY( ${OY_MODULE_LIB}
             SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} )
INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})


IF( LIBPNG_FOUND )
  SET( OY_MODULE oPNG )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  FIND_LIBRARY( ZLIB_LIBRARIES NAMES z )
  IF( ZLIB_LIBRARIES )
    SET( PNG_EXTRA_LIBS ${EXTRA_LIBS} ${ZLIB_LIBRARIES} )
  ENDIF( ZLIB_LIBRARIES )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
  TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${LIBPNG_LIBRARIES} ${ZLIB_LIBRARIES} )
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${LIBPNG_LIBRARIES} ${ZLIB_LIBRARIES} )
ENDIF()

IF( JPEG_FOUND )
  SET( OY_MODULE oJPG )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c jpegmarkers.c )
  TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${JPEG_LIBRARY} )
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${JPEG_LIBRARY} )
ENDIF()


SET( OY_MODULE oydi )
SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
ADD_LIBRARY( ${OY_MODULE_LIB}
             SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${XCM_LIBRARIES} ${XFIXES_LIBRARIES} )
INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${XCM_LIBRARIES} ${XFIXES_LIBRARIES} )

SET( OY_MODULE oyra )
SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
ADD_LIBRARY( ${OY_MODULE_LIB}
             SHARED
             ${PACKAGE_NAME}_cmm_${OY_MODULE}.c
             ${PACKAGE_NAME}_cmm_${OY_MODULE}_image.c
             ${PACKAGE_NAME}_cmm_${OY_MODULE}_image_channel.c
             ${PACKAGE_NAME}_cmm_${OY_MODULE}_image_expose.c
             ${PACKAGE_NAME}_cmm_${OY_MODULE}_image_scale.c
             ${PACKAGE_NAME}_cmm_${OY_MODULE}_image_ppm.c
           )
TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${XCM_LIBRARIES} ${XFIXES_LIBRARIES} )
INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})

# threads handler
IF( PTHREADS_FOUND )
  SET( OY_MODULE trds )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
  TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${THREAD_LIBRARY} )
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${THREAD_LIBRARY} )
ENDIF( PTHREADS_FOUND )

# DB handler
IF( HAVE_OPENICC )
  SET( OY_MODULE oiDB )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
  TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${OPENICC_LIBRARY} )
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${OPENICC_LIBRARY} )
ENDIF( HAVE_OPENICC )

IF( HAVE_ELEKTRA )
  SET( OY_MODULE elDB )
  SET( OY_MODULE_LIB ${PACKAGE_NAME}_${OY_MODULE}${OY_MODULE_NAME} )
  ADD_LIBRARY( ${OY_MODULE_LIB}
               SHARED ${PACKAGE_NAME}_cmm_${OY_MODULE}.c )
  IF( ${PLATFORM} MATCHES Windows)
    # currently (Elektra-0.8.9) only a statically linked elektra works for Oyranos
    TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${ELEKTRA_LDFLAGS} elektra-full )
  ELSE()
    TARGET_LINK_LIBRARIES ( ${OY_MODULE_LIB} ${PROJECT_NAME} ${EXTRA_LIBS} ${ELEKTRA_LDFLAGS} )
  ENDIF()
  INSTALL (TARGETS ${OY_MODULE_LIB} DESTINATION lib${LIB_SUFFIX}/${OY_CMMSUBPATH})
  SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} ${ELEKTRA_LDFLAGS} )
ENDIF( HAVE_ELEKTRA )

# --- device modules ---

ADD_SUBDIRECTORY (devices)

SET( OY_MODULE_LIBRARIES ${OY_MODULE_LIBRARIES} PARENT_SCOPE )
