0

Using waf 1.7.9 with extras/boost.py added, I find that you have to get the libraries at configuration time which makes it difficult to build targets with different sets of libraries. For example, I have two programs, one that needs only the header files from boost (program 'a') and another that uses some libraries (program 'b'). Here is my solution, but my question is: Is there a better/preferred way to do this?

#! /usr/bin/env python
# encoding: utf-8

def options(opt):
    opt.load('compiler_cxx boost')

def configure(conf):
    conf.load('compiler_cxx boost')

    conf.check_boost()
    conf.env.DEFINES_BOOST = ['NDEBUG']

    conf.env.LIB_BOOST_FILESYSTEM = conf.boost_get_libs('filesystem system')[-1]
    conf.env.LIB_BOOST_PROGRAM_OPTIONS = conf.boost_get_libs('program_options')[-1]

def build(bld):
    # program 'a' requires header-only part of boost
    bld.program(
        target = 'a',
        source = 'a.cpp',
        use = ['BOOST'] )

    # program 'b' requires link to some boost libraries
    bld.program(
        target = 'b',
        source = 'b.cpp',
        use = ['BOOST', 'BOOST_FILESYSTEM', 'BOOST_PROGRAM_OPTIONS'] )
John
  • 1,709
  • 1
  • 24
  • 27

1 Answers1

1

I don't know if there is a preferred way, but there is a way that I consider to have less magic to it. Basically, don't use the boost extra. You can specify exactly which libraries you want included without it.

#!/usr/bin/env python
# encoding: utf-8

def options(opt):
    opt.load('compiler_cxx')

def configure(conf):
    conf.load('compiler_cxx')

    # NOTE: The uselib_store keyword argument is not necessary here, it is just added
    # So that it is clear what name is required to use it during building.
    conf.check(compiler='cxx',lib='boost_filesystem',uselib_store='BOOST_FILESYSTEM')
    conf.check(compiler='cxx',lib='boost_program_options',uselib_store='BOOST_PROGRAM_OPTIONS')

    # NOTE: I don't know what DEFINES_BOOST is used for
    # conf.env.DEFINES_BOOST = ['NDEBUG']
    # This will give you a command line define
    conf.define('NDEBUG,'',quote=False)

def build(bld):
    # NOTE: Specifying include directories is dependent on your platform. I think Waf
    # takes care of this for you, but I'm putting it here for effect.
    inc = ['/usr/include']

    # program 'a' requires header-only part of boost
    bld.program(
        target = 'a',
        source = 'a.cpp',
        use = []
        includes = inc )

    # program 'b' requires link to some boost libraries
    bld.program(
        target = 'b',
        source = 'b.cpp',
        use = ['BOOST_FILESYSTEM', 'BOOST_PROGRAM_OPTIONS'],
        includes = inc)
Doran
  • 4,051
  • 2
  • 27
  • 41
  • +1 for an alternative way to do this and accepted for now, though I still need to test against the version of boost so I do want to use the extra/boost.py methods. Side note, the DEFINES_BOOST (and all other X_BOOST variables are used when you add use=['BOOST'] to the bld.program() method. – John Mar 08 '13 at 14:53