Index: cmake/modules/FindKDE4Internal.cmake
===================================================================
--- cmake/modules/FindKDE4Internal.cmake	(revision 659047)
+++ cmake/modules/FindKDE4Internal.cmake	(working copy)
@@ -109,6 +109,7 @@
 # The following user adjustable options are provided:
 #
 # KDE4_ENABLE_FINAL - enable KDE-style enable-final all-in-one-compilation
+# KDE4_ENABLE_MERGED - enable merged files to speed up compiling of untouched files
 # KDE4_BUILD_TESTS  - enable this to build the testcases
 # KDE4_ENABLE_FPIE  - enable it to use gcc Position Independent Executables feature
 #
@@ -148,6 +149,12 @@
 #    one for the C files and one for the C++ files.
 #    These files will have the names given in filename_CXX and filename_C.
 #
+# KDE4_CREATE_MERGERD_FILES (filename_CXX filename_C file1 ... fileN)
+#    This macro is intended mainly for internal uses.
+#    It is used for enable-final. It will generate two source files,
+#    one for the C files and one for the C++ files.
+#    These files will have the names given in filename_CXX and filename_C.
+#
 # KDE4_ADD_PLUGIN ( name [WITH_PREFIX] file1 ... fileN )
 #    Create a KDE plugin (KPart, kioslave, etc.) from the given source files.
 #    It supports KDE4_ENABLE_FINAL.
@@ -306,9 +313,14 @@
 
 
 option(KDE4_ENABLE_FINAL "Enable final all-in-one compilation")
+option(KDE4_ENABLE_MERGED "Enable merged files to speed up compiling of untouched files")
 option(KDE4_BUILD_TESTS  "Build the tests")
 
-if( KDE4_ENABLE_FINAL)
+if(KDE4_ENABLE_MERGED)
+   set(KDE4_ENABLE_FINAL TRUE CACHE TYPE BOOL FORCE)
+endif(KDE4_ENABLE_MERGED)
+
+if(KDE4_ENABLE_FINAL)
    add_definitions(-DKDE_USE_FINAL)
 endif(KDE4_ENABLE_FINAL)
 
Index: cmake/modules/KDE4Macros.cmake
===================================================================
--- cmake/modules/KDE4Macros.cmake	(revision 659047)
+++ cmake/modules/KDE4Macros.cmake	(working copy)
@@ -492,6 +492,8 @@
 ENDMACRO (KDE4_INSTALL_LIBTOOL_FILE)
 
 
+if (NOT KDE4_ENABLE_MERGED)
+
 # For all C++ sources a big source file which includes all the files
 # is created.
 # This is not done for the C sources, they are just gathered in a separate list
@@ -521,6 +523,123 @@
 
 endmacro (KDE4_CREATE_FINAL_FILES)
 
