Boost logo

Boost-Build :

Subject: Re: [Boost-build] Conditional targets not resolving properly
From: Phillip Seaver (phil_at_[hidden])
Date: 2009-09-10 11:35:03


Johan Larsson wrote:
> Hello.
>
> As part of a project, I have a library with an associated Jamfile I
> need to build. I want to build this particular library as a static
> lib, so I've added <link>static to the project requirements in the
> Jamfile for the library. So far so good.
>
> However, I also want to exclude a particular source file from the
> library if I use a particular toolset (gcc in this case). So I've
> created two targets; one with all the sources and no particular
> requirements, and one without the source file in question with
> <toolset>gcc added as a requirement, like so:
>
>
>
> project A
> : requirements
> <link>static
> <toolset>gcc:<cxxflags>-DNO_SMART
> : usage-requirements
> <linkflags>-lA
> <include>.
> ;
>
> alias commonsources
> : (snip)
> ;
>
> lib libA
> : commonsources
> SOURCE.cpp
> ;
>
> lib libA
> : commonsources
> : <toolset>gcc
> ;
>
> The problem is that when building with a toolset that is not gcc, bjam
> fails to find an appropriate target. The output it gives me is as follows:
> error: No best alternative for ./libA
> next alternative: required properties: <link>static
> not matched
> next alternative: required properties: <link>static <toolset>gcc
> not matched
>
> Obviously, I want the builds to match the closest possible
> alternative; that is, any build with a toolset other than gcc should
> match the first target, and any build with gcc as a toolset should
> match the second target.
>
> Is there a way to achieve this, or perhaps a different way altoghether
> to exclude source files from a target when build with a particular
> toolset?

This should work:

    project A
      : requirements
        <link>static
        <toolset>gcc:<define>NO_SMART
      : usage-requirements
        <include>.
      ;

    lib libA
      : (snip)
      : <toolset>gcc:<source>SOURCE.cpp
      ;

The <source> feature adds that file to the list of sources as if you had
specified it in the same argument as "(snip)".

I got rid of the "<linkflags>-lA" because just referring to this project
in another project would cause it to link against libA and it kind of
defeats the purpose of using boost-build if you're using <linkflags> and
<cxxflags> when there's a feature that does the same thing in a
cross-platform way. :-)

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