On Wednesday 27 June 2007, Alexander Neundorf wrote:
> Could you maybe measure cmake times with the old and the new one with cold
> and warm caches ?

Measuring is almost impossible. Using
time cmake
I get +/- 50% on total time. But here are the numbers:

old automoc:
without cache: 39.47s user 12.53s system 36% cpu 2:22.32 total
with    cache: 16.59s user  2.62s system 26% cpu 1:13.69 total

new automoc as from Alex's patch:
without cache: 38.78s user 12.06s system 32% cpu 2:38.27 total
with    cache: 16.15s user  3.01s system 18% cpu 1:42.67 total

reworked patch:
without cache: 39.01s user 11.80s system 34% cpu 2:26.86 total
with    cache: 16.03s user  2.75s system 20% cpu 1:32.07 total

without cache means:
% rm CMakeCache.txt
% time cmake -DCMAK... ../../src/kdelibs

with cache:
% time cmake ./

Anyway, I changed quite a bit:
1. don't create _automoc.files files anymore; instead pass all the variables 
on the command line to kde4automoc.cmake. I did this in order to save on IO 
at cmake time. (Optimizing cmake performance is guesswork or do you have any 
way to gather better data?)

2. I added KDE4_MOC_HEADERS that takes the target and a list of header files. 
The headers are then moc'ed and the resulting moc_foo.cpp file is added to 
the list of source files of the given target.

3. If kde4automoc.cmake is given a header file then it will simply create a 
moc_foo.cpp file from it (might result in an empty file).

4. kde4automoc.cmake now recreates the moc file if only the header was changed

5. tried unsuccessfully to make kde4automoc.cmake show "Automoc: Generating 
${_moc} from ${_moc_source}" in color

6. the _automoc.mark file is now only used for a timestamp, the variables that 
were written to it and later read from it again are now used directly

7. If the .cpp file contains #include "<filename>.moc" and ^[ \t]*Q_OBJECT 
then the moc file is created from the .cpp file

So far I tested it with kdelibs only.

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
[EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED]
Index: KDE4Macros.cmake
===================================================================
--- KDE4Macros.cmake	(revision 680441)
+++ KDE4Macros.cmake	(working copy)
@@ -5,6 +5,11 @@
 # KDE4_ADD_UI3_FILES
 # KDE4_ADD_KCFG_FILES
 # KDE4_AUTOMOC
+# KDE4_SET_CUSTOM_TARGET_PROPERTY
+# KDE4_GET_CUSTOM_TARGET_PROPERTY
+# KDE4_MOC_HEADERS
+# KDE4_APPEND_MOC_FILES
+# KDE4_HANDLE_AUTOMOC
 # KDE4_INSTALL_LIBTOOL_FILE
 # KDE4_CREATE_FINAL_FILES
 # KDE4_ADD_KDEINIT_EXECUTABLE
@@ -22,6 +27,7 @@
 
 # Copyright (c) 2006, 2007, Alexander Neundorf, <[EMAIL PROTECTED]>
 # Copyright (c) 2006, 2007, Laurent Montel, <[EMAIL PROTECTED]>
+# Copyright (c) 2007 Matthias Kretz <[EMAIL PROTECTED]>
 #
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
@@ -145,77 +151,79 @@
    endforeach (_current_FILE)
 endmacro (KDE4_ADD_UI3_FILES)
 
-
+# keep it here until it is removed everywhere
 macro (KDE4_AUTOMOC)
-   qt4_get_moc_inc_dirs(_moc_INCS)
+endmacro (KDE4_AUTOMOC)
 
-   # iterate over all  files
-   foreach (_current_FILE ${ARGN})
+macro (KDE4_SET_CUSTOM_TARGET_PROPERTY _target_name _property_name _property)
+   string(REPLACE "[/ ]" "_" _dir "${CMAKE_CURRENT_SOURCE_DIR}")
+   set(_kde4_${_dir}_${_target_name}_${_property_name} "${_property}")
+endmacro (KDE4_SET_CUSTOM_TARGET_PROPERTY)
 
