Boost logo

Boost :

Subject: Re: [boost] [build][test][gsoc] question about compiling tests with multiple compile params using b2
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2015-05-21 20:17:57


AMDG

On 05/21/2015 05:19 PM, Damian Vicino wrote:
> Hi,
> I’m working in the safe_float library for the GSOC.
>
> For testing I’m using the boost.test library and for building I’m using b2.
>
> The implementation have several pieces that are implemented in two flavours, one for compilers supporting FLOAT_ENV and one for those not supporting it. (this is a C++11 feature missed in at least clang and gcc compilers)
>
> Right now, the implementation is selected with an #ifdef and I #define them with a -D parameter.
>
> My config file for test is:
> using testing ;
> lib boost_unit_test_framework ;
> unit-test test : main-test.cpp [ glob *_test.cpp ] boost_unit_test_framework ;
>
> I guess I can generate 2 different executables using 2 targets, duplicating last line and adding something to tell it to pass -DFENV_AVAILABLE, but I couldn’t find how to do that.
> Having 2 executables for the tests and running them both will provide testing for both compilation paths (when using a compiler supporting FENV).
>

The simplest way is just to define a wrapper rule
that creates two targets at a time, like so:

rule my-unit-test ( target : sources * : requirements * )
{
    unit-test $(target)-fenv : $(sources)
      : $(requirements) <define>FENV_AVAILABLE ;
    unit-test $(target)-no-fenv : $(sources)
      : $(requirements) ;
}

> Also, I’m wondering if B2 has the inteligence detect and pass a parameter when using a compiler supporting FENV.
>

There's nothing built in, but you can define it yourself.

> Is there any common approach for these situations where conditionally compiling based on a c++ feature support?
>
> In the case a Boost.Build needs to define a test for detecting if the compiler supports the feature (autoconf-like) it can be tested compiling a one-liner file: test.fenv.cpp
> #pragma STDC FENV_ACCESS ON
> When compiled:
> clang++ -c test.fenv.cpp
> test.clang.cpp:1:14: warning: pragma STDC FENV_ACCESS ON is not supported, ignoring pragma [-Wunknown-pragmas]
> #pragma STDC FENV_ACCESS ON
> The warning means the feature is not supported.
>

You'll need to define a target for this.

obj has_fenv : test.fenv.cpp : <warnings-as-errors>on ;

Then you can use configure.check-target-builds to
select features conditionally:

import configure : check-target-builds ;
run test.cpp : : : [ check-target-builds has_fenv : <define>XXX :
<build>no ] ;

> Thanks for any guidance in this area, I’m pretty newbie with the b2 system.
>

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