Boost logo

Boost-Build :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2007-07-24 11:10:43


I tried to work out Volodyas proposal a little more.
It looks very promising what I got so far.

I generalized the concept and introduced an external-lib target
which derives from searched-lib. The generator is in the file
external.jam.

Basically a <name> property is added, that allows indirect rule calls,
i.e. <name>@myrule .

This works on linux so far. However I expect a problem on msvc
compilers: The static (searched) boost libraries are prefixed with
a "lib" tag which is not part of the compilers policy, but boost
policy. So I think the boost tag rule will need to be altered to
capture this. What do you think?

My solution is in the both attached files.

I appreciate any feedback!

Roland

import property-set ;
import type ;
import generators ;
import "class" : new ;

type.register EXTERNAL_LIB : : SEARCHED_LIB ;

# The following is needed to suppress the pre and suffix,
# since these are usually not allowed on searched libs.
# I am not sure if these better go into tools/types
type.set-generated-target-prefix SEARCHED_LIB : : "" ;
type.set-generated-target-suffix SEARCHED_LIB : : "" ;

class external-lib-generator : searched-lib-generator
{
        import indirect ;
        import set ;
        import property-set ;

        rule __init__ ( )
        {
                # bypassing the base class init is questionable, but it seems to work ...
                generator.__init__ external-lib-generator : : EXTERNAL_LIB ;
        }

        rule run ( project name ? : property-set : sources * : multiple ? )
        {
                local real-name = [ $(property-set).get <name> ] ;
                local props = [ set.difference [ $(property-set).raw ] : <name>$(real-name) ] ;
                if $(real-name)-not-empty
                {
                        local rule-name = [ MATCH ^@(.*) : $(real-name) ] ;
                        if $(rule-name)
                        {
                                real-name = [ indirect.call $(rule-name) $(name) : SEARCHED_LIB : $(property-set) ] ;
                        }
                }

                return [ searched-lib-generator.run
                                    $(project) $(name)
                                : [ property-set.create $(props) <name>$(real-name) ]
                                : $(sources)
                                : $(multiple)
                        ] ;
        }
}

generators.register [ new external-lib-generator ] ;

import external ;
import property-set ;
import common ;

####################################################################################
# The following three items must be generated by the build system
layout = ;
local build-id = ;
constant BOOST_VERSION : 1.34.0 ;

####################################################################################
# This is the part that must be shared between the source tree and
# the pre-built lib project

layout ?= versioned ;
layout-$(layout) = true ;

local version-tag = [ MATCH "^([^.]+)[.]([^.]+)[.]([^.]+)" : $(BOOST_VERSION) ] ;
if $(version-tag[3]) = 0
{
    version-tag = $(version-tag[1-2]) ;
}

constant BOOST_VERSION_TAG : $(version-tag:J="_") ;

if $(build-id)
{
    constant BUILD_ID : [ regex.replace $(build-id) "[*\\/:.\"\' ]" "_" ] ;
}

rule tag ( name : type ? : property-set )
{
    # the SEARCHED_LIB is necessary but not yet present in the original
    if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB SEARCHED_LIB
    {
        if $(layout) = versioned
        {
            local result = [ common.format-name
                <base> <toolset> <threading> <runtime> -$(BOOST_VERSION_TAG)
                -$(BUILD_ID)
                : $(name) : $(type) : $(property-set) ] ;
            
            # Optionally add version suffix.
            # On NT, library with version suffix won't be recognized
            # by linkers. On CYGWIN, we get strage duplicate symbol
            # errors when library is generated with version suffix.
            # On OSX, version suffix is not needed -- the linker expets
            # libFoo.1.2.3.dylib format.
            # AIX linkers don't accept version suffixes either.
            if $(type) = SHARED_LIB &&
              ! ( [ $(property-set).get <target-os> ] in windows cygwin darwin aix )
            {
                result = $(result).$(BOOST_VERSION) ;
            }
            
            return $(result) ;
        }
        else
        {
            return [ common.format-name
                <base> <threading> <runtime> -$(BUILD_ID)
                : $(name) : $(type) : $(property-set) ] ;
        }
    }
}
####################################################################################

# the <name> has been extended by allowing a rule
# external-lib targets are derivatives of SEARCHED_LIB type
# so they are recognized by the linking target

project boost
        : requirements <name>@tag ;

external-lib boost_thread ;
external-lib boost_program_options ;


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