[cmake-developers] kde4_automoc issue
Alexander Neundorf
neundorf at kde.org
Sun Jul 16 14:24:15 EDT 2006
Hi all,
for KDE I wrote a macro KDE4_AUTMOC(), which parses at cmake time the source
files, checks whether they include a line like "#include "kfoo.moc" and if
that's the case use add_custom_command() to create a rule for this file.
This has two issues:
1) it only detects these lines at cmake time, i.e. if a incude "kfoo.moc" line
is added but no cmake file is touched the file will not be generated.
2) it consumes approx. 20 to 25 percent of the time of a cmake run in a KDE
module. This is the bigger problem.
So I have an idea regarding automoc:
one idea would be to scan the files which need automoc before building the
target.
Let's say I build target kfoo.
Here comes some pseudo code:
KDE4_AUTOMOC could be changed to just set a property on the files:
foreach file
set_sourcefiles_properties(file PROPERTIES DO_AUTOMOC TRUE)
endforeach
and then in
KDE4_ADD_(LIBRARY|EXECUTABLE|PLUGIN)()
I could do:
foreach file
if file HAS_PROPERTY DO_AUTOMOC
need_automoc=TRUE
autmocfiles.append(file)
endif
endforeach
if (need_automoc)
# create a file with all files for automoc
file(WRITE kfoo_automoc_files ${automocfiles)
# create a target which will be built before the actual target
ADD_CUSTOM_TARGET(kfoo_automoc COMMAND <scan all files from kfoo_automoc
and run moc if required> )
ADD_DEPENDENCIES(kfoo kfoo_automoc)
endif
This would move the automoc from cmake time to buildtime, which is a good
thing.
But there is a problem still. If the COMMAND used for kfoo_automoc is a cmake
script (which I would like it to be) it would scan all files every time the
target is built. This would make building probably quite a lot slower.
So either that command has to be written in another language (perl, since we
already require it) or there would need to be a way in cmake to detect
whether a file has changed since the last build.
if (NOT EXISTS file_marker OR file_marker OLDER_THAN file)
do_scan(file)
FILE(WRITE file_marker "timestamp only")
endif
What do you think ?
Bye
Alex
--
Work: alexander.neundorf AT jenoptik.com - http://www.jenoptik-los.de
Home: neundorf AT kde.org - http://www.kde.org
alex AT neundorf.net - http://www.neundorf.net
More information about the cmake-developers
mailing list