diff --git a/CMake/FLTKfunctions.cmake b/CMake/FLTKfunctions.cmake
new file mode 100644
index 0000000..9e13016
--- /dev/null
+++ b/CMake/FLTKfunctions.cmake
@@ -0,0 +1,95 @@
+#
+# "$Id$"
+#
+# FLTKfunctions.cmake defines macros used by the build system
+# 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 to be exported for 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)
+
+#######################################################################
+# called for Mac bundle handling
+function(FLTK_ADD_BUNDLE NAME RESOURCE_FILES PLIST DEFINITIONS)
+
+    if (APPLE OR USE_X11)
+
+	message(STATUS "FLTK_ADD_BUNDLE '${NAME}' '${RESOURCE_FILES}' '${PLIST}' '${DEFINITIONS}'")
+        set_target_properties("${NAME}" PROPERTIES MACOSX_BUNDLE TRUE)
+
+        set(ICON_NAME "${NAME}.icns")
+	message(STATUS "ICON_NAME = '${ICON_NAME}'")
+
+        if (RESOURCE_FILES)
+            foreach(RESOURCE_FILE IN LISTS RESOURCE_FILES)
+		message(STATUS "	find_file(RES '${RESOURCE_FILE}')")
+                find_file(RES "${RESOURCE_FILE}")
+                if (RES)
+		    message(STATUS "	set_target_properties('${NAME}' PROPERTIES RESOURCE '${RES}')")
+                    set_target_properties("${NAME}" PROPERTIES RESOURCE "${RES}")
+                endif (RES)
+                get_filename_component(RESOURCE_PATH "${RESOURCE_FILE}" DIRECTORY)
+		if (CMAKE_VERSION VERSION_LESS 2.8.11)
+		  message(STATUS "	include_directories('${RESOURCE_PATH}')")
+		  include_directories("${RESOURCE_PATH}")
+		else ()
+		  message(STATUS "	target_include_directories('${NAME}' PRIVATE '${RESOURCE_PATH}')")
+		  target_include_directories("${NAME}" PRIVATE "${RESOURCE_PATH}")
+		endif (CMAKE_VERSION VERSION_LESS 2.8.11)
+
+                find_file(ICON_FILE "${ICON_NAME}" "${RESOURCE_PATH}")
+                if (ICON_FILE)
+		    message(STATUS "	set_target_properties('${NAME}' PROPERTIES MACOSX_BUNDLE_ICON_FILE '${ICON_NAME}')")
+                    set_target_properties("${NAME}" PROPERTIES MACOSX_BUNDLE_ICON_FILE "${ICON_NAME}")
+                endif (ICON_FILE)
+            endforeach(RESOURCE_FILE IN LISTS RESOURCE_LIST)
+        endif (RESOURCE_FILES)
+
+        if (DEFINITIONS)
+	  if (CMAKE_VERSION VERSION_LESS 2.8.11)
+	    message(STATUS "	add_definitions('${DEFINITIONS}')")
+            add_definitions("${DEFINITIONS}")
+	  else ()
+	    message(STATUS "	target_compile_definitions('${NAME}' PRIVATE '${DEFINITIONS}')")
+            target_compile_definitions("${NAME}" PRIVATE "${DEFINITIONS}")
+	  endif (CMAKE_VERSION VERSION_LESS 2.8.11)
+        endif (DEFINITIONS)
+
+        if (PLIST)
+	    message(STATUS "	set_target_properties('${NAME}' PROPERTIES MACOSX_BUNDLE_INFO_PLIST '${PLIST}')")
+	    set_target_properties("${NAME}" PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${PLIST}")
+        endif (PLIST)
+
+    endif (APPLE OR USE_X11)
+
+endfunction(FLTK_ADD_BUNDLE NAME RESOURCE_FILES PLIST DEFINITIONS)
diff --git a/CMake/macros.cmake b/CMake/macros.cmake
index 057c267..eda3788 100644
--- a/CMake/macros.cmake
+++ b/CMake/macros.cmake
@@ -82,25 +82,6 @@ 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)
 
     set (srcs)			# source files
