waf在构建时指定库,但在配置时获取全名

时间:2013-02-24 17:07:58

标签: c++ boost waf

使用添加了extras / boost.py的waf 1.7.9,我发现你必须在配置时获取库,这使得构建具有不同库集的目标变得困难。例如,我有两个程序,一个只需要来自boost(程序'a')的头文件,另一个只需要一些库(程序'b')。这是我的解决方案,但我的问题是:有更好/首选的方法吗?

#! /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'] )

1 个答案:

答案 0 :(得分:1)

我不知道是否有一种首选方式,但我认为有一种方法可以减少它的魔力。基本上,不要使用额外的提升。没有它,您可以准确指定要包含的库。

#!/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)