Boost logo

Boost-Build :

Subject: Re: [Boost-build] shared (prebuilt) libraries question
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-03-17 17:02:47


AMDG

On 03/17/2012 11:59 AM, George Georgiev wrote:
> I am relatively new to the Boost Build.
>
> I have a prebuilt library that I need to link against in my projects.
>
> To accomplish this I created a rule that defines the library. Then in
> the beginning of every jamfile where this library will be used I call
> this rule.
>
> There are several things that concerns me and I hope you guys will
> give me ideas how to do this better.
>
> 1. Is it possible I to avoid the need of calling the rule for every
> project. Somehow to define the library in the root and it to become
> visible for every project.

Yes. In Jamroot:

project /myproject ;
lib mylib ;

In other Jamfiles, you can refer to the library
as /myproject//mylib.

> 2. With adding more and more platforms to the project the rule becomes
> uglier and uglier. There is a lot of repeating requirements, see
> following the rule:
>
> <snip>
>
> I wish there is a way I to be able to structure this:
>
>
> rule xercesDefines
> {
> lib prebuilt_xerces
> # for all
> <include>$(ROOT)/xerces/include
> <define>XERCES_STATIC_LIBRARY
> ;
>
>
> if NT
> {
> lib advapi32
> :
> : <name>advapi32
> ;
> }
>
> lib prebuilt_xerces
> :
> : # for <toolset>msvc
> :
> :
> <library>advapi32
> ;
>
>
> if MACOSX
> {
> lib curl
> :
> : <name>curl
> ;
> }
>
> lib prebuilt_xerces
> :
> : # for <toolset>darwin
> :
> :
> <framework>CoreServices
> <library>curl
> <cxxflags>-fvisibility-inlines-hidden
> <cflags>-mmacosx-version-min=10.5
> ;
>

This is fairly easy using project requirements
and aliases.

project
  : usage-requirements
      <include>$(ROOT)/xerces/include
      <define>XERCES_STATIC_LIBRARY
  ;

lib advapi32 : : <name>advapi32 ;
lib curl : : <name>curl ;

alias prebuilt_xerces_requirements :
  <target-os>windows : <library>advapi ;
alias prebuilt_xerces_requirements :
  <target-os>darwin : <library>curl ;

alias prebuilt_xerces
  : prebuilt_xerces_requirements
    prebuilt_xerces_lib
  ;

# Use prebuilt_xerces_lib to select the library

> <snip>
>
> }
>
> 3. How I can avoid listing all combination per every prebuilt library.
> For example lib/linuxx86_64/gcc44libc211/dyn this part of the path is
> going to be the same for all prebuilt libraries. I wish there was a
> way I to say:
>
> lib prebuilt_xerces
> :
> : <file>$(ROOT)/xerces/$(libsubdirectory)/libxerces-c.a
> ;
>
> And libsubdirectory to be different based on the toolset, version,
> variant, address-model etc.
>

Well, clearly you have to start by defining
a rule that computes the correct path.

rule xerces-file ( properties * )
{
  local address-model =
    [ property.select <address-model> : $(properties) ] ;
  # ...
  return <file>$(ROOT)/xerces/... ;
}

Then use an indirect conditional to compute the file name:

searched-lib prebuilt_xerces : : <conditional>@xerces-file ;

In Christ,
Steven Watanabe


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