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

Boris Kolpackov boris at codesynthesis.com
Wed May 8 14:30:01 UTC 2019


Sam Schweigel <s.schweigel at gmail.com> writes:

> 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.

This will actually work almost auto-magically in build2. Specifically,
any missing generated header will be automatically generated provided
there is a rule. This is how all our auto-generated headers (cli, in)
are handled.


> 3. Scanning user header files for the "Q_OBJECT" string that moc
> requires be present, and running the preprocessor on them.

This will be quite a bit harder, I think.

Firstly, you need to somehow define a "pool" of headers to scan.
List of prerequisites for an exe or lib feels like the right set
(we do something similar for C++ modules). Then, after scanning,
I presume you will need to inject the moc-generated source files
as additional prerequisites to said exe or lib.

It seems the clean way to do it would be to define "Qt exe" and
"Qt lib" target types that would "signal" that such additional
functionality is required. For example:

qtexe{hello}: {hxx cxx}{main}

Then you will need to provide a customized link rule that will
implement this scanning/injection logic.

I suppose all this can be done (and we can probably even add
a suitable hook to the link rule), but it feels like a lot
more work compared to options 1 and 2.



More information about the users mailing list