-      get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
-      # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
-      # here. this is required to make bouic work correctly:
-      # we need to add generated .cpp files to the sources (to compile them),
-      # but we cannot let automoc handle them, as the .cpp files don't exist yet when
-      # cmake is run for the very first time on them -> however the .cpp files might
-      # exist at a later run. at that time we need to skip them, so that we don't add two
-      # different rules for the same moc file
-      get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC)
+macro (KDE4_GET_CUSTOM_TARGET_PROPERTY _var _target_name _property_name)
+   string(REPLACE "[/ ]" "_" _dir "${CMAKE_CURRENT_SOURCE_DIR}")
+   set(${_var} "${_kde4_${_dir}_${_target_name}_${_property_name}}")
+endmacro (KDE4_GET_CUSTOM_TARGET_PROPERTY)
 
-      # if the file exists and should not be skipped read it completely into memory
-      # and grep for all include <foo.moc> lines
-      # for each found moc file generate a custom_target and collect
-      # the generated moc files in a list which will be set as a source files property
-      # and later be queried in kde4_add_library/executable/plugin()
-      if (EXISTS ${_abs_FILE} AND NOT _skip)
-         set(_moc_FILES_PROPERTY)
+macro (KDE4_MOC_HEADERS _target_NAME)
+   set (_headers_to_moc)
+   foreach (_current_FILE ${ARGN})
+      get_filename_component(_suffix "${_current_FILE}" EXT)
+      if (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
+         set (_headers_to_moc ${_headers_to_moc} ${_current_FILE})
+      else (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
+         message(STATUS "KDE4_MOC_HEADERS: ignoring non-header file ${_current_FILE}")
+      endif (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
+   endforeach (_current_FILE)
+   # need to create moc_<filename>.cpp file using kde4automoc.cmake
+   # and add it to the target
+   if(_headers_to_moc)
+      KDE4_SET_CUSTOM_TARGET_PROPERTY(${_target_NAME} AUTOMOC_HEADERS "${_headers_to_moc}")
+   endif(_headers_to_moc)
+endmacro (KDE4_MOC_HEADERS)
 
-         file(READ ${_abs_FILE} _contents)
-         get_filename_component(_abs_PATH ${_abs_FILE} PATH)
+macro(KDE4_APPEND_MOC_FILES _target_name _list)
+   KDE4_GET_CUSTOM_TARGET_PROPERTY(_headers_to_moc ${_target_name} AUTOMOC_HEADERS)
+   if(NOT _headers_to_moc STREQUAL "NOTFOUND")
+      foreach (_current_FILE ${_headers_to_moc})
+         get_filename_component(_basename "${_current_FILE}" NAME_WE)
+         set(_moc "${CMAKE_CURRENT_BINARY_DIR}/moc_${_basename}.cpp")
+         set_source_files_properties(${_moc} PROPERTIES GENERATED TRUE)
+         set(${_list} ${${_list}} ${_moc})
+      endforeach (_current_FILE)
+   endif(NOT _headers_to_moc STREQUAL "NOTFOUND")
+endmacro(KDE4_APPEND_MOC_FILES _list)
 
-         string(REGEX MATCHALL "#include +[^ ]+\\.moc[\">]" _match "${_contents}")
-         if (_match)
-            foreach (_current_MOC_INC ${_match})
-               string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
-               get_filename_component(_basename ${_current_MOC} NAME_WE)
-               set(_header ${_abs_PATH}/${_basename}.h)
-               set(_moc    ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
+macro(KDE4_HANDLE_AUTOMOC _target_NAME)
+   KDE4_GET_CUSTOM_TARGET_PROPERTY(_headers_to_moc ${_target_NAME} AUTOMOC_HEADERS)
+   if(_headers_to_moc STREQUAL "NOTFOUND")
+      set(_headers_to_moc)
+   endif(_headers_to_moc STREQUAL "NOTFOUND")
+   foreach (_current_FILE ${_headers_to_moc} ${ARGN})
+      get_filename_component(_abs_current_FILE "${_current_FILE}" ABSOLUTE)
+      get_source_file_property(_skip "${_abs_current_FILE}" SKIP_AUTOMOC)
+      get_source_file_property(_generated "${_abs_current_FILE}" GENERATED)
 
-               if (NOT EXISTS ${_abs_PATH}/${_basename}.h)
-                  message(FATAL_ERROR "In the file \"${_abs_FILE}\" the moc file \"${_current_MOC}\" is included, but \"${_abs_PATH}/${_basename}.h\" doesn't exist.")
-               endif (NOT EXISTS ${_abs_PATH}/${_basename}.h)
+      if(NOT _generated AND NOT _skip)
+         get_filename_component(_basename "${_current_FILE}" NAME)
+         macro_additional_clean_files("${CMAKE_CURRENT_BINARY_DIR}/${_basename}_automoc.mark")
+         set(_moc_files "${_moc_files}\;${_abs_current_FILE}")
+      endif(NOT _generated AND NOT _skip)
+   endforeach (_current_FILE)
 
-               add_custom_command(OUTPUT ${_moc}
-                  COMMAND ${QT_MOC_EXECUTABLE}
-                  ARGS ${_moc_INCS} ${_header} -o ${_moc}
-                  MAIN_DEPENDENCY ${_header}
+   qt4_get_moc_inc_dirs(_moc_INCS)
+   add_custom_target(${_target_NAME}_automoc
+                    COMMAND ${CMAKE_COMMAND}
+                      -DKDE4_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
+                      -DQT_MOC_EXECUTABLE=${QT_MOC_EXECUTABLE}
+                      -DQT_MOC_INCS="${_moc_INCS}"
+                      -DMOC_FILES="${_moc_files}"
+                      -DCOLOR=$(COLOR)
+                      -P ${KDE4_MODULE_DIR}/kde4automoc.cmake
                )
+   add_dependencies(${_target_NAME} ${_target_NAME}_automoc)
+endmacro(KDE4_HANDLE_AUTOMOC)
 
-               list(APPEND _moc_FILES_PROPERTY ${_moc})
-
-            endforeach (_current_MOC_INC)
-         endif (_match)
-
-         set_source_files_properties(${_abs_FILE} PROPERTIES AUTOMOC_FILES "${_moc_FILES_PROPERTY}")
-      endif (EXISTS ${_abs_FILE} AND NOT _skip)
-   endforeach (_current_FILE)
-endmacro (KDE4_AUTOMOC)
-
-
-macro(KDE4_GET_AUTOMOC_FILES _list)
-   set(${_list})
-   foreach (_current_FILE ${ARGN})
-      set(_automoc_FILES_PROPERTY)
-      get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
-      get_source_file_property(_automoc_FILES_PROPERTY ${_abs_FILE} AUTOMOC_FILES)
-      if (_automoc_FILES_PROPERTY)
-         foreach (_current_MOC_FILE ${_automoc_FILES_PROPERTY})
-            list(APPEND ${_list} ${_current_MOC_FILE})
-         endforeach (_current_MOC_FILE)
-      endif (_automoc_FILES_PROPERTY)
-   endforeach (_current_FILE)
-endmacro(KDE4_GET_AUTOMOC_FILES)
-
 macro(KDE4_CREATE_PO_FILES)
    set(_list_gmo)
    file(GLOB _po_files *.po)
@@ -631,19 +639,20 @@
       set(_first_SRC ${_with_PREFIX})
    endif (${_with_PREFIX} STREQUAL "WITH_PREFIX")
 
-   kde4_get_automoc_files(_automoc_FILES ${_first_SRC} ${ARGN})
-
+   set(_SRCS ${_first_SRC} ${ARGN})
+   kde4_append_moc_files(${_target_NAME} _SRCS)
    if (KDE4_ENABLE_FINAL)
-      kde4_create_final_files(${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp _separate_files ${_first_SRC} ${ARGN})
-      add_library(${_target_NAME} MODULE  ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp ${_separate_files} ${_automoc_FILES})
+      kde4_create_final_files(${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp _separate_files ${_SRCS})
+      add_library(${_target_NAME} MODULE  ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp ${_separate_files})
    else (KDE4_ENABLE_FINAL)
-      add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN} ${_automoc_FILES})
+      add_library(${_target_NAME} MODULE ${_SRCS})
    endif (KDE4_ENABLE_FINAL)
 
    if (_first_SRC)
       set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
    endif (_first_SRC)
 
+   kde4_handle_automoc(${_target_NAME} ${_SRCS})
    kde4_handle_rpath_for_library(${_target_NAME})
 
    if (WIN32)
@@ -718,16 +727,17 @@
 #      KDE4_ADD_EXECUTABLE(${_target_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp ${ARGN} )
 #   else (WIN32)
       # under UNIX, create a shared library and a small executable, which links to this library
-   kde4_get_automoc_files(_automoc_FILES ${_SRCS})
 
+   kde4_append_moc_files(${_target_NAME} _SRCS)
    if (KDE4_ENABLE_FINAL)
       kde4_create_final_files(${CMAKE_CURRENT_BINARY_DIR}/kdeinit_${_target_NAME}_final_cpp.cpp _separate_files ${_SRCS})
-      add_library(kdeinit_${_target_NAME} SHARED  ${CMAKE_CURRENT_BINARY_DIR}/kdeinit_${_target_NAME}_final_cpp.cpp ${_separate_files} ${_automoc_FILES})
+      add_library(kdeinit_${_target_NAME} SHARED  ${CMAKE_CURRENT_BINARY_DIR}/kdeinit_${_target_NAME}_final_cpp.cpp ${_separate_files})
 
    else (KDE4_ENABLE_FINAL)
-      add_library(kdeinit_${_target_NAME} SHARED ${_SRCS} ${_automoc_FILES})
+      add_library(kdeinit_${_target_NAME} SHARED ${_SRCS})
    endif (KDE4_ENABLE_FINAL)
 
+   kde4_handle_automoc(kdeinit_${_target_NAME} ${_SRCS})
    kde4_handle_rpath_for_library(kdeinit_${_target_NAME})
    set_target_properties(kdeinit_${_target_NAME} PROPERTIES OUTPUT_NAME kdeinit4_${_target_NAME})
 
@@ -778,15 +788,17 @@
 
    set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
 
-   kde4_get_automoc_files(_automoc_FILES ${ARGN})
+   set(_SRCS ${ARGN})
+   kde4_append_moc_files(${_target_NAME} _SRCS)
+   add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS})
 
-   add_executable(${_target_NAME} ${_add_executable_param} ${ARGN} ${_automoc_FILES})
-
    set_target_properties(${_target_NAME} PROPERTIES
                          COMPILE_FLAGS -DKDESRCDIR=\\"${CMAKE_CURRENT_SOURCE_DIR}\\"
                          SKIP_BUILD_RPATH FALSE
                          BUILD_WITH_INSTALL_RPATH FALSE)
 
+   kde4_handle_automoc(${_target_NAME} ${_SRCS})
+
    if (WIN32)
       target_link_libraries(${_target_NAME} ${QT_QTMAIN_LIBRARY})
    endif (WIN32)
@@ -821,15 +833,15 @@
       set(_type "RUN_UNINSTALLED")
    endif (_uninst)
 
-   kde4_get_automoc_files(_automoc_FILES ${_SRCS})
-
+   kde4_append_moc_files(${_target_NAME} _SRCS)
    if (KDE4_ENABLE_FINAL)
       kde4_create_final_files(${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp _separate_files ${_SRCS})
-      add_executable(${_target_NAME} ${_add_executable_param} ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp ${_separate_files} ${_automoc_FILES})
+      add_executable(${_target_NAME} ${_add_executable_param} ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp ${_separate_files})
    else (KDE4_ENABLE_FINAL)
-      add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS} ${_automoc_FILES})
+      add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS})
    endif (KDE4_ENABLE_FINAL)
 
