Boost logo

Boost-Build :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-11-03 04:04:49


Hi Christopher,

> I'm trying to build a toolset that implements the following scenario:
>
>
> exe xmlapp : main.cpp [ xml-cpp Person.cpp Name.cpp : schema.xml ] ;

[...]

> I've been pretty successful so far, I've almost got it working. Here is
> my current implementation:

[...]

> for local name in $(targets)
> {
> targets.create-typed-target CPP
>
> : $(project) : $(name) : $(source) : $(requirements)
> : $(default-build) : $(usage-requirements) ;

[...]

> So far, so good. The only problem is that the system now runs the
> schema-compile action once for each generated CPP file, even though the
> tool will create them all at the same time.

Yes, you create two main targets, one for each .cpp file to be produced, and
as far as Boost.Build is concerned, they are not related in any way.

> Obviously I needed a way to specify that the generator was going to
> create multiple targets, and so I tried adding:
>
> generators.register [
> new generator objectlink.schema-compile
>
> : XSD : CPP($(targets).cpp)
>
> ] ;

Oh... that's really not a good way. You're creating a new generator for each
main target rule, and that's not the way they are supposed to work.

> into my rule, just before the return, and removing the standard
> generator below. This broke the build, because somewhere my CPP targets
> are getting defined twice. My build now gives the errors below.
>
> I figure that the generator is defining new virtual-targets with the
> same file-target name, because my generator output is fixed. So what I
> probably need to do is not create the typed-targets, and return the
> virtual-targets from the generator. Trouble is, I can't figure out how
> to get those target id's out of the generator.
> Am I on the right track? Or is there another way to solve this dilemma?

There's a certain problem with using generators to this task. Each generator
gets a 'name' of target(s) to produce, but there's no direct way to pass
several target names. You can pass them via properties, but that's kinda
complex.

The solution, I think, it to avoid the generators and create the targets
directory, by deriving a class from 'basic-target' class and overriding it's
'construct' method. The construct method will create targets and action, set
something like 'objlink.link' as rule for action, and define the 'link'
action.

You can pass the list of sources to create to the constructor of this class,
and then use the names in 'construct'.

The 'make.jam' module gives a reasonable example, in fact, it only differs by
the fact that it can't produce several files.

BTW, I recall you was planning to write a tutorial on creating main target
class, so you might know everything already?

Anyway, questions are welcome.

- Volodya

 


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk