Alex wrote: > On Wednesday 27 June 2007 18:26, Matthias Kretz wrote: > > 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 > > I didn't mean the cmake cache, I meant the disk cache, i.e. compared > directly after booting (with cold cache) and when running cmake multiple > times in a row (-> warm caches).
That's what I feared you'd mean. And no, I won't really test that except if
you give me a method to clear the disk cache without rebooting and without
waiting forever...
> > 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
>
> The thing to watch out for: does it work with spaces in the path to the
> source or binary dir ?
I tested that now and needed the following in KDE4Macros.cmake:
qt4_get_moc_inc_dirs(_moc_INCS)
set(_incs)
foreach(_inc ${_moc_INCS})
set(_incs "${_incs}\;${_inc}")
endforeach(_inc ${_moc_INCS})
changing that to:
set(_incs)
GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES)
FOREACH(_current ${_inc_DIRS})
SET(_incs "${_incs}\;-I\;${_current}")
ENDFOREACH(_current)
saves ~15s total time spent in cmake.
and then I'm passing
-DQT_MOC_INCS="${_incs}"
to the cmake command
then in kde4automoc.cmake I need to do:
STRING(REPLACE "\\ " " " MOC_FILES "${MOC_FILES}")
STRING(REPLACE "\\ " " " QT_MOC_INCS "${QT_MOC_INCS}")
after that it seems to work, at least my stuff. Here's an error I didn't look
into:
Scanning dependencies of target globalcleanuptest
[ 8%] Building CXX object
kdecore/tests/CMakeFiles/globalcleanuptest.dir/globalcleanuptest.o
g++: libs/kdecore/tests": No such file or directory
<command line>:1:1: warning: "KDESRCDIR" redefined
<command line>:1:1: warning: this is the location of the previous definition
make[2]: ***
[kdecore/tests/CMakeFiles/globalcleanuptest.dir/globalcleanuptest.o] Error 1
make[1]: *** [kdecore/tests/CMakeFiles/globalcleanuptest.dir/all] Error 2
I renamed my src/kdelibs dir to src/kde\ libs and obj/kdelibs to obj/kde\ libs
> > save on IO at cmake time. (Optimizing cmake performance is guesswork or
> > do you have any way to gather better data?)
>
> I used valgrind. But this doesn't really help for IO.
Last night it occurred to me that adding a custom target is very IO expensive
since it needs to create the whole ${target_name}.dir directory structure
plus all the files contained in it. So I tried to get rid of the custom
automoc target again and instead use a custom command. Patch against trunk
(svn di -x -w) attached.
timings for kdelibs with the new patch:
without cache: 37.97s user 10.99s system 45% cpu 1:46.53 total
with cache: 14.89s user 2.13s system 24% cpu 1:09.05 total
CPU usage seems higher, it still seems faster though which must be from the
reduced IO.
PS: Now I'm subscribed to kde-buildsystem...
--
________________________________________________________
Matthias Kretz (Germany) <><
http://Vir.homelinux.org/
[EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED]
Index: KDE4Macros.cmake
===================================================================
--- KDE4Macros.cmake (revision 681306)
+++ 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
@@ -24,6 +29,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.
@@ -147,77 +153,91 @@
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 _SRCS)
+ KDE4_GET_CUSTOM_TARGET_PROPERTY(_headers_to_moc ${_target_name} AUTOMOC_HEADERS)
+ if(NOT _headers_to_moc STREQUAL "NOTFOUND")
+ qt4_get_moc_inc_dirs(_moc_INCS)
+ 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(${_SRCS} ${${_SRCS}} ${_moc})
+ add_custom_command(OUTPUT ${_moc} COMMAND ${QT_MOC_EXECUTABLE} ${_moc_INCS} ${CMAKE_CURRENT_SOURCE_DIR}/${_current_FILE} -o ${_moc})
+ endforeach (_current_FILE)
+ endif(NOT _headers_to_moc STREQUAL "NOTFOUND")
+endmacro(KDE4_APPEND_MOC_FILES)
- 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 _SRCS)
+ set(_mark_file "${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}.automoc")
+ set(_moc_files)
+ set(_moc_headers)
+ foreach (_current_FILE ${${_SRCS}})
+ 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_WE)
+ get_filename_component(_abs_path "${_abs_current_FILE}" PATH)
+ set(_header "${_abs_path}/${_basename}.h")
+ if(EXISTS "${_header}")
+ set(_moc_headers ${_moc_headers} ${_header})
+ endif(EXISTS "${_header}")
+ #macro_additional_clean_files("${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
+ #macro_additional_clean_files("${CMAKE_CURRENT_BINARY_DIR}/moc_${_basename}.cpp")
+ 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}
+ set(_moc_incs)
+ GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES)
+ FOREACH(_current ${_inc_DIRS})
+ SET(_moc_incs "${_moc_incs}\;-I\;${_current}")
+ ENDFOREACH(_current)
+ add_custom_command(OUTPUT ${_mark_file}
+ 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}"
+ -DMARK_FILE="${_mark_file}"
+ -P ${KDE4_MODULE_DIR}/kde4automoc.cmake
+ DEPENDS ${${_SRCS}} ${_moc_headers}
)
+ set(${_SRCS} ${${_SRCS}} ${_mark_file})
+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)
@@ -633,13 +653,14 @@
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)
+ kde4_handle_automoc(${_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)
@@ -720,14 +741,15 @@
# 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)
+ kde4_handle_automoc(kdeinit_${_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_rpath_for_library(kdeinit_${_target_NAME})
@@ -780,15 +802,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)
+ kde4_handle_automoc(${_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)
+
if (WIN32)
target_link_libraries(${_target_NAME} ${QT_QTMAIN_LIBRARY})
endif (WIN32)
@@ -823,13 +847,13 @@
set(_type "RUN_UNINSTALLED")
endif (_uninst)
- kde4_get_automoc_files(_automoc_FILES ${_SRCS})
-
+ kde4_append_moc_files(${_target_NAME} _SRCS)
+ kde4_handle_automoc(${_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_rpath_for_executable(${_target_NAME} ${_type})
@@ -860,13 +884,14 @@
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)
+ kde4_handle_automoc(${_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_rpath_for_library(${_target_NAME})
Index: kde4automoc.cmake
===================================================================
--- kde4automoc.cmake (revision 681306)
+++ kde4automoc.cmake (working copy)
@@ -1,22 +1,40 @@
# 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}" OR _force_moc)
+ 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}" OR _force_moc)
+endmacro (generate_moc)
- file(READ "${_filename}" _contents)
+if (EXISTS "${MARK_FILE}")
+ set(_force_moc FALSE)
+else (EXISTS "${MARK_FILE}")
+ set(_force_moc TRUE)
+endif (EXISTS "${MARK_FILE}")
+STRING(REPLACE "\\ " " " MOC_FILES "${MOC_FILES}")
+STRING(REPLACE "\\ " " " QT_MOC_INCS "${QT_MOC_INCS}")
+foreach(_filename ${MOC_FILES})
+ get_filename_component(_name "${_filename}" NAME)
get_filename_component(_abs_PATH "${_filename}" PATH)
- message(STATUS "Automoc: Parsing ${_filename}")
+ get_filename_component(_basename "${_filename}" NAME_WE)
+ set(_moc_source ${_abs_PATH}/${_basename}.h)
+ if ("${_filename}" IS_NEWER_THAN "${MARK_FILE}" OR "${_moc_source}" IS_NEWER_THAN "${MARK_FILE}")
+ get_filename_component(_suffix "${_filename}" EXT)
+ if (".cpp" STREQUAL "${_suffix}" OR ".cc" STREQUAL "${_suffix}" OR ".cxx" STREQUAL "${_suffix}" OR ".C" STREQUAL "${_suffix}")
+ #message(STATUS "Automoc: Looking for outdated moc includes in ${_filename}")
- set(_mocs_PER_FILE)
+ # read the whole file
+ file(READ ${_filename} _contents)
string(REGEX MATCHALL "#include +([\"<]moc_[^ ]+\\.cpp|[^ ]+\\.moc)[\">]" _match "${_contents}")
if (_match)
@@ -24,53 +42,41 @@
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 '${_filename}' with unknown suffix '${_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 "${MARK_FILE}" OR "${_moc_source}" IS_NEWER_THAN "${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)
-
+# touch .mark file
+file(WRITE "${MARK_FILE}" "")
pgpZOqtmf5Nzn.pgp
Description: PGP signature
_______________________________________________ Kde-buildsystem mailing list [email protected] https://mail.kde.org/mailman/listinfo/kde-buildsystem
