MACRO(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
	SET(srcs)
	FOREACH(src ${SOURCES})
		IF("${src}" MATCHES ".fl$")
			GET_FILENAME_COMPONENT(fname ${src} NAME_WE)
			SET(fluid_name "${CMAKE_CURRENT_SOURCE_DIR}/${fname}.fl")
			SET(cxx_name "${CMAKE_CURRENT_BINARY_DIR}/${fname}.cxx")
			SET(h_name "${CMAKE_CURRENT_BINARY_DIR}/${fname}.cxx")
			SET(srcs ${srcs} "${cxx_name}")
			ADD_CUSTOM_COMMAND(
				OUTPUT ${cxx_name}
				DEPENDS "${fluid_name}" "${FLUID_COMMAND}"
				COMMAND ${FLUID_COMMAND}
				ARGS -c ${fluid_name})
			ADD_CUSTOM_COMMAND(
				OUTPUT ${h_name}
				DEPENDS "${fluid_name}" "${FLUID_COMMAND}"
				COMMAND ${FLUID_COMMAND}
				ARGS -c ${fluid_name})
		ELSE("${src}" MATCHES ".fl$")
			SET(srcs ${srcs} ${src})
		ENDIF("${src}" MATCHES ".fl$")
	ENDFOREACH(src)
	ADD_EXECUTABLE(${NAME} ${srcs})
	TARGET_LINK_LIBRARIES(${NAME} ${LIBRARIES})
ENDMACRO(CREATE_EXAMPLE)

INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}
  )

CREATE_EXAMPLE(adjuster adjuster.cxx fltk)
CREATE_EXAMPLE(arc arc.cxx fltk)
CREATE_EXAMPLE(ask ask.cxx fltk)
CREATE_EXAMPLE(bitmap bitmap.cxx fltk)
CREATE_EXAMPLE(boxtype boxtype.cxx fltk)
CREATE_EXAMPLE(browser browser.cxx fltk)
CREATE_EXAMPLE(button button.cxx fltk)
CREATE_EXAMPLE(buttons buttons.cxx fltk)
CREATE_EXAMPLE(checkers checkers.cxx fltk)
CREATE_EXAMPLE(clock clock.cxx fltk)
CREATE_EXAMPLE(colbrowser colbrowser.cxx "fltk;fltk_forms")
CREATE_EXAMPLE(color_chooser color_chooser.cxx fltk)
CREATE_EXAMPLE(cursor cursor.cxx fltk)
CREATE_EXAMPLE(curve curve.cxx fltk)
CREATE_EXAMPLE(demo demo.cxx "fltk;fltk_forms")
CREATE_EXAMPLE(doublebuffer doublebuffer.cxx fltk)
CREATE_EXAMPLE(editor editor.cxx fltk)
CREATE_EXAMPLE(fast_slow fast_slow.fl fltk)
CREATE_EXAMPLE(file_chooser file_chooser.cxx "fltk;fltk_images")
CREATE_EXAMPLE(fonts fonts.cxx fltk)
CREATE_EXAMPLE(forms forms.cxx "fltk;fltk_forms")
CREATE_EXAMPLE(hello hello.cxx fltk)
CREATE_EXAMPLE(help help.cxx "fltk;fltk_images")
CREATE_EXAMPLE(iconize iconize.cxx fltk)
CREATE_EXAMPLE(image image.cxx fltk)
CREATE_EXAMPLE(inactive inactive.fl fltk)
CREATE_EXAMPLE(input input.cxx fltk)
CREATE_EXAMPLE(keyboard "keyboard.cxx;keyboard_ui.fl" fltk)
CREATE_EXAMPLE(label label.cxx "fltk;fltk_forms")
CREATE_EXAMPLE(line_style line_style.cxx fltk)
CREATE_EXAMPLE(list_visuals list_visuals.cxx fltk)
CREATE_EXAMPLE(mandelbrot "mandelbrot_ui.fl;mandelbrot.cxx" fltk)
CREATE_EXAMPLE(menubar menubar.cxx fltk)
CREATE_EXAMPLE(message message.cxx fltk)
CREATE_EXAMPLE(minimum minimum.cxx fltk)
CREATE_EXAMPLE(navigation navigation.cxx fltk)
CREATE_EXAMPLE(output output.cxx "fltk;fltk_forms")
CREATE_EXAMPLE(overlay overlay.cxx fltk)
CREATE_EXAMPLE(pack pack.cxx fltk)
CREATE_EXAMPLE(pixmap pixmap.cxx fltk)
CREATE_EXAMPLE(pixmap_browser pixmap_browser.cxx "fltk;fltk_images")
CREATE_EXAMPLE(preferences preferences.fl fltk)
CREATE_EXAMPLE(radio radio.fl fltk)
CREATE_EXAMPLE(resize resize.fl fltk)
CREATE_EXAMPLE(resizebox resizebox.cxx fltk)
CREATE_EXAMPLE(scroll scroll.cxx fltk)
CREATE_EXAMPLE(subwindow subwindow.cxx fltk)
CREATE_EXAMPLE(symbols symbols.cxx fltk)
CREATE_EXAMPLE(tabs tabs.fl fltk)
CREATE_EXAMPLE(threads threads.cxx fltk)
CREATE_EXAMPLE(tile tile.cxx fltk)
CREATE_EXAMPLE(tiled_image tiled_image.cxx fltk)
CREATE_EXAMPLE(valuators valuators.fl fltk)

# OpenGL demos...
IF(OPENGL_FOUND)
CREATE_EXAMPLE(CubeView "CubeMain.cxx;CubeView.cxx;CubeViewUI.fl" "fltk;fltk_gl")
CREATE_EXAMPLE(cube cube.cxx "fltk;fltk_gl;${OPENGL_LIBRARIES}")
CREATE_EXAMPLE(fractals "fractals.cxx;fracviewer.cxx" "fltk;fltk_gl")
CREATE_EXAMPLE(fullscreen fullscreen.cxx "fltk;fltk_gl")
CREATE_EXAMPLE(glpuzzle glpuzzle.cxx "fltk;fltk_gl;${OPENGL_LIBRARIES}")
CREATE_EXAMPLE(gl_overlay gl_overlay.cxx "fltk;fltk_gl;${OPENGL_LIBRARIES}")
CREATE_EXAMPLE(shape shape.cxx "fltk;fltk_gl;${OPENGL_LIBRARIES}")
ENDIF(OPENGL_FOUND)
