[build2] Build system module for code-generation utilities Qt moc, etc.

Sam Schweigel s.schweigel at gmail.com
Wed May 8 08:51:36 UTC 2019


Boris Kolpackov writes:

> Can you provide a more precise description of what you want to
> achieve preferably with an example?

Most build systems that support Qt have some way of automatically
detecting when moc needs to be run, and injects dependencies on those
preprocessed files.

Unfortunately existing build systems for Qt seem to just "do everything
at once", hoping that one of them will work.  Here are the approaches
that CMake tries:

1. Looking for #include directives of the form "moc_foo.cxx", and
running the preprocessor on "foo.hxx" to generate it.
2. Looking for #include "foo.moc", and generating it by running moc on
the file containing the directive itself.
3. Scanning user header files for the "Q_OBJECT" string that moc
requires be present, and running the preprocessor on them.  This seems
to be the most widely used technique (?).  Qmake also does this.

I'd like to try implementing the third option, but I'm not sure where
this searching logic would fit into a build2 module.

Example:

buildfile:
using cxx moc
# maybe require setting a variable to get the automatic scanning?
exe{hello}: {hxx cxx}{main}

hello.cxx: empty

hello.hxx:
#pragma once

class A {
  Q_OBJECT
};

This would make exe{hello} depend on a generated cxx.moc{main}, which
would depend on hxx{main}.



More information about the users mailing list