Boost logo

Boost-Build :

Subject: Re: [Boost-build] multiple generated targets from a single source file
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-04-02 08:41:58


AMDG

On 04/01/2012 01:13 PM, George Georgiev wrote:
> Hi,
>
> I am tying to resolve something that looks a corner case for the Boost
> Build system.
>
> The end goal I want to accomplish is I to be able to use more than one
> generation process for the same input file that will result in
> different files.
>
> For example if I have foo.compil I can use it to create foo.cpp and
> foo.h, but also I can use the same file to create foo-proxy.h and
> foo-proxy.cpp or foo-adapter.h and foo-adapter.cpp. Note the number of
> output files needs to be flexible and it needs to be controlled from
> the jamfile. For example I should be able to do something similar to
> this:
>
> lib shared :
> <compil-generator>impl:foo.compil
> ;
>
> lib server :
> <compil-generator>adapter:foo.compil
>
> shared
> ;
>
> lib client :
> <compil-generator>proxy:foo.compil
>
> shared
> ;
>
> What will be the right way to go here - generator that accept
> arguments, multiple generators for single extension or something else.

Both options work.

If you use a single generator, you'll need to define
a feature to control it:

# in compil.jam
feature.feature compil-type : impl adapter proxy : optional ;
toolset.flags compil OPTIONS <compil-type>impl : -generate-impl ;
toolset.flags compil OPTIONS <compil-type>adapter : -generate-adapter ;
toolset.flags compil OPTIONS <compil-type>proxy : -generate-proxy ;
# Expand $(OPTIONS) in the action

lib client : foo.compil : <compil-type>proxy ;

This is probably the best solution if the
generating actions only differ by a command
line option. If they're totally different,
you'll want to use multiple generators.

If you have multiple generators, you have two
choices. You can distinguish them with
a feature. I believe that one of the parameters
of class_at_generator.__init__ allows you to restrict
the generator with a feature. The generator
definition would end up looking like

generators.register
  [ new compil-generator generate-impl : <compil-type>impl ] ;
generators.register
  [ new compil-generator generate-adapter : <compil-type>adapter ] ;
generators.register
  [ new compil-generator generate-proxy : <compil-type>proxy ] ;

(Warning, this is off the top of my head and not tested.
I probably don't have the syntax exactly right.)

The user code in this case is identical to using
a single generator.

Finally, you can distinguish the different outputs
as different types:

type.type COMPIL_IMPL : : CPP ;
type.type COMPIL_ADAPTER : : CPP ;
type.type COMPIL_PROXY : : CPP ;

Now the Jamfiles will look like

lib client [ compil-impl _ : foo.compil ] ;

> If you can point me to example for something similar already done it
> will be perfect.
>

In Christ,
Steven Watanabe


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