Index: KDE4Macros.cmake
===================================================================
--- KDE4Macros.cmake	(revision 752780)
+++ KDE4Macros.cmake	(working copy)
@@ -979,3 +979,98 @@
     endif(WIN32)
 endmacro (KDE4_ADD_WIN32_APP_ICON)
 
+# adds application icon to target source list 
+
+# this macro adds an application icon to the specified target
+# mac osx notes : the application icon is added to a Mac OS X bundle so that Finder and friends show the right thing.
+# win32 notes: the application icon(s) are compiled into the application 
+# parameters: 
+# 'target'         - cmake target to generate 
+# 'appsources' - specifies the list of source files 
+# 'pattern'       - regular expression for searching application icons 
+# example: KDE4_ADD_APP_ICON(myapp myapp_sources "pics/cr*-myapp.png")
+
+macro (KDE4_ADD_APP_ICON target appsources pattern )
+    if (WIN32)
+        find_program(PNG2ICO_EXECUTABLE NAMES png2ico)
+        find_program(WINDRES_EXECUTABLE NAMES windres)
+        if(MSVC)
+            set(WINDRES_EXECUTABLE TRUE)
+        endif(MSVC)        
+        if (PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE)
+            file(GLOB files  "${pattern}")
+            FOREACH (it ${files})
+                GET_FILENAME_COMPONENT(_name ${it} NAME_WE)
+                if (it MATCHES ".*16-.*" )
+                    list (APPEND _icons ${it})
+                endif (it MATCHES ".*16-.*")
+                if (it MATCHES ".*32-.*" )
+                    list (APPEND _icons ${it})
+                endif (it MATCHES ".*32-.*")
+                if (it MATCHES ".*64-.*" )
+                    list (APPEND _icons ${it})
+                endif (it MATCHES ".*64-.*")
+            ENDFOREACH (it)
+            set (_outfilename ${CMAKE_CURRENT_BINARY_DIR}/${target})
+            # requires kdewin32 >= 0.3.4  - is there any way to detect the version of the installed kdewin32 library to avoid using too old versions ? 
+            ADD_CUSTOM_COMMAND(OUTPUT ${_outfilename}.ico ${_outfilename}.rc
+                               COMMAND ${PNG2ICO_EXECUTABLE} ARGS --rcfile ${_outfilename}.rc ${_outfilename}.ico ${_icons}
+                               DEPENDS ${PNG2ICO_EXECUTABLE} ${ARGN}
+                               WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+                              )
+            if (MINGW)
+                ADD_CUSTOM_COMMAND(OUTPUT ${_outfilename}_res.o
+                                   COMMAND ${WINDRES_EXECUTABLE} ARGS -i ${_outfilename}.rc -o ${_outfilename}_res.o --include-dir=${CMAKE_CURRENT_SOURCE_DIR}
+                                   DEPENDS ${WINDRES_EXECUTABLE} ${_outfilename}.rc
+                                   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+                                  )
+                list(APPEND ${appsources} ${_outfilename}_res.o)
+            else(MINGW)
+                list(APPEND ${appsources} ${_outfilename}.rc)
+            endif(MINGW)
+        else(PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE)
+            message(STATUS "Unable to find the png2ico or windres utilities - application will not have an application icon!")
+        endif(PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE)
+    endif(WIN32)
+    if (Q_WS_MAC)
+        # first convert image to a tiff using the Mac OS X "sips" utility,
+        # then use tiff2icns to convert to an icon
+        find_program(SIPS_EXECUTABLE NAMES sips)
+        find_program(TIFF2ICNS_EXECUTABLE NAMES tiff2icns)
+        if (SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
+            file(GLOB files  "${pattern}")
+            FOREACH (it ${files})
+                GET_FILENAME_COMPONENT(_name ${it} NAME_WE)
+                if (it MATCHES ".*128-.*" )
+                    set (_icon ${it})
+                endif (it MATCHES ".*128-.*")
+            ENDFOREACH (it)
+            set (_outfilename ${CMAKE_CURRENT_BINARY_DIR}/${target})
+
+            # first, get the basename of our app icon
+            add_custom_command(OUTPUT ${_outfilename}.icns
+                               COMMAND sips -s format tiff ${_icon} --out _tmp_appicon.tiff
+                               COMMAND tiff2icns _tmp_appicon.tiff ${_outfilename}.icns
+                               DEPENDS ${_icon}
+                               )
+
+            macro_additional_clean_files(_tmp_appicon.tiff ${_outfilename}.icns)
+
+            # This will register the icon into the bundle
+            set(MACOSX_BUNDLE_ICON_FILE ${_outfilename}.icns)
+
+            # Append the icns file to the sources list so it will be a dependency to the
+            # main target
+            list(APPEND ${_appsources} ${_outfilename}.icns)
+
+            #            this doesn't seem to work for me - Use manual "install" instead
+            #            SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${target}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
+
+            install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_outfilename}.icns DESTINATION ${BIN_INSTALL_DIR}/${target}.app/Contents/Resources/)
+
+        else(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
+            message(STATUS "Unable to find the sips and tiff2icns utilities - application will not have an application icon!")
+        endif(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
+    endif(Q_WS_MAC)    
+endmacro (KDE4_ADD_APP_ICON)
+
