vmrob
vmrob

Reputation: 3046

How can I make the target name of a Boost Build rule templated?

I have a small Jamfile that I process with Boost Build that looks like this:

exe add-account    : add-account.cpp    ..//server-lib ../../shared//shared ;
exe add-deck       : add-deck.cpp       ..//server-lib ../../shared//shared ;
exe give-all-cards : give-all-cards.cpp ..//server-lib ../../shared//shared ;
exe give-card      : give-card.cpp      ..//server-lib ../../shared//shared ;

install . :
    add-account
    add-deck
    give-all-cards
    give-card
;

I feel like I should be able to do this with some sort of template. I've been looking around in the Boost Build user manual, but haven't found a language rule that will help me.

It's probably worth mentioning that I'm aware that more code is probably not the best solution here, but I'm still interested in if it can be done. It would at least be useful in cases where I want to compile an entire directory filled with single source-file programs.

Upvotes: 0

Views: 150

Answers (1)

Juraj Ivančić
Juraj Ivančić

Reputation: 725

There are several ways to make this more concise. Just for illustration:

local exe-list = add-account add-deck give-all-cards give-card ;
for exe-file in $(exe-list)
{
    exe $(exe-file) : $(exe-file).cpp ..//server-lib ../../shared//shared ;
}

install . : $(exe-list) ;

You can also create a helper rule.

rule simple-exe ( name )
{
    exe $(name) : $(name).cpp ..//server-lib ../../shared//shared ;
}

local exe-list = add-account add-deck give-all-cards give-card ;
for exe-file in $(exe-list)
{
    simple-exe $(exe-file) ;
}

install . : $(exe-list) ;

Additionally - if same library dependencies are often used, they can be put into an alias

alias common : ..//server-lib ../../shared//shared ;

exe add-account    : add-account.cpp    common ;
exe add-deck       : add-deck.cpp       common ;
exe give-all-cards : give-all-cards.cpp common ;
exe give-card      : give-card.cpp      common ;

or in project requirements

project my-project : requirements
    <library>..//server-lib
    <library../../shared//shared
;

exe add-account    : add-account.cpp    ;
exe add-deck       : add-deck.cpp       ;
exe give-all-cards : give-all-cards.cpp ;
exe give-card      : give-card.cpp      ;

Some combination of these techniques should do the trick.

Upvotes: 2

Related Questions