+   kde4_handle_automoc(${_target_NAME} ${_SRCS})
    kde4_handle_rpath_for_executable(${_target_NAME} ${_type})
 
    if (WIN32)
@@ -858,15 +870,16 @@
       set(_add_lib_param MODULE)
    endif (${_lib_TYPE} STREQUAL "MODULE")
 
-   kde4_get_automoc_files(_automoc_FILES ${_first_SRC} ${ARGN})
-
+   set(_SRCS ${_first_SRC} ${ARGN})
+   kde4_append_moc_files(${_target_NAME} _SRCS)
    if (KDE4_ENABLE_FINAL)
-      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})
+      kde4_create_final_files(${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp _separate_files ${_SRCS})
+      add_library(${_target_NAME} ${_add_lib_param}  ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_final_cpp.cpp ${_separate_files})
    else (KDE4_ENABLE_FINAL)
-      add_library(${_target_NAME} ${_add_lib_param} ${_first_SRC} ${ARGN} ${_automoc_FILES})
+      add_library(${_target_NAME} ${_add_lib_param} ${_SRCS})
    endif (KDE4_ENABLE_FINAL)
 
+   kde4_handle_automoc(${_target_NAME} ${_SRCS})
    kde4_handle_rpath_for_library(${_target_NAME})
 
    if (WIN32)
Index: kde4automoc.cmake
===================================================================
--- kde4automoc.cmake	(revision 680441)
+++ kde4automoc.cmake	(working copy)
@@ -1,76 +1,79 @@
 # do the automoc handling 
 
 # Copyright (c) 2006, Alexander Neundorf, <[EMAIL PROTECTED]>
+# Copyright (c) 2007, Matthias Kretz, <[EMAIL PROTECTED]>
 #
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 
-include(${KDE4_AUTOMOC_FILE})
+macro (generate_moc _moc_source _current_MOC)
+   set(_moc ${KDE4_CURRENT_BINARY_DIR}/${_current_MOC})
 
-macro(PARSE_ONE_FILE _filename _moc_mark_FILE)
-   if ("${_filename}" IS_NEWER_THAN "${_moc_mark_FILE}")
-      file(WRITE "${_moc_mark_FILE}" "#file is autogenerated, do not edit\n")
+   if ("${_moc_source}" IS_NEWER_THAN "${_moc}")
+      # why does cmake not show the color?
+      #execute_process(COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --switch=${COLOR} --blue --bold "Automoc: Generating ${_moc} from ${_moc_source}")
+      message(STATUS "Automoc: Generating ${_moc} from ${_moc_source}")
+      execute_process(COMMAND ${QT_MOC_EXECUTABLE} ${QT_MOC_INCS} ${_moc_source} -o ${_moc})
+   endif ("${_moc_source}" IS_NEWER_THAN "${_moc}")
+endmacro (generate_moc)
 
-      file(READ "${_filename}" _contents)
+foreach(_filename ${MOC_FILES})
+   get_filename_component(_name "${_filename}" NAME)
+   set(_moc_mark_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_name}_automoc.mark)
 
       get_filename_component(_abs_PATH "${_filename}" PATH)
