[CMake] general issue with KDE4_AUTOMOC() and cmake

Craig Bradney cbradney at zip.com.au
Fri Aug 25 19:40:09 EDT 2006


On Friday 25 August 2006 23:01, Alexander Neundorf wrote:
> Hi,
>
> in KDE4 we have the KDE4_AUTOMOC() macro.
> It basically does:
>
> macro(KDE4_AUTOMOC srcs...)
>    foreach (file srcs)
>       if (file contains "include <something.moc>")
>          add_custom_command(OUTPUT something.moc COMMAND moc ... )
>       endif()
>    endforeach()
> endmacro(KDE4_AUTOMOC srcs...)
>
> So this is run at cmake time and uses 20 to 25 percent of a cmake run on a
> KDE modules. At the time the cmake runs, let's say "kwidget.cpp" doesn't
> contain the include <something.moc> line yet so cmake doesn't generate a
> add_custom_command() to generate a moc file. Then it can happen that the
> developer adds the "include <something.moc>" line to kwidget.cpp, but
> doesn't edit any cmake files. So he edited one source file, but the result
> would have to be that the buildsystem adds a custom_command() to generate
> an additional file. CMake can create rules for generating files when cmake
> runs. But since he just edited a source file, cmake doesn't run and so it
> is not possible to create a new rule for the new required moc file. The
> only way out is to "touch" a cmake file which forces cmake to run again.
> While this works, it's not ideal.
>
> I see two ways to improve the situation:
>
> 1) keep the parsing at cmake time, but for every parsed file create a
> kfoo.automoc_rules file, which contains the required ADD_CUSTOM_COMMAND()
> calls for this file. This file is then INCLUDEd in the CMakeLists.txt and
> kfoo.cpp is only parsed again if kfoo.automoc_rules is older then kfoo.cpp
> . This would avoid parsing all source files every time cmake runs.
>
> 2) parse the source files at build time
> This will make the cmake time much shorter -> good.
> But then at build time there must be a script which parses the source files
> if required *and* executes moc to generate the files. I.e. the moc call and
> the dependencies would not be handled by make (or XCode or ...) but by the
> script, which feels a bit "suboptimal" (but doable).

This is similar to issues we've seen with Scribus too. Now and then we do get 
one of us reporting that a moc file was not update, deleting it forces 
recreation and its ok then.

Craig


More information about the CMake mailing list