SET(INC_DIR . ${GTK_INCLUDE_DIR} ${FILMGIMP_SRC_DIR}
            ${FILMGIMP_SRC_DIR}/lib ${LCMS_INCLUDE_DIR}
            ${JPEG_INCLUDE_DIR})

INCLUDE_DIRECTORIES( ${INC_DIR} )

SET(ALL_PLUGIN_TARGETS  bmp cineon  fits 
                hdr iff jpeg png rawphoto rotate sgi)
		
# Macro to add a single plugin where there is a single C file
# with the same name as the plugin and placed in a directory with the
# same name as the plugin
MACRO(ADD_SINGLE_SOURCE_PLUGIN NAME)
  ADD_EXECUTABLE(${NAME} ${NAME}/${NAME}.c)
  TARGET_LINK_LIBRARIES(${NAME} lib wire libhalf ${GTK_LIBRARIES})
  SET_TARGET_PROPERTIES(${NAME} PROPERTIES LINKER_LANGUAGE CXX)
  SET(ALL_PLUGIN_TARGETS ${ALL_PLUGIN_TARGETS} ${NAME})
ENDMACRO(ADD_SINGLE_SOURCE_PLUGIN)

# Add a list of plugins that have a single C file
MACRO(ADD_SINGLE_SOURCE_PLUGINS)
  FOREACH(SNAME ${ARGV})
    ADD_SINGLE_SOURCE_PLUGIN(${SNAME})
  ENDFOREACH(SNAME)
ENDMACRO(ADD_SINGLE_SOURCE_PLUGINS)

ADD_EXECUTABLE(bmp bmp/bmp.c bmp/bmpread.c bmp/bmpwrite.c)
TARGET_LINK_LIBRARIES(bmp lib wire ${GTK_LIBRARIES})

ADD_EXECUTABLE(cineon cineon/cineon.c cineon/logImageCore.c cineon/cineonlib.c 
			  cineon/dpxlib.c      cineon/logImageLib.c)
TARGET_LINK_LIBRARIES(cineon lib wire ${GTK_LIBRARIES})
			  

ADD_SINGLE_SOURCE_PLUGINS(blur compose decompose dicom edge
             gauss_rle gbr gifload iff mblur median minimum
	     noisify
             png pnm psd psd_save retinex rotate screenshot
             sharpen snoise sobel spread tga unsharp xwd)

ADD_EXECUTABLE(fits fits/fits.c fits/fitsrw.c)
TARGET_LINK_LIBRARIES(fits lib wire ${GTK_LIBRARIES})

# ADD_SINGLE_SOURCE_PLUGIN(gfig)

# gif does not compile
# ADD_SINGLE_SOURCE_PLUGIN(gif)

ADD_EXECUTABLE(hdr hdr/callbacks.c  hdr/fromrad.c  
                       hdr/hdr.c  hdr/interface.c)
TARGET_LINK_LIBRARIES(hdr lib wire ${GTK_LIBRARIES})

ADD_EXECUTABLE(jpeg jpeg/iccjpeg.c  jpeg/jpeg.c)
TARGET_LINK_LIBRARIES(jpeg lib wire libhalf ${GTK_LIBRARIES} ${JPEG_LIBRARIES}
                            ${LCMS})
SET_TARGET_PROPERTIES(jpeg PROPERTIES LINKER_LANGUAGE CXX)


ADD_EXECUTABLE(rawphoto  rawphoto/rawphoto.c)
ADD_EXECUTABLE(dcraw  rawphoto/dcraw.c)
SET_TARGET_PROPERTIES(rawphoto PROPERTIES LINKER_LANGUAGE CXX)

TARGET_LINK_LIBRARIES(rawphoto lib wire ${GTK_LIBRARIES} 
                                 ${LCMS})

TARGET_LINK_LIBRARIES(dcraw ${JPEG_LIBRARIES} ${LCMS})

ADD_EXECUTABLE(sgi sgi/sgi.c  sgi/sgilib.c)
TARGET_LINK_LIBRARIES(sgi lib wire ${GTK_LIBRARIES})


IF(TIFF_FOUND)
  ADD_EXECUTABLE(tiff tiff/tiff.c tiff/info.c tiff/gui.c tiff/cmm_funcs)
  TARGET_LINK_LIBRARIES(tiff lib wire libhalf lcms ${TIFF_LIBRARIES} ${GTK_LIBRARIES})
  SET_TARGET_PROPERTIES(tiff PROPERTIES LINKER_LANGUAGE CXX)
  SET(ALL_PLUGIN_TARGETS ${ALL_PLUGIN_TARGETS} tiff)
ENDIF(TIFF_FOUND)

IF(FLTK_FOUND)
  ADD_SUBDIRECTORY(icc_examin)
  ADD_EXECUTABLE(collect collect/collect.cpp)
  TARGET_LINK_LIBRARIES(collect lib wire fl_i18n ${GTK_LIBRARIES} 
      fltk fltk_images fltk_gl ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
  ADD_SUBDIRECTORY(bracketing_to_hdr)
ENDIF(FLTK_FOUND)

IF(WIN32)
  ADD_SINGLE_SOURCE_PLUGINS(winclipboard winprint)
ENDIF(WIN32)

ADD_SUBDIRECTORY(openexr)

ADD_EXECUTABLE(script-fu 
script-fu/gimpcolorbutton.c
script-fu/gimpfileselection.c
script-fu/gimpgradientmenu.c
script-fu/gimpgradientselect.c
script-fu/gimpgradientselect_pdb.c
script-fu/gimpmenu.c
script-fu/interp_regex.c
script-fu/interp_sliba.c
script-fu/interp_slib.c
script-fu/interp_trace.c
script-fu/script-fu.c
script-fu/script-fu-console.c
script-fu/script-fu-constants.c
script-fu/script-fu-scripts.c
script-fu/script-fu-server.c
dbbrowser/dbbrowser_utils.c)

TARGET_LINK_LIBRARIES(script-fu lib wire ${GTK_LIBRARIES} )

INSTALL(TARGETS ${ALL_PLUGIN_TARGETS}
        DESTINATION ${PROGRAM_PLUGINS_DIR_INFIX})

INSTALL(TARGETS dcraw
        DESTINATION ${PROGRAM_EXTRA_DIR_INFIX})
