diff --git a/CMake/FLTK-Functions.cmake b/CMake/FLTK-Functions.cmake
new file mode 100644
index 0000000..03fc3a3
--- /dev/null
+++ b/CMake/FLTK-Functions.cmake
@@ -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
+        RESOURCE "${ICON_PATH}"
+        MACOSX_BUNDLE_ICON_FILE "${ICON_NAME}"
+    )
+endfunction(FLTK_SET_BUNDLE_ICON TARGET ICON_PATH)
diff --git a/CMake/macros.cmake b/CMake/macros.cmake
index 057c267..f75f936 100644
--- a/CMake/macros.cmake
+++ b/CMake/macros.cmake
@@ -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,26 +82,7 @@ macro(FL_ADD_LIBRARY LIBNAME LIBTYPE LIBFILES)
 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)
-
-#######################################################################
-macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
+function(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
 
     set (srcs)			# source files
     set (flsrcs)		# fluid source files
@@ -124,45 +105,21 @@ macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
 
     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)
     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)
 
 #######################################################################
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4015f28..3ad9d17 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,8 +25,9 @@ project(FLTK)
 cmake_minimum_required(VERSION 2.6.3)
 
 #######################################################################
-# define some macros
+# define some functions and macros
 #######################################################################
+include(CMake/FLTK-Functions.cmake)
 include(CMake/macros.cmake)
 
 #######################################################################
diff --git a/fluid/CMakeLists.txt b/fluid/CMakeLists.txt
index 3320c1c..e58a237 100644
--- a/fluid/CMakeLists.txt
+++ b/fluid/CMakeLists.txt
@@ -40,10 +40,10 @@ set(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}" )
+  set( ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Fluid.app/Contents/Resources/${ICON_NAME}" )
   add_executable(fluid MACOSX_BUNDLE ${CPPFILES} ${ICON_PATH})
 else()
-  add_executable(fluid ${CPPFILES})
+  add_executable(fluid WIN32 ${CPPFILES})
 endif(APPLE AND NOT OPTION_APPLE_X11)
 
 target_link_libraries(fluid fltk fltk_images fltk_forms)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index fbef50b..7487546 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -22,21 +22,36 @@ CREATE_EXAMPLE(arc arc.cxx fltk)
 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}")
+FLTK_SET_BUNDLE_ICON(blocks "${CMAKE_CURRENT_SOURCE_DIR}/blocks.app/Contents/Resources/blocks.icns}" )
+
 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)
+FLTK_SET_BUNDLE_ICON(checkers "${CMAKE_CURRENT_SOURCE_DIR}/checkers.app/Contents/Resources/checkers.icns}" )
+
 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")
+target_compile_definitions(demo PRIVATE USING_XCODE)
+
 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 +87,10 @@ CREATE_EXAMPLE(resizebox resizebox.cxx fltk)
 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}")
+FLTK_SET_BUNDLE_ICON(sudoku "${CMAKE_CURRENT_SOURCE_DIR}/sudoku.app/Contents/Resources/sudoku.icns}" )
+
 CREATE_EXAMPLE(symbols symbols.cxx fltk)
 CREATE_EXAMPLE(tabs tabs.fl fltk)
 CREATE_EXAMPLE(table table.cxx fltk)
