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

Boris Kolpackov boris at codesynthesis.com
Tue May 7 14:13:30 UTC 2019


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

> I've had a lot of success packaging libraries for build2 so far, and I'd
> like to experiment with getting Qt5 building using it, which involves a
> number of preprocessing steps (moc, rcc, uic).

That would be quite impressive if you can pull it off.


> I understand that these would be implemented as build system modules,
> and that eventually the plan is to have dynamically-loadable build
> system modules that would be packaged with the build tools themselves.

Right, though that last part (where such external build system modules
come from) is still a bit fuzzy. It feels like coming together with
the tool (moc in this case) would be quite natural.


> To get a feel for the build2 codebase, I've tried to implement
> a `moc` rule myself:
> 
> using cxx moc
> 
> exe{hello}: cxx{file1} hxx{file1} cxx{file1_moc}
> cxx{file1_moc}: hxx{file1}
> 
> Where the `moc` module introduces no target types and contains a rule
> that can turn an `hxx{xyz}` into an `cxx{xyz_moc}`.  Is this the
> idiomatic way of doing this?

Yes, this could be one way of doing it. One potential issue with this
approach is that your rule will probably use the presence of `_moc`
suffix in the target name to decide if it matches. Which won't work
if I want to use a different suffix (say, `-moc`).

So an alternative way would be to define a new target type; the
recommended name would be moc.cxx{}. It can simply derive from
cxx{} or you can make it a target group (similar to cli.cxx{})
or you can turn it into a target group later if/when needed (for
example, if moc outputs more than one file). The buildfile will
look like this:

exe{hello}: cxx{file1} hxx{file1} moc.cxx{file1_moc}
moc.cxx{file1_moc}: hxx{file1}

Or you could continue using cxx{} for the prerequisite if you prefer:

exe{hello}: cxx{file1} hxx{file1} cxx{file1_moc}


> Additionally, I'd like to be able to scan all the `hxx` targets for the
> string `Q_OBJECT`, and inject all targets that depend on that header
> with a dependency on `cxx{blah_moc}`.  Where should the logic for this
> go?

Hm, I am not sure I understand what you mean here. But I am pretty
sure you don't mean "all targets" which would include things from
/usr/include/ ;-).

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



More information about the users mailing list