Index: CMake/FLTK-Functions.cmake
===================================================================
--- CMake/FLTK-Functions.cmake	(revision 0)
+++ CMake/FLTK-Functions.cmake	(working copy)
@@ -0,0 +1,49 @@
+#
+# "$Id$"
+#
+# FLTK-Functions.cmake
+# Written by Michael Surette
+#
+# Copyright 1998-2016 by Bill Spitzak and others.
+#
+# This library is free software. Distribution and use rights are outlined in
+# the file "COPYING" which should have been included with this file.  If this
+# file is missing or damaged, see the license at:
+#
+#     http://www.fltk.org/COPYING.php
+#
+# Please report all bugs and problems on the following page:
+#
+#     http://www.fltk.org/str.php
+#
+
+#######################################################################
+# functions used by the build system and exported for the end-user
+#######################################################################
+# USAGE: FLTK_RUN_FLUID TARGET_NAME "FLUID_SOURCE [.. FLUID_SOURCE]"
+function(FLTK_RUN_FLUID TARGET SOURCES)
+    set (CXX_FILES)
+    foreach(src ${SOURCES})
+        if ("${src}" MATCHES "\\.fl$")
+            string(REGEX REPLACE "(.*).fl" \\1 basename ${src})
+            add_custom_command(
+                OUTPUT "${basename}.cxx" "${basename}.h"
+                COMMAND fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/${src}
+                DEPENDS ${src}
+                MAIN_DEPENDENCY ${src}
+            )
+            list(APPEND CXX_FILES "${basename}.cxx")
+        endif ("${src}" MATCHES "\\.fl$")
+        set (${TARGET} ${CXX_FILES} PARENT_SCOPE)
+    endforeach(src)
+endfunction(FLTK_RUN_FLUID TARGET SOURCES)
+
+#######################################################################
+# sets the bundle icon for OSX bundles
+function(FLTK_SET_BUNDLE_ICON TARGET ICON_PATH)
+    get_filename_component(ICON_NAME "${ICON_PATH}" NAME)
+    set_target_properties("${TARGET}" PROPERTIES
+        MACOSX_BUNDLE_ICON_FILE "${ICON_NAME}"
+        RESOURCE "${ICON_PATH}"
+    )
+endfunction(FLTK_SET_BUNDLE_ICON TARGET ICON_PATH)
Index: CMake/UseFLTK.cmake.in
===================================================================
--- CMake/UseFLTK.cmake.in	(revision 11676)
+++ CMake/UseFLTK.cmake.in	(working copy)
@@ -1,7 +1,7 @@
 #
 # UseFLTK.CMake - FLTK CMake environment configuration file for external projects.
 #
-# This file is generated by CMake and used to set FLTK's environment for an external project.
+# This file is depricated and will be removed in FLTK 1.4
 #
 # automatically generated - do not edit
 
Index: CMake/export.cmake
===================================================================
--- CMake/export.cmake	(revision 11676)
+++ CMake/export.cmake	(working copy)
@@ -44,6 +44,13 @@
 # generate FLTK-Targets.cmake for build directory use
 export(TARGETS ${FLUID} ${FLTK_LIBRARIES} FILE ${CMAKE_BINARY_DIR}/FLTK-Targets.cmake)
 
+# generate FLTK-Functions.cmake for build directory use
+configure_file(
+    ${FLTK_SOURCE_DIR}/CMake/FLTK-Functions.cmake
+    ${FLTK_BINARY_DIR}/FLTK-Functions.cmake
+    COPYONLY
+    )
+
 # generate FLTKConfig.cmake for build directory use
 set(INCLUDE_DIRS "${FLTK_INCLUDE_DIRS}")
 set(CONFIG_PATH ${FLTK_BINARY_DIR})
Index: CMake/install.cmake
===================================================================
--- CMake/install.cmake	(revision 11676)
+++ CMake/install.cmake	(working copy)
@@ -60,8 +60,10 @@
    @ONLY
 )
 