+else (NOT KDE4_ENABLE_MERGED)
+
+macro(KDE4_CREATE_FINAL_FILES _filenameCPP _file_list)
+   # construct filename for the file including all others
+   # e.g: kdecore_final_cpp -> _merged_kdecore_files.cpp
+   GET_FILENAME_COMPONENT(_file_const_we ${_filenameCPP} NAME_WE)
+   string(REGEX REPLACE "_final_cpp" "" _file_const ${_file_const_we})
+   set(_file_const ${CMAKE_CURRENT_BINARY_DIR}/_merged_${_file_const}_files.cpp)
+   
+   # don't touch exisiting or non-empty file,
+   # so a cmake re-run doesn't touch all created files
+   set(_rebuild_file_const 0)
+   if (NOT EXISTS ${_file_const})
+      set(_rebuild_file_const 1)
+   else (NOT EXISTS ${_file_const})
+      FILE(READ ${_file_const} _file_content)
+      if (NOT _file_content)
+         set(_rebuild_file_const 1)
+      endif (NOT _file_content)
+   endif (NOT EXISTS ${_file_const})
+   
+   if (KDE4_MERGED_REBUILD)
+      set(_rebuild_file_const 1)
+   endif (KDE4_MERGED_REBUILD)
+   
+   if (_rebuild_file_const)
+      file(WRITE  ${_file_const} "// autogenerated file \n//\n")
+      file(APPEND ${_file_const} "//   * clear or delete this file to build it again by a cmake run\n//\n")
+      file(APPEND ${_file_const} "//   * This file is the master file of the merged-file build.\n")
+      file(APPEND ${_file_const} "//     In this file all files are included which could be assumed as untouched. \n")
+      file(APPEND ${_file_const} "//     By default this file includes all files, as it is done by the KDE4_ENABLE_FINAL build. \n")
+      file(APPEND ${_file_const} "//     The difference to the KDE4_ENABLE_FINAL build is that it is possible to exclude \n")
+      file(APPEND ${_file_const} "//     source files from this file. By this it is possible to work on these files without \n")
+      file(APPEND ${_file_const} "//     losing the advantage of the faster compilation of the KDE4_ENABLE_FINAL build. \n//\n")
+      file(APPEND ${_file_const} "//   * To compile a file separately suppress the including in this file \n")
+      file(APPEND ${_file_const} "//     and comment out the corresponding macro definition, for instance: \n//\n")
+      file(APPEND ${_file_const} "//        //#define kdesktopfile___ASSUME_CONST \n")
+      file(APPEND ${_file_const} "//        #if defined(kdesktopfile___ASSUME_CONST) && !defined(DONT_INCLUDE_CONST_FILES) \n")
+      file(APPEND ${_file_const} "//        //#include \"/home/user_name/kde/kdelibs/kdecore/config/kdesktopfile.cpp\" \n")
+      file(APPEND ${_file_const} "//        #endif  \n//\n")
+      file(APPEND ${_file_const} "//     or just delete these lines. \n//\n\n")      
+   endif (_rebuild_file_const)
+   
+   # empty file for backward compatibility
+   if (NOT EXISTS ${_filenameCPP})
+      file(WRITE ${_filenameCPP} "// autogenerated empty backward compatibility file\n")
+   endif (NOT EXISTS ${_filenameCPP})
+   
+   set(${_file_list} ${_file_const})
+   set(_file_header ${_file_const})
+  
+   foreach (_current_FILE ${ARGN})
+      get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
+      # don't include any generated files in the final-file
+      # because then cmake will not know the dependencies
+      get_source_file_property(_isGenerated ${_abs_FILE} GENERATED)
+      if (_isGenerated)
+         list(APPEND ${_file_list} ${_abs_FILE})
+      else (_isGenerated)
+         # don't include c-files in the final-file, because they usually come
+         # from a 3rd party and as such are not intended to be compiled all-in-one
+         string(REGEX MATCH ".+\\.c$" _isCFile ${_abs_FILE})
+         if (_isCFile)
+            list(APPEND ${_file_list} ${_abs_FILE})
+         else (_isCFile)
+           GET_FILENAME_COMPONENT(_file_name ${_abs_FILE} NAME_WE)
+           STRING(REGEX REPLACE "-" "_" _file_name "${_file_name}" )
+           set(__macro_name ${_file_name}___ASSUME_CONST)
+        
+           if (_rebuild_file_const)
+              file(APPEND ${_file_const}  "#define ${__macro_name} \n")
+              file(APPEND ${_file_const}  "#if defined(${__macro_name}) && !defined(DONT_INCLUDE_CONST_FILES) \n")
+              file(APPEND ${_file_const}  "#include \"${_abs_FILE}\" \n")
+              file(APPEND ${_file_const}  "#endif \n\n")
+              #message(STATUS "_rebuild_file_const  : adding macro ${__macro_name}")
+           endif (_rebuild_file_const)
+        
+           set(_file_touched ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}_touched.cpp)                    
+           set(_rebuild_file_touched 0)
+           if (NOT EXISTS ${_file_touched})
+              set(_rebuild_file_touched 1)
+           else (NOT EXISTS ${_file_touched})
+              FILE(READ ${_file_touched} _file_content)
+              if (NOT _file_content)
+                 set(_rebuild_file_touched 1)
+              endif (NOT _file_content)   
+           endif (NOT EXISTS ${_file_touched})
+           
+           if (KDE4_MERGED_REBUILD)
+              set(_rebuild_file_touched 1)
+           endif (KDE4_MERGED_REBUILD)
+   
+           if (_rebuild_file_touched)
+              file(WRITE  ${_file_touched} "// autogenerated file \n//\n")
+              file(APPEND ${_file_touched} "//    * clear or delete this file to build it again by cmake \n//\n")
+              file(APPEND ${_file_touched} "//    * don't touch this file compile separately the code included by this file. \n")
+              file(APPEND ${_file_touched} "//      change ${_file_const}, see explanation there. \n\n")
+		      file(APPEND ${_file_touched} "// look for touched  files \n")
+		      file(APPEND ${_file_touched} "#define DONT_INCLUDE_CONST_FILES \n")
+		      file(APPEND ${_file_touched} "#include \"${_file_header}\" \n\n")
+              file(APPEND ${_file_touched} "#ifndef ${__macro_name} \n")
+              file(APPEND ${_file_touched} "#include \"${_abs_FILE}\" \n")
+              file(APPEND ${_file_touched} "#endif \n\n")
+              set_source_files_properties(${_file_touched} PROPERTIES OBJECT_DEPENDS ${_file_const})
+              #message(STATUS "_rebuild_file_touched: adding file  ${_file_touched}")
+           endif (_rebuild_file_touched)          
+           
+           set(${_file_list} ${${_file_list}} ${_file_touched})
+           
+        endif (_isCFile)
+          
+      endif (_isGenerated)
+   endforeach (_current_FILE)
+endmacro (KDE4_CREATE_FINAL_FILES)
+
+endif (NOT KDE4_ENABLE_MERGED)
+
 # This macro sets the RPATH related options for libraries, plugins and kdeinit executables.
 # It overrides the defaults set in FindKDE4Internal.cmake.
 # If RPATH is not explicitely disabled, libraries and plugins are built without RPATH, in
