添加包含Waf配置的路径(C ++)

时间:2013-02-10 19:08:51

标签: c++ python compilation include waf

如何添加wscript的包含路径?

我知道我可以根据任何cpp文件声明我想要包含哪些文件夹的文件,例如:

def build(bld):
    bld(features='c cxx cxxprogram',
        includes='include', 
        source='main.cpp', 
        target='app', 
        use=['M','mylib'], 
        lib=['dl'])

但我不想为每个文件设置它。我想添加一个路径到"全球包括"因此,每次编译任何文件时都会包含它。

3 个答案:

答案 0 :(得分:9)

我找到了答案。您只需将“INCLUDES”的值设置为所需的路径列表即可。 不要忘记再次运行waf configure:)

def configure(cfg):
    cfg.env.append_value('INCLUDES', ['include'])

答案 1 :(得分:2)

我花了一些时间使用bld.program()方法中的“use”选项来做一个好方法。以boost库为例,我想出了以下内容。我希望它有所帮助!

'''
run waf with -v option and look at the command line arguments given
to the compiler for the three cases.

you may need to include the boost tool into waf to test this script.
'''
def options(opt):
    opt.load('compiler_cxx boost')

def configure(cfg):
    cfg.load('compiler_cxx boost')
    cfg.check_boost()

    cfg.env.DEFINES_BOOST = ['NDEBUG']

    ### the following line would be very convenient
    ###     cfg.env.USE_MYCONFIG = ['BOOST']
    ### but this works too:
    def copy_config(cfg, name, new_name):
        i = '_'+name
        o = '_'+new_name
        l = len(i)
        d = {}
        for key in cfg.env.keys():
            if key[-l:] == i:
                d[key.replace(i,o)] = cfg.env[key]
        cfg.env.update(d)

    copy_config(cfg, 'BOOST', 'MYCONFIG')

    # now modify the new env/configuration
    # this adds the appropriate "boost_" to the beginning
    # of the library and the "-mt" to the end if needed
    cfg.env.LIB_MYCONFIG = cfg.boost_get_libs('filesystem system')[-1]

def build(bld):

    # basic boost (no libraries)
    bld.program(target='test-boost2', source='test-boost.cpp',
                use='BOOST')

    # myconfig: boost with two libraries
    bld.program(target='test-boost',  source='test-boost.cpp',
                use='MYCONFIG')

    # warning:
    # notice the NDEBUG shows up twice in the compilation
    # because MYCONFIG already includes everything in BOOST
    bld.program(target='test-boost3', source='test-boost.cpp',
                use='BOOST MYCONFIG')

答案 2 :(得分:0)

我想出来了,步骤如下:

在wscript文件中的configure函数中添加了以下检查。这告诉脚本检查给定的库文件(在本例中为libmongoclient),并将此检查的结果存储在MONGOCLIENT中。

conf.check_cfg(package='libmongoclient', args=['--cflags', '--libs'], uselib_store='MONGOCLIENT', mandatory=True)

完成此步骤后,我们需要将包配置文件(.pc)添加到/ usr / local / lib / pkgconfig路径中。这是我们指定lib和headers的路径的文件。粘贴下面这个文件的内容。

prefix=/usr/local 
libdir=/usr/local/lib 
includedir=/usr/local/include/mongo

Name: libmongoclient 
Description: Mongodb C++ driver 
Version: 0.2 
Libs: -L${libdir} -lmongoclient 
Cflags: -I${includedir}

将依赖项添加到sepcific程序的构建函数中,该函数依赖于上述库(即MongoClient)。以下是一个例子。

mobility = bld( target='bin/mobility', features='cxx cxxprogram', source='src/main.cpp', use='mob-objects MONGOCLIENT', )

在此之后,再次运行configure,并构建您的代码。