Boost logo

Boost-Build :

Subject: Re: [Boost-build] How to create and call a rule which acts differentlydepending on the build variant?
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2009-11-12 02:47:54


Deniz Bahadir wrote:
> Hello everyone,
>

[snip]

> Now, the names of these libraries shall be used as required
> dependencies for other libraries or executables. To always include the
> correct file I could use conditional requirements like this:
> exe bar
> : bar.cpp
> : <variant>debugstatic:<file>libfoo_debugstatic.a
> <variant>debugdynamic:<file>libfoo_debugdynamic.so
> <variant>releasestatic:<file>libfoo_releasestatic.a
> <variant>releasedynamic:<file>libfoo_releasedynamic.so
> ;
> However, with a lot of required libraries I have to write the same
> stuff over and over again (4 times more often than I want).
> So I would like to have a rule which automatically adds the correct
> postfix and suffix to the base library name. Maybe I can do something
> similar to the following?

Using indirect conditional requirements seems like overkill in this case. As
you only seem to support one platform, it would be pretty simple to do it
"the other way around". This is the basic idea:

path-constant LIB_PATH : relative/path/to/libs ;

lib foo
  :
  : <file>$(LIB_PATH)/libfoo_debugstatic.a <variant>debugstatic
  ;

lib foo
  :
  : <file>$(LIB_PATH)/libfoo_debugdynamic.so <variant>debugdynamic
  ;

... repeat for other variants ...

exe bar
    : bar.cpp
    : <library>foo
    ;

exe baz
    : baz.cpp
    : <library>foo
    ;

(There's hardly any reason to tag the libs with "dynamic/static" as this are
already identified by their extension).

Also, if e.g. the "foo" library has certain include directories or defines
that need to be propagated to its users it's easy to add that to the
"usage-requirements" argument in the lib definitions, e.g:

lib foo
  :
  : <file>$(LIB_PATH)/libfoo_debugdynamic.so <variant>debugdynamic
  :
  : <include>$(LIB_INCLUDE_PATH)/foo <define>FOO_DYNAMIC
  ;

HTH / Johan


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