-install(FILES ${FLTK_BINARY_DIR}/etc/FLTKConfig.cmake
-   DESTINATION ${FLTK_CONFIG_PATH}
+install(FILES
+    ${FLTK_BINARY_DIR}/etc/FLTKConfig.cmake
+    ${FLTK_SOURCE_DIR}/CMake/FLTK-Functions.cmake
+    DESTINATION ${FLTK_CONFIG_PATH}
 )
 
 configure_file(
Index: CMake/macros.cmake
===================================================================
--- CMake/macros.cmake	(revision 11676)
+++ CMake/macros.cmake	(working copy)
@@ -1,7 +1,7 @@
 #
 # "$Id$"
 #
-# macros.cmake defines macros used by the build system
+# macros.cmake
 # Written by Michael Surette
 #
 # Copyright 1998-2016 by Bill Spitzak and others.
@@ -82,27 +82,8 @@
 endmacro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
 
 #######################################################################
-# USAGE: FLTK_RUN_FLUID TARGET_NAME "FLUID_SOURCE [.. FLUID_SOURCE]"
-function(FLTK_RUN_FLUID TARGET SOURCES)
-    set (CXX_FILES)
-    foreach(src ${SOURCES})
-        if ("${src}" MATCHES "\\.fl$")
-	    string(REGEX REPLACE "(.*).fl" \\1 basename ${src})
-	    add_custom_command(
-		OUTPUT "${basename}.cxx" "${basename}.h"
-		COMMAND fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/${src}
-		DEPENDS ${src}
-		MAIN_DEPENDENCY ${src}
-		)
-	    list(APPEND CXX_FILES "${basename}.cxx")
-        endif ("${src}" MATCHES "\\.fl$")
-        set (${TARGET} ${CXX_FILES} PARENT_SCOPE)
-    endforeach(src)
-endfunction(FLTK_RUN_FLUID TARGET SOURCES)
+function(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
 
-#######################################################################
-macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
-
     set (srcs)			# source files
     set (flsrcs)		# fluid source files
 
@@ -124,45 +105,26 @@
 
     set (FLUID_SOURCES)
     if (flsrcs)
-	FLTK_RUN_FLUID(FLUID_SOURCES "${flsrcs}")
+        FLTK_RUN_FLUID(FLUID_SOURCES "${flsrcs}")
     endif (flsrcs)
 
     if (APPLE AND NOT OPTION_APPLE_X11)
-      unset (RESOURCE_PATH)
-      if (${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku")
-        set (ICON_NAME ${tname}.icns)
-        set (RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/${tname}.app/Contents/Resources/${ICON_NAME}")
-      elseif (${tname} STREQUAL "demo")
-        set (RESOURCE_PATH "${PROJECT_SOURCE_DIR}/test/demo.menu")
-      endif (${tname} STREQUAL "blocks" OR ${tname} STREQUAL "checkers" OR ${tname} STREQUAL "sudoku")
-
-      if (DEFINED RESOURCE_PATH)
-        add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES} ${RESOURCE_PATH})
-        if (${tname} STREQUAL "demo")
-          target_compile_definitions(demo PUBLIC USING_XCODE)
-        endif (${tname} STREQUAL "demo")
-      else ()
         add_executable(${tname} MACOSX_BUNDLE ${srcs} ${FLUID_SOURCES})
-      endif (DEFINED RESOURCE_PATH)
+        foreach(src ${SOURCES})
+            if ("${src}" MATCHES "\\.icns$")
+                FLTK_SET_BUNDLE_ICON(${tname} ${src} )
+            endif ("${src}" MATCHES "\\.icns$")
+        endforeach(src)
     else ()
-      add_executable(${tname} WIN32 ${srcs} ${FLUID_SOURCES})
+        add_executable(${tname} WIN32 ${srcs} ${FLUID_SOURCES})
     endif (APPLE AND NOT OPTION_APPLE_X11)
 
     set_target_properties(${tname}
-      PROPERTIES OUTPUT_NAME ${oname}
+        PROPERTIES OUTPUT_NAME ${oname}
     )
-    if (APPLE AND DEFINED RESOURCE_PATH)
-      if (NOT ${tname} STREQUAL "demo")
-        set_target_properties(${tname} PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
-      endif (NOT ${tname} STREQUAL "demo")
-      set_target_properties(${tname} PROPERTIES RESOURCE ${RESOURCE_PATH})
-    endif (APPLE AND DEFINED RESOURCE_PATH)
-    if (APPLE AND (NOT OPTION_APPLE_X11) AND ${tname} STREQUAL "editor")
-      set_target_properties("editor" PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/ide/Xcode4/plists/editor-Info.plist")
-    endif (APPLE AND (NOT OPTION_APPLE_X11) AND ${tname} STREQUAL "editor")
 
     target_link_libraries(${tname} ${LIBRARIES})
 
-endmacro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
+endfunction(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
 
 #######################################################################
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 11676)
+++ CMakeLists.txt	(working copy)
@@ -25,8 +25,9 @@
 cmake_minimum_required(VERSION 2.6.3)
 
 #######################################################################
-# define some macros
+# define some functions and macros
 #######################################################################
+include(CMake/FLTK-Functions.cmake)
 include(CMake/macros.cmake)
 
 #######################################################################
Index: fluid/CMakeLists.txt
===================================================================
--- fluid/CMakeLists.txt	(revision 11676)
+++ fluid/CMakeLists.txt	(working copy)
@@ -38,22 +38,17 @@
     widget_panel.cxx
 )
 
+set(APPSRC ${CPPFILES})
+
 if(APPLE AND NOT OPTION_APPLE_X11)
-  set( ICON_NAME fluid.icns )
-  set( ICON_PATH "${PROJECT_SOURCE_DIR}/fluid/Fluid.app/Contents/Resources/${ICON_NAME}" )
-  add_executable(fluid MACOSX_BUNDLE ${CPPFILES} ${ICON_PATH})
-else()
-  add_executable(fluid ${CPPFILES})
+  list(APPEND APPSRC "${CMAKE_CURRENT_SOURCE_DIR}/Fluid.app/Contents/Resources/fluid.icns")
 endif(APPLE AND NOT OPTION_APPLE_X11)
 
-target_link_libraries(fluid fltk fltk_images fltk_forms)
+CREATE_EXAMPLE(fluid "${APPSRC}" "fltk;fltk_images;fltk_forms")
 
 # install fluid
 
 if(APPLE AND NOT OPTION_APPLE_X11)
-  # create bundle
-  set_target_properties(fluid PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
-  set_target_properties(fluid PROPERTIES RESOURCE ${ICON_PATH})
   # install
   install(TARGETS fluid DESTINATION ${FLTK_BINDIR})
 else()
Index: test/CMakeLists.txt
===================================================================
--- test/CMakeLists.txt	(revision 11676)
+++ test/CMakeLists.txt	(working copy)
@@ -22,21 +22,40 @@
 CREATE_EXAMPLE(animated animated.cxx fltk)
 CREATE_EXAMPLE(ask ask.cxx fltk)
 CREATE_EXAMPLE(bitmap bitmap.cxx fltk)
-CREATE_EXAMPLE(blocks blocks.cxx "fltk;${AUDIOLIBS}")
+
+CREATE_EXAMPLE(blocks "blocks.cxx;${CMAKE_CURRENT_SOURCE_DIR}/blocks.app/Contents/Resources/blocks.icns"
+  "fltk;${AUDIOLIBS}")
+
 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(checkers "checkers.cxx;${CMAKE_CURRENT_SOURCE_DIR}/checkers.app/Contents/Resources/checkers.icns"
+  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)
+set_target_properties(demo PROPERTIES RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/demo.menu")
+if (CMAKE_VERSION VERSION_LESS 2.8.11)
+#    add_definitions("PRIVATE USING_XCODE") #this does not work at all
+else ()
+    target_compile_definitions(demo PRIVATE USING_XCODE)
+endif (CMAKE_VERSION VERSION_LESS 2.8.11)
+
 CREATE_EXAMPLE(device device.cxx fltk)
 CREATE_EXAMPLE(doublebuffer doublebuffer.cxx fltk)
+
 CREATE_EXAMPLE(editor editor.cxx fltk)
+set_target_properties(editor PROPERTIES 
+    MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/ide/Xcode4/plists/editor-Info.plist"
+    )
+
 CREATE_EXAMPLE(fast_slow fast_slow.fl fltk)
 CREATE_EXAMPLE(file_chooser file_chooser.cxx "fltk;fltk_images")
 CREATE_EXAMPLE(fonts fonts.cxx fltk)
@@ -72,7 +91,10 @@
 CREATE_EXAMPLE(rotated_text rotated_text.cxx fltk)
 CREATE_EXAMPLE(scroll scroll.cxx fltk)
 CREATE_EXAMPLE(subwindow subwindow.cxx fltk)
-CREATE_EXAMPLE(sudoku sudoku.cxx "fltk;fltk_images;${AUDIOLIBS}")
+
+CREATE_EXAMPLE(sudoku "sudoku.cxx;${CMAKE_CURRENT_SOURCE_DIR}/sudoku.app/Contents/Resources/sudoku.icns"
+  "fltk;fltk_images;${AUDIOLIBS}")
+
 CREATE_EXAMPLE(symbols symbols.cxx fltk)
 CREATE_EXAMPLE(tabs tabs.fl fltk)
 CREATE_EXAMPLE(table table.cxx fltk)
