[cmake-developers] Automoc in cmake

Rolf Eike Beer eike at sf-mail.de
Thu Jun 9 07:06:03 EDT 2011


> On Thursday 09 June 2011, Alexander Neundorf wrote:
> ...
>> At build time, the logic is complex enough and it also has to be really
>> fast so that this should IMO be done in the C++.
>> It could either be a -E automoc <infofile> option, or a -P
>> CMakeAutomoc.cmake script, which then calls a new automoc() function.
>> This then needs to go through the list of source files, and if the file
>> is
>> newer than the associated stamp-file or if no stamp-file exists, it
>> needs
>> to parse the source file for a #include-moc statement,
>
> It does even more that that. Some comments from the implementation:
>
> // the program goes through all .cpp files to see which moc files are
> // included. It is not really interesting how the moc file is named, but
> what
> // file the moc is created from. Once a moc is included the same moc may
> not
> // be included in the _automoc.cpp file anymore. OTOH if there's a
> // header containing Q_OBJECT where no corresponding moc file is included
> // anywhere a moc_<filename>.cpp file is created and included in the
> // _automoc.cpp file.
> ...
>
> // If the moc include is of the moc_foo.cpp style we expect the Q_OBJECT
> class
> // declaration in a header file.
> // If the moc include is of the foo.moc style we need to look for a
> Q_OBJECT
> // macro in the current source file, if it contains the macro we generate
> the
> // moc file from the source file, else from the header.

Which the moc-scanner still could do. The interface I talked about is
basically to allow CMake to filter "noise" away from the scanners so they
don't get called for things they don't care about at all. What the scanner
later does with the files it get's passed is only his point.

Eike



More information about the cmake-developers mailing list