@@ -110,8 +91,10 @@ macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
     set (oname ${NAME})		# output (executable) name
 
     # rename reserved target name "help" (CMake 2.8.12 and later)
+    # FIXME: this must be removed in FLTK 1.4.0 by renaming
+    # help.cxx to helpview.cxx and related changes (demo.menu etc.)
     if (${tname} MATCHES "^help$")
-        set (tname "test_help")
+        set (tname "helpview")
     endif (${tname} MATCHES "^help$")
 
     foreach(src ${SOURCES})
@@ -127,42 +110,23 @@ macro(CREATE_EXAMPLE NAME SOURCES LIBRARIES)
 	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})
-    endif (APPLE AND NOT OPTION_APPLE_X11)
+    add_executable(${tname} WIN32 ${srcs} ${FLUID_SOURCES})
 
     set_target_properties(${tname}
       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)
 
 #######################################################################
+function(internal_ADD_BUNDLE NAME RESOURCE_FILES plist DEFINITIONS)
+
+  if (NOT OPTION_APPLE_X11)
+
+    FLTK_ADD_BUNDLE("${NAME}" "${RESOURCE_FILES}" "${plist}" "${DEFINITIONS}")
+
+  endif (NOT OPTION_APPLE_X11)
+
+endfunction(internal_ADD_BUNDLE NAME RESOURCE_FILES plist DEFINITIONS)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4015f28..03a573b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,7 @@ cmake_minimum_required(VERSION 2.6.3)
 #######################################################################
 # define some macros
 #######################################################################
+include(CMake/FLTKfunctions.cmake)
 include(CMake/macros.cmake)
 
 #######################################################################
diff --git a/fluid/CMakeLists.txt b/fluid/CMakeLists.txt
index 3320c1c..eda64f5 100644
--- a/fluid/CMakeLists.txt
+++ b/fluid/CMakeLists.txt
@@ -38,32 +38,19 @@ set(CPPFILES
     widget_panel.cxx
 )
 
-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})
-endif(APPLE AND NOT OPTION_APPLE_X11)
+add_executable(fluid WIN32 ${CPPFILES})
+internal_ADD_BUNDLE(fluid ${CMAKE_CURRENT_SOURCE_DIR}/Fluid.app/Contents/Resources/fluid.icns "" "")
 
 target_link_libraries(fluid 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()
-  install(TARGETS fluid
+install(TARGETS fluid
     EXPORT FLTK-Targets
     RUNTIME DESTINATION ${FLTK_BINDIR}
     LIBRARY DESTINATION ${FLTK_LIBDIR}
     ARCHIVE DESTINATION ${FLTK_LIBDIR}
+    BUNDLE  DESTINATION ${FLTK_BINDIR}
     )
-endif(APPLE AND NOT OPTION_APPLE_X11)
 
 # install desktop files
 
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index fbef50b..406df2f 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -23,17 +23,20 @@ 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}")
+internal_ADD_BUNDLE(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)
+internal_ADD_BUNDLE(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)
+internal_ADD_BUNDLE(demo "${CMAKE_CURRENT_SOURCE_DIR}/demo.menu" "" "USING_XCODE")
 CREATE_EXAMPLE(device device.cxx fltk)
 CREATE_EXAMPLE(doublebuffer doublebuffer.cxx fltk)
 CREATE_EXAMPLE(editor editor.cxx fltk)
@@ -42,6 +45,7 @@ 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)
+# FIXME: rename reserved target name "help" to "helpview" in FLTK 1.4.0
 CREATE_EXAMPLE(help help.cxx "fltk;fltk_images")
 CREATE_EXAMPLE(icon icon.cxx fltk)
 CREATE_EXAMPLE(iconize iconize.cxx fltk)
@@ -73,6 +77,7 @@ 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}")
+internal_ADD_BUNDLE(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)