+   get_filename_component(_basename "${_filename}" NAME_WE)
+   set(_moc_source ${_abs_PATH}/${_basename}.h)
+   if ("${_filename}" IS_NEWER_THAN "${_moc_mark_FILE}" OR "${_moc_source}" IS_NEWER_THAN "${_moc_mark_FILE}")
+      # touch .mark file
+      file(WRITE "${_moc_mark_FILE}" "")
+
       message(STATUS "Automoc: Parsing ${_filename}")
 
-      set(_mocs_PER_FILE)
+      # read the whole file
+      file(READ "${_filename}" _contents)
 
+      get_filename_component(_suffix "${_filename}" EXT)
+      if (".cpp" STREQUAL "${_suffix}" OR ".cc" STREQUAL "${_suffix}" OR ".cxx" STREQUAL "${_suffix}" OR ".C" STREQUAL "${_suffix}")
       string(REGEX MATCHALL "#include +([\"<]moc_[^ ]+\\.cpp|[^ ]+\\.moc)[\">]" _match "${_contents}")
       if (_match)
          foreach (_current_MOC_INC ${_match})
             string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
             if(_current_MOC)
                get_filename_component(_basename ${_current_MOC} NAME_WE)
+
+                  # if the .cpp file contains the Q_OBJECT macro we create the .moc file from the .cpp file
+                  string(REGEX MATCH "^[ \t]*Q_OBJECT" _matches_q_object "${_contents}")
+                  if (_matches_q_object)
+                     set(_moc_source ${_filename})
+                  else (_matches_q_object)
+                     set(_moc_source ${_abs_PATH}/${_basename}.h)
+                  endif (_matches_q_object)
             else(_current_MOC)
                string(REGEX MATCH "moc_[^ <\"]+\\.cpp" _current_MOC "${_current_MOC_INC}")
                get_filename_component(_basename ${_current_MOC} NAME_WE)
                string(REPLACE "moc_" "" _basename "${_basename}")
