3
# WARNING! Do not edit! http://waf.googlecode.com/svn/docs/wafbook/single.html#_obtaining_the_waf_file
6
if sys.hexversion < 0x020400f0: from sets import Set as set
8
To add the boost tool to the waf file:
9
$ ./waf-light --tools=compat15,boost
10
or, if you have waf >= 1.6.2
11
$ ./waf update --files=boost
13
The wscript will look like:
16
opt.load('compiler_cxx boost')
19
conf.load('compiler_cxx boost')
20
conf.check_boost(lib='system filesystem', mt=True, static=True)
23
bld(source='main.cpp', target='app', use='BOOST')
27
from waflib import Utils,Logs
28
from waflib.Configure import conf
29
BOOST_LIBS=('/usr/lib','/usr/local/lib','/opt/local/lib','/sw/lib','/lib')
30
BOOST_INCLUDES=('/usr/include','/usr/local/include','/opt/local/include','/sw/include')
31
BOOST_VERSION_FILE='boost/version.hpp'
32
BOOST_VERSION_CODE='''
34
#include <boost/version.hpp>
35
int main() { std::cout << BOOST_LIB_VERSION << std::endl; }
37
PLATFORM=Utils.unversioned_sys_platform()
38
detect_intel=lambda env:(PLATFORM=='win32')and'iw'or'il'
39
detect_clang=lambda env:(PLATFORM=='darwin')and'clang-darwin'or'clang'
40
detect_mingw=lambda env:(re.search('MinGW',env.CXX[0]))and'mgw'or'gcc'
41
BOOST_TOOLSETS={'borland':'bcb','clang':detect_clang,'como':'como','cw':'cw','darwin':'xgcc','edg':'edg','g++':detect_mingw,'gcc':detect_mingw,'icpc':detect_intel,'intel':detect_intel,'kcc':'kcc','kylix':'bck','mipspro':'mp','mingw':'mgw','msvc':'vc','qcc':'qcc','sun':'sw','sunc++':'sw','tru64cxx':'tru','vacpp':'xlc'}
43
opt.add_option('--boost-includes',type='string',default='',dest='boost_includes',help='''path to the boost directory where the includes are
44
e.g. /boost_1_45_0/include''')
45
opt.add_option('--boost-libs',type='string',default='',dest='boost_libs',help='''path to the directory where the boost libs are
46
e.g. /boost_1_45_0/stage/lib''')
47
opt.add_option('--boost-static',action='store_true',default=False,dest='boost_static',help='link static libraries')
48
opt.add_option('--boost-mt',action='store_true',default=False,dest='boost_mt',help='select multi-threaded libraries')
49
opt.add_option('--boost-abi',type='string',default='',dest='boost_abi',help='''select libraries with tags (dgsyp, d for debug),
50
see doc Boost, Getting Started, chapter 6.1''')
51
opt.add_option('--boost-toolset',type='string',default='',dest='boost_toolset',help='force a toolset e.g. msvc, vc90, \
52
gcc, mingw, mgw45 (default: auto)')
53
py_version='%d%d'%(sys.version_info[0],sys.version_info[1])
54
opt.add_option('--boost-python',type='string',default=py_version,dest='boost_python',help='select the lib python with this version \
55
(default: %s)'%py_version)
56
def __boost_get_version_file(self,dir):
58
return self.root.find_dir(dir).find_node(BOOST_VERSION_FILE)
61
def boost_get_version(self,dir):
62
re_but=re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.*)"$',re.M)
64
val=re_but.search(self.__boost_get_version_file(dir).read()).group(1)
66
val=self.check_cxx(fragment=BOOST_VERSION_CODE,includes=[dir],execute=True,define_ret=True)
68
def boost_get_includes(self,*k,**kw):
69
includes=k and k[0]or kw.get('includes',None)
70
if includes and self.__boost_get_version_file(includes):
72
for dir in BOOST_INCLUDES:
73
if self.__boost_get_version_file(dir):
76
self.fatal('headers not found in %s'%includes)
78
self.fatal('headers not found, use --boost-includes=/path/to/boost')
79
def boost_get_toolset(self,cc):
82
build_platform=Utils.unversioned_sys_platform()
83
if build_platform in BOOST_TOOLSETS:
87
if cc in BOOST_TOOLSETS:
88
toolset=BOOST_TOOLSETS[cc]
89
return isinstance(toolset,str)and toolset or toolset(self.env)
90
def __boost_get_libs_path(self,*k,**kw):
91
''' return the lib path and all the files in it '''
93
return self.root.find_dir('.'),Utils.to_list(kw['files'])
94
libs=k and k[0]or kw.get('libs',None)
96
path=self.root.find_dir(libs)
97
files=path.ant_glob('*boost_*')
98
if not libs or not files:
99
for dir in BOOST_LIBS:
101
path=self.root.find_dir(dir)
102
files=path.ant_glob('*boost_*')
105
path=self.root.find_dir(dir+'64')
106
files=path.ant_glob('*boost_*')
113
self.fatal('libs not found in %s'%libs)
115
self.fatal('libs not found, \
116
use --boost-includes=/path/to/boost/lib')
118
def boost_get_libs(self,*k,**kw):
120
return the lib path and the required libs
121
according to the parameters
123
path,files=self.__boost_get_libs_path(**kw)
125
if kw.get('mt',False):
127
if kw.get('abi',None):
129
tags=t and'(-%s)+'%'-'.join(t)or''
130
toolset='(-%s[0-9]{0,3})+'%self.boost_get_toolset(kw.get('toolset',''))
131
version='(-%s)+'%self.env.BOOST_VERSION
132
def find_lib(re_lib,files):
134
if re_lib.search(file.name):
137
def format_lib_name(name):
138
if name.startswith('lib'):
140
return name.split('.')[0]
142
for lib in Utils.to_list(k and k[0]or kw.get('lib',None)):
143
py=(lib=='python')and'(-py%s)+'%kw['python']or''
144
for pattern in['boost_%s%s%s%s%s'%(lib,toolset,tags,py,version),'boost_%s%s%s%s'%(lib,tags,py,version),'boost_%s%s%s'%(lib,tags,version),'boost_%s%s%s%s'%(lib,toolset,tags,py),'boost_%s%s%s'%(lib,tags,py),'boost_%s%s'%(lib,tags)]:
145
file=find_lib(re.compile(pattern),files)
147
libs.append(format_lib_name(file.name))
150
self.fatal('lib %s not found in %s'%(lib,path))
151
return path.abspath(),libs
152
def check_boost(self,*k,**kw):
153
if not self.env['CXX']:
154
self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
155
params={'lib':k and k[0]or kw.get('lib',None)}
156
for key,value in self.options.__dict__.items():
157
if not key.startswith('boost_'):
159
key=key[len('boost_'):]
160
params[key]=value and value or kw.get(key,'')
161
var=kw.get('uselib_store','BOOST')
162
self.start_msg('Checking boost includes')
163
self.env['INCLUDES_%s'%var]=self.boost_get_includes(**params)
164
self.env.BOOST_VERSION=self.boost_get_version(self.env['INCLUDES_%s'%var])
165
self.end_msg(self.env.BOOST_VERSION)
167
Logs.pprint('CYAN',' path : %s'%self.env['INCLUDES_%s'%var])
168
if not params['lib']:
170
self.start_msg('Checking boost libs')
171
suffix=params.get('static','ST')or''
172
path,libs=self.boost_get_libs(**params)
173
self.env['%sLIBPATH_%s'%(suffix,var)]=[path]
174
self.env['%sLIB_%s'%(suffix,var)]=libs
177
Logs.pprint('CYAN',' path : %s'%path)
178
Logs.pprint('CYAN',' libs : %s'%libs)
180
conf(__boost_get_version_file)
181
conf(boost_get_version)
182
conf(boost_get_includes)
183
conf(boost_get_toolset)
184
conf(__boost_get_libs_path)
b'\\ No newline at end of file'