Index: modules/KDE4Macros.cmake
===================================================================
--- modules/KDE4Macros.cmake	(revision 646833)
+++ modules/KDE4Macros.cmake	(working copy)
@@ -811,7 +811,56 @@
 
 endmacro (KDE4_ADD_EXECUTABLE)
 
+macro (KDE4_CREATE_MERGED_FILES _filenameCPP _filesExcludedFromFinalFile )
+   set(${_filesExcludedFromFinalFile})
+   
+   set(_file_const ${CMAKE_CURRENT_BINARY_DIR}/${_filenameCPP}_const.C)
+   set(_file_touched ${CMAKE_CURRENT_BINARY_DIR}/${_filenameCPP}_touched.C)
+   
+   file(WRITE ${_file_const} "//autogenerated file\n")
+   file(WRITE ${_file_touched} "//autogenerated file\n")
+   
+   file(APPEND ${_file_touched} "// touched files\n\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_const}\"\n\n\n")
+   
+   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 ${_filesExcludedFromFinalFile} ${_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 ${_filesExcludedFromFinalFile} ${_abs_FILE})
+         else (_isCFile)
+            file(APPEND ${_filenameCPP} "#include \"${_abs_FILE}\"\n")
+            
+            GET_FILENAME_COMPONENT(_file_name ${_abs_FILE} NAME_WE)
+            STRING(REGEX REPLACE "-" "_" _file_name "${_file_name}" )
+            set(__macro_name ${_file_name}___ASSUME_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")
+            
+            file(APPEND ${_file_touched}  "#ifndef ${__macro_name}\n")
+            file(APPEND ${_file_touched}  "#include \"${_abs_FILE}\"\n")
+            file(APPEND ${_file_touched}  "#endif\n\n")
+            
+         endif (_isCFile)
+      endif (_isGenerated)
+   endforeach (_current_FILE)
 
+endmacro (KDE4_CREATE_MERGED_FILES)
+
+
 macro (KDE4_ADD_LIBRARY _target_NAME _lib_TYPE)
 #is the first argument is "WITH_PREFIX" then keep the standard "lib" prefix, otherwise set the prefix empty
 
@@ -837,7 +886,17 @@
       kde4_create_final_files(${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp _separate_files ${_first_SRC} ${ARGN})
       add_library(${_target_NAME} ${_add_lib_param}  ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp ${_separate_files} ${_automoc_FILES})
    else (KDE4_ENABLE_FINAL)
-      add_library(${_target_NAME} ${_add_lib_param} ${_first_SRC} ${ARGN} ${_automoc_FILES})
+      if (merge_files)
+         KDE4_CREATE_MERGED_FILES(${_target_NAME}_allinone _separate_files ${_first_SRC} ${ARGN})
+         add_library(${_target_NAME} ${_add_lib_param} 
+                ${_separate_files} 
+                ${_automoc_FILES}
+                ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_allinone_const.C
+                ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_allinone_touched.C
+          )
+      else (merge_files)
+         add_library(${_target_NAME} ${_add_lib_param} ${_first_SRC} ${ARGN} ${_automoc_FILES})
+      endif (merge_files)
    endif (KDE4_ENABLE_FINAL)
 
    kde4_handle_rpath_for_library(${_target_NAME})
