Adding an inclusion path to a Waf configuration (C ++)

How to add include path to wscript?

I know that I can declare which files from which folders I want to include in any cpp file, for example:

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

but I do not want to install it for each file. I want to add the path to "global includes", so it will be included every time any file is compiled.

+5
source share
3 answers

I have found the answer. You should simply set the value "INCLUDES" to the list of paths you want. Do not forget to run again waf configure:)

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

, "use" bld.program(). 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

, :

​​ configure wscript. script (libmongoclient ), MONGOCLIENT.

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

(.pc) /usr/local/lib/pkgconfig. , lib . .

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}

​​ , ( MongoClient). .

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

configure .

0

All Articles