+
+                  # always create moc_foo.cpp from the .h
+                  set(_moc_source ${_abs_PATH}/${_basename}.h)
             endif(_current_MOC)
 
-            set(_header ${_abs_PATH}/${_basename}.h)
-            set(_moc    ${KDE4_CURRENT_BINARY_DIR}/${_current_MOC})
+               if (NOT EXISTS ${_moc_source})
+                  message(FATAL_ERROR "In the file \"${_filename}\" the moc file \"${_current_MOC}\" is included, but \"${_moc_source}\" doesn't exist.")
+               endif (NOT EXISTS ${_moc_source})
 
-            if (NOT EXISTS ${_header})
-               message(FATAL_ERROR "In the file \"${_filename}\" the moc file \"${_current_MOC}\" is included, but \"${_header}\" doesn't exist.")
-            endif (NOT EXISTS ${_header})
-
-            list(APPEND _mocs_PER_FILE ${_basename})
-            file(APPEND ${_moc_mark_FILE} "set( ${_basename}_MOC ${_moc})\n")
-            file(APPEND ${_moc_mark_FILE} "set( ${_basename}_HEADER ${_header})\n")
+               generate_moc(${_moc_source} ${_current_MOC})
          endforeach (_current_MOC_INC)
       endif (_match)
-      file(APPEND ${_moc_mark_FILE} "set(mocs ${_mocs_PER_FILE})\n")
-   endif ("${_filename}" IS_NEWER_THAN "${_moc_mark_FILE}")
+      else (".cpp" STREQUAL "${_suffix}" OR ".cc" STREQUAL "${_suffix}" OR ".cxx" STREQUAL "${_suffix}" OR ".C" STREQUAL "${_suffix}")
+         if (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
+            get_filename_component(_basename ${_filename} NAME_WE)
+            set(_current_MOC "moc_${_basename}.cpp")
+            generate_moc(${_filename} ${_current_MOC})
+         else (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
+            message(STATUS "Automoc: ignoring file with unknown suffix")
+         endif (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
+      endif (".cpp" STREQUAL "${_suffix}" OR ".cc" STREQUAL "${_suffix}" OR ".cxx" STREQUAL "${_suffix}" OR ".C" STREQUAL "${_suffix}")
+   endif ("${_filename}" IS_NEWER_THAN "${_moc_mark_FILE}" OR "${_moc_source}" IS_NEWER_THAN "${_moc_mark_FILE}")
+endforeach(_filename)
 
-endmacro(PARSE_ONE_FILE)
-
-foreach( _current_FILE ${MOC_FILES})
-#   message(STATUS "Automoc: Checking ${_current_FILE}...")
-
-   get_filename_component(_basename ${_current_FILE} NAME)
-   set(_moc_mark_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_automoc.mark)
-
-   if(EXISTS ${_moc_mark_FILE})
-      set(_force_MOC FALSE)
-   else(EXISTS ${_moc_mark_FILE})
-      set(_force_MOC TRUE)
-   endif(EXISTS ${_moc_mark_FILE})
-
-   parse_one_file(${_current_FILE} ${_moc_mark_FILE})
-   
-   include(${_moc_mark_FILE})
-   
-   foreach(_current_MOC ${mocs})
-      if ("${${_current_MOC}_HEADER}" IS_NEWER_THAN "${${_current_MOC}_MOC}" OR _force_MOC)
-         message(STATUS "Automoc: Generating ${${_current_MOC}_MOC} from ${${_current_MOC}_HEADER}")
-         execute_process(COMMAND ${QT_MOC_EXECUTABLE} ${QT_MOC_INCS} ${${_current_MOC}_HEADER} -o ${${_current_MOC}_MOC})
-         
-      endif ("${${_current_MOC}_HEADER}" IS_NEWER_THAN "${${_current_MOC}_MOC}" OR _force_MOC)
-   endforeach(_current_MOC)
-
-
-endforeach( _current_FILE)
-

Attachment: pgpuTXj4LZhCT.pgp
Description: PGP signature

_______________________________________________
Kde-buildsystem mailing list
Kde-buildsystem@kde.org
https://mail.kde.org/mailman/listinfo/kde-buildsystem

Reply via email to