2013-02-10 12 views
5

wscriptへのインクルードパスを追加するにはどうしたらいいですか?Waf設定へのインクルードパスの追加(C++)

私は同じように、私は任意のCPPファイルあたりに含めるしたいフォルダからそのファイルを宣言することができます知っている:

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

が、私はすべてのファイルごとに設定する必要はありません。 "global includes"へのパスを追加したいので、ファイルがコンパイルされるたびにインクルードされます。

答えて

8

私は答えを見つけました。必要なパスのリストに「INCLUDES」の値を設定するだけです。 は再びwaf configureを実行することを忘れないでください:)

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

私はこの回答に独立して収束しましたが、これを行うためのOSに依存しない方法がもっとたくさんあることを願って私はここで迷っていました。 – meawoppl

2

私は「使用」オプションbld.programで()メソッドを使用して、これを行うための良い方法をワークアウトいくつかの時間を費やしました。ブーストライブラリを例にして、私は次のことを思いつきました。私はそれが助けて欲しい!

''' 
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') 
0

私はこれを考え出したし、次のような手順は次のとおりですWScriptのファイルで構成機能のチェック次

を追加しました。これはスクリプトに与えられたライブラリファイル(この場合は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)に依存するsepcificプログラムのビルド機能に依存関係を追加しました。以下は例です。

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

この後、configureを再度実行し、コードをビルドします。

+1

将来は、回答を複製するだけでなく、手元の質問への回答を調整してください。ここで、答えは*両方の質問に適用されます*あなたはそれらを捨てることができないほど十分に異なっています(一つはインクルードの追加を要求し、もう一つはライブラリの追加を要求します)。少なくとも、質問の*特定の状況*にどのように適用されるかをそれぞれ説明してください。 –