Index: cmake/modules/KDE4Macros.cmake
===================================================================
--- cmake/modules/KDE4Macros.cmake	(revision 656724)
+++ cmake/modules/KDE4Macros.cmake	(working copy)
@@ -491,7 +491,9 @@
    INSTALL(FILES ${_laname} DESTINATION ${_subdir})
 ENDMACRO (KDE4_INSTALL_LIBTOOL_FILE)
 
+set(ENABLE_OLD_IMPL 0)
 
+if(ENABLE_OLD_IMPL)
 # 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,92 @@
 
 endmacro (KDE4_CREATE_FINAL_FILES)
 
+else(ENABLE_OLD_IMPL)
+
+macro(KDE4_CREATE_FINAL_FILES _filenameCPP _file_list)
+   GET_FILENAME_COMPONENT(_file_const ${_filenameCPP} NAME_WE)
+   set(_file_const ${CMAKE_CURRENT_BINARY_DIR}/_all_${_file_const}.cpp)
+   
+   # don't touch exisiting or non-empty file
+   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 (_rebuild_file_const)
+      file(WRITE ${_file_const} "// autogenerated file\n// clear it to build it again by cmake\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 (_rebuild_file_touched)
+              file(WRITE ${_file_touched} "// autogenerated file\n// clear it to build it again by cmake\n")
+		      file(APPEND ${_file_touched} "// look for non-const 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")
+              #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(ENABLE_OLD_IMPL)
+
 # 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
