Boost logo

Boost-Build :

Subject: Re: [Boost-build] How to create and call a rule which acts differently depending on the build variant?
From: Deniz Bahadir (D.Bahadir_at_[hidden])
Date: 2009-11-11 12:41:04


Thank you again, Volodya,

>> ...
>> 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
>> ;
>
> Are those libraries also created by Boost.Build? If so, you
> probably can include the relevant target in the sources for 'bar',
> as opposed to using <file>
>
Yes and no. Originally they are built by Boost.Build but by an
entirely different call to bjam with a different Jamroot. So I guess,
I need the <file>?
But you made me think about something: Do I have to add these
libraries (at least the static ones) to the source-section of the
exe-rule instead of the requirements-section? They are needed for
linking, so I guess they should be in the source-section?

> Please take a look at indirect conditional requirements, here:
>
> http://www.boost.org/boost-build2/doc/html/bbv2/overview/targets.html#bbv2.overview.targets.requirements
>

I must have overseen the indirect conditional requirement part in the
documentation. However, I was not really able to figure out, how to
adopt this to my problem.
Right now I have created the following rule:

rule AppendCorrectPostfixAndSuffix ( properties * )
{
  # find the correct postfix + suffix
  local postfix_suffix ;

  if <variant>debugstatic in $(properties)
  {
    postfix_suffix += _debugstatic.a ;
  }
  else if <variant>releasestatic in $(properties)
  {
    postfix_suffix += _releasestatic.a ;
  }
  else if <variant>debugdynamic in $(properties)
  {
    postfix_suffix += _debugdynamic.so ;
  }
  else if <variant>releasedynamic in $(properties)
  {
    postfix_suffix += _releasedynamic.so ;
  }

  # return the postfix
  return $(postfix_suffix) ;
}

If it gets called, it returns the correct postfix/suffix combination.
But I am not so sure, how to call it and how to append the returned
value to the list of libraries. I figured out, it is only called if
added to the requirements section of (e.g) an exe-rule, directly after
a feature (like this: <somefeature>@AppendCorrectPostfixAndSuffix).
But how do I get this to my list of library-base-names, that I want to
link with.
These list of library-base-names might look like this (or do they have
to be path-constants?):

  constant LIST_OF_LIBS : libfoo libbar ;

And I thought of creating my executable similar to one of the following:

  exe hello
    : hello.cpp $(LIST_OF_LIBS)@AppendCorrectPostfixAndSuffix ;

  exe hello2
    : hello.cpp
    : <file>$(LIST_OF_LIBS)@AppendCorrectPostfixAndSuffix ;

Maybe you could give me some more advice?
Thanks again,
DENIZ


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