Boost logo

Boost-Build :

From: Phillip Seaver (phil_at_[hidden])
Date: 2006-04-24 06:59:45


Kostas Kostiadis wrote:
>
> Hello all,
>
>
>
> The quick version of my question:
>
>
>
> Where is the best place to specify global defines that are then
> propagated to all sub-projects?
>
> For example, I need to have something like:
>
>
>
> requirements <variant>debug:<define>ENABLE_ASSERTS
>
>
>
> that will be true for ALL projects under a certain root directory.
>
You can add a "project" rule to the Jamfile or Jamroot in that top-level
directory that specifies that, like:

    project root : requirements <variant>debug:<define>ENABLE_ASSERTS ;

In my Jamroot.jam, I have a project rule that does global requirements
like that. There are no build rules (like "exe", "lib", etc.) in there,
so it doesn't build anything, but the requirements get propagated to all
the child projects.

> The long version of my question (explained by example):
>
> Say I have a UTILS lib (in its own folder with its own Jamfile) and
> one of its source files has something along the lines of:
>
>
>
> #ifdef ENABLE_ASSERTS
>
> #define ASSERT OutputSomeMessageAndHalt
>
> #else
>
> #define ASSERT NothingFunction
>
> #endif
>
>
>
> In this lib (i.e. UTILS) the Jamfile has something like
>
>
>
> project UTILS
>
> : requirements <variant>debug:<define>ENABLE_ASSERTS
>
> ;
>
>
>
> Now say I have another lib, call it MATH, which uses the UTILS lib.
>
> Because I can't specify the order things are build, ASSERT ends up
> being the NothingFunction during debug builds of the MATH lib.
>
>
>
> The only way I found of "fixing" this, is by adding this
>
> : requirements <variant>debug:<define>ENABLE_ASSERTS
>
>
>
> to project MATH in the math lib Jamfile as well...
>
> This is quite bad because it means I'll have to define ENABLE_ASSERTS
> in all the other Jamfiles for all libs and projects that want to use it.
>
> What is the best way to deal with this problem? Is defining
> ENABLE_ASSERTS globally somewhere the best solution?
>
> If so, how can I do this?
>
On the other hand, if all you need to do is make sure all users of the
UTILS library have that defined, I'd do it in the UTILS Jamfile:

    project UTILS
       : requirements <variant>debug:<define>ENABLE_ASSERTS
       : usage-requirements <variant>debug:<define>ENABLE_ASSERTS
    ;

Then you can have, e.g., "use-project /UTILS : path/to/UTILS ;" in a
higher-level Jamfile, and add /UTILS to the source of the MATH lib:

    lib MATH : math.c /UTILS ;

That will cause the usage requirements of UTILS to be applied to MATH.

Hope this helps,

Phillip


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