Boost logo

Boost :

Subject: Re: [boost] Boost.Build check to see if cxxflags flag is supported?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-11-07 20:46:39


AMDG

On 11/07/2018 09:09 AM, James E. King III via Boost wrote:
> I'm looking for an example for how I could check to see if "-fPIC" is
> supported for the compiler as part of project requirements.
>
> In some recent PRs that include building a static library which then gets
> included in a shared library, code needs to be built with "-fPIC" on
> supported platforms/toolsets. There is some code in gcc.jam to do this if
> the overall link mode is shared (note: this code is not in clang.jam!), but
> in this case the overall link mode is static, and a Jamfile wraps the
> result in a shared library, so the directives in gcc.jam are not applied.
>
> So at the top level Jamfile, I want to add a project requirement that
> basically says, "if the compiler supports <cxxflags>-fPIC then use it".
>

import flags ;
project
 : requirements
   [ check-has-flag <cxxflags>-fPIC : <cxxflags>-fPIC ]
 ;

Note 1: The documentation for this is only in
`b2 --help flags.check-has-flag`. It isn't
integrated into the html docs yet.

Note 2: This is pretty new, so if you run into
any problems, please let me know.

Note 3: It might be more reliable to separate
the object files out and set <link>shared on them:
 obj x.o : x.cpp : <link>shared ;
 ...
 lib l : x.o y.o ... ;
(This will only work if the library is one
that is specifically built for the test, not
if it's a generic Boost library.)

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk