4
# partially based on boost.py written by Gernot Vormayr
5
# written by Ruediger Sonderfeld <ruediger@c-plusplus.de>, 2008
6
# modified by Bjoern Michaelsen, 2008
7
# modified by Luca Fossati, 2008
8
# rewritten for waf 1.5.1, Thomas Nagy, 2008
9
# rewritten for waf 1.6.2, Sylvain Rouquette, 2011
12
To add the boost tool to the waf file:
13
$ ./waf-light --tools=compat15,boost
14
or, if you have waf >= 1.6.2
15
$ ./waf update --files=boost
17
The wscript will look like:
20
opt.load('compiler_cxx boost')
23
conf.load('compiler_cxx boost')
24
conf.check_boost(lib='system filesystem', mt=True, static=True)
27
bld(source='main.cpp', target='app', use='BOOST')
32
from waflib import Utils, Logs
33
from waflib.Configure import conf
34
from waflib.Errors import WafError
36
BOOST_LIBS = ('/usr/lib', '/usr/local/lib',
37
'/opt/local/lib', '/sw/lib', '/lib')
38
BOOST_INCLUDES = ('/usr/include', '/usr/local/include',
39
'/opt/local/include', '/sw/include')
40
BOOST_VERSION_FILE = 'boost/version.hpp'
41
BOOST_VERSION_CODE = '''
43
#include <boost/version.hpp>
44
int main() { std::cout << BOOST_LIB_VERSION << std::endl; }
47
# toolsets from {boost_dir}/tools/build/v2/tools/common.jam
48
PLATFORM = Utils.unversioned_sys_platform()
49
detect_intel = lambda env: (PLATFORM == 'win32') and 'iw' or 'il'
50
detect_clang = lambda env: (PLATFORM == 'darwin') and 'clang-darwin' or 'clang'
51
detect_mingw = lambda env: (re.search('MinGW', env.CXX[0])) and 'mgw' or 'gcc'
54
'clang': detect_clang,
62
'intel': detect_intel,
77
opt.add_option('--boost-includes', type='string',
78
default='', dest='boost_includes',
79
help='''path to the boost directory where the includes are
80
e.g. /boost_1_45_0/include''')
81
opt.add_option('--boost-libs', type='string',
82
default='', dest='boost_libs',
83
help='''path to the directory where the boost libs are
84
e.g. /boost_1_45_0/stage/lib''')
85
opt.add_option('--boost-static', action='store_true',
86
default=False, dest='boost_static',
87
help='link static libraries')
88
opt.add_option('--boost-mt', action='store_true',
89
default=False, dest='boost_mt',
90
help='select multi-threaded libraries')
91
opt.add_option('--boost-abi', type='string', default='', dest='boost_abi',
92
help='''select libraries with tags (dgsyp, d for debug),
93
see doc Boost, Getting Started, chapter 6.1''')
94
opt.add_option('--boost-toolset', type='string',
95
default='', dest='boost_toolset',
96
help='force a toolset e.g. msvc, vc90, \
97
gcc, mingw, mgw45 (default: auto)')
98
py_version = '%d%d' % (sys.version_info[0], sys.version_info[1])
99
opt.add_option('--boost-python', type='string',
100
default=py_version, dest='boost_python',
101
help='select the lib python with this version \
102
(default: %s)' % py_version)
106
def __boost_get_version_file(self, dir):
108
return self.root.find_dir(dir).find_node(BOOST_VERSION_FILE)
114
def boost_get_version(self, dir):
115
"""silently retrieve the boost version number"""
116
re_but = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.*)"$', re.M)
118
val = re_but.search(self.__boost_get_version_file(dir).read()).group(1)
120
val = self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[dir],
121
execute=True, define_ret=True)
126
def boost_get_includes(self, *k, **kw):
127
includes = k and k[0] or kw.get('includes', None)
128
if includes and self.__boost_get_version_file(includes):
130
for dir in BOOST_INCLUDES:
131
if self.__boost_get_version_file(dir):
134
self.fatal('headers not found in %s' % includes)
136
self.fatal('headers not found, use --boost-includes=/path/to/boost')
140
def boost_get_toolset(self, cc):
143
build_platform = Utils.unversioned_sys_platform()
144
if build_platform in BOOST_TOOLSETS:
147
cc = self.env.CXX_NAME
148
if cc in BOOST_TOOLSETS:
149
toolset = BOOST_TOOLSETS[cc]
150
return isinstance(toolset, str) and toolset or toolset(self.env)
154
def __boost_get_libs_path(self, *k, **kw):
155
''' return the lib path and all the files in it '''
157
return self.root.find_dir('.'), Utils.to_list(kw['files'])
158
libs = k and k[0] or kw.get('libs', None)
160
path = self.root.find_dir(libs)
161
files = path.ant_glob('*boost_*')
162
if not libs or not files:
163
for dir in BOOST_LIBS:
165
path = self.root.find_dir(dir)
166
files = path.ant_glob('*boost_*')
169
path = self.root.find_dir(dir + '64')
170
files = path.ant_glob('*boost_*')
177
self.fatal('libs not found in %s' % libs)
179
self.fatal('libs not found, \
180
use --boost-includes=/path/to/boost/lib')
185
def boost_get_libs(self, *k, **kw):
187
return the lib path and the required libs
188
according to the parameters
190
path, files = self.__boost_get_libs_path(**kw)
192
if kw.get('mt', False):
194
if kw.get('abi', None):
196
tags = t and '(-%s)+' % '-'.join(t) or ''
197
toolset = '(-%s[0-9]{0,3})+' % self.boost_get_toolset(kw.get('toolset', ''))
198
version = '(-%s)+' % self.env.BOOST_VERSION
200
def find_lib(re_lib, files):
202
if re_lib.search(file.name):
206
def format_lib_name(name):
207
if name.startswith('lib'):
209
return name.split('.')[0]
212
for lib in Utils.to_list(k and k[0] or kw.get('lib', None)):
213
py = (lib == 'python') and '(-py%s)+' % kw['python'] or ''
214
# Trying libraries, from most strict match to least one
215
for pattern in ['boost_%s%s%s%s%s' % (lib, toolset, tags, py, version),
216
'boost_%s%s%s%s' % (lib, tags, py, version),
217
'boost_%s%s%s' % (lib, tags, version),
218
# Give up trying to find the right version
219
'boost_%s%s%s%s' % (lib, toolset, tags, py),
220
'boost_%s%s%s' % (lib, tags, py),
221
'boost_%s%s' % (lib, tags)]:
222
file = find_lib(re.compile(pattern), files)
224
libs.append(format_lib_name(file.name))
227
self.fatal('lib %s not found in %s' % (lib, path))
229
return path.abspath(), libs
233
def check_boost(self, *k, **kw):
237
You can pass the same parameters as the command line (without "--boost-"),
238
but the command line has the priority.
240
if not self.env['CXX']:
241
self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
243
params = {'lib': k and k[0] or kw.get('lib', None)}
244
for key, value in self.options.__dict__.items():
245
if not key.startswith('boost_'):
247
key = key[len('boost_'):]
248
params[key] = value and value or kw.get(key, '')
250
var = kw.get('uselib_store', 'BOOST')
252
self.start_msg('Checking boost includes')
254
self.env['INCLUDES_%s' % var] = self.boost_get_includes(**params)
255
self.env.BOOST_VERSION = self.boost_get_version(self.env['INCLUDES_%s' % var])
257
self.end_msg("not found", 'YELLOW')
259
self.end_msg(self.env.BOOST_VERSION)
261
Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var])
263
if not params['lib']:
265
self.start_msg('Checking boost libs')
267
suffix = params.get('static', 'ST') or ''
268
path, libs = self.boost_get_libs(**params)
270
self.end_msg("not found", 'YELLOW')
272
self.env['%sLIBPATH_%s' % (suffix, var)] = [path]
273
self.env['%sLIB_%s' % (suffix, var)] = libs
276
Logs.pprint('CYAN', ' path : %s' % path)
277
Logs.pprint('CYAN', ' libs : %s' % libs)