-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_boost.py
186 lines (158 loc) · 5.88 KB
/
find_boost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# -*- python -*-
# stdlib imports ---
import os
import os.path as osp
import subprocess
# waf imports ---
import waflib.Utils
import waflib.Logs as msg
from waflib.Configure import conf
#
_heptooldir = osp.dirname(osp.abspath(__file__))
def options(ctx):
ctx.load('hwaf-base', tooldir=_heptooldir)
ctx.load('boost')
ctx.add_option(
'--with-boost',
default=None,
help="Look for boost at the given path")
return
def configure(ctx):
ctx.load('hwaf-base', tooldir=_heptooldir)
return
@conf
def find_boost(ctx, **kwargs):
'''
find_boost instructs hwaf to find a boost installation.
keyword arguments are the same than of the waflib.extras.boost.check_boost
function (see @waflib.extras.boost.)
Relevant keyword args:
"lib": list of boost libraries to check
"includes": path to the boost includes
"libs": path to boost libraries
'''
ctx.load('hwaf-base', tooldir=_heptooldir)
if not ctx.env.HWAF_FOUND_C_COMPILER:
ctx.fatal('load a C compiler first')
pass
if not ctx.env.HWAF_FOUND_CXX_COMPILER:
ctx.fatal('load a C++ compiler first')
pass
if not ctx.env.HWAF_FOUND_PYTHON:
ctx.load('find_python')
ctx.find_python()
pass
xx,yy = ctx.env.PYTHON_VERSION.split(".")[:2]
ctx.options.boost_python = "%s%s" % (xx,yy)
for k in ('with_boost', 'with_boost_incdir', 'with_boost_libdir'):
if not getattr(ctx.options, k, None):
continue
topdir = getattr(ctx.options, k)
topdir = ctx.hwaf_subst_vars(topdir)
setattr(ctx.options, k, topdir)
pass
ctx.load('boost')
boost_libs = kwargs.get('lib', '''\
chrono date_time filesystem graph iostreams
math_c99 math_c99f math_tr1 math_tr1f
prg_exec_monitor program_options
random regex serialization
signals system thread
unit_test_framework wave wserialization
''')
kwargs['lib'] = boost_libs
kwargs['mt'] = kwargs.get('mt', False)
kwargs['static'] = kwargs.get('static', False)
kwargs['use'] = waflib.Utils.to_list(kwargs.get('use', [])) + ['python']
# get include/lib-dir from command-line or from API
kwargs['includes'] = getattr(ctx.options, 'with_boost_incdir', kwargs.get('includes', None))
kwargs['libs'] = getattr(ctx.options, 'with_boost_libdir', kwargs.get('libs', None))
# rationalize types
if kwargs['libs'] is None: kwargs['libs'] = []
if kwargs['includes'] is None: kwargs['includes'] = []
# waflib.boost only checks under /usr/lib
# for machines where dual-libs (32/64) are installed, also inject:
if ctx.is_64b():
libpath = [
'/usr/lib64', '/usr/local/lib64', '/opt/local/lib64',
'/sw/lib64', '/lib64',
]
import waflib.extras.boost as _mod
if _mod.BOOST_LIBS[0] != libpath[0]:
_mod.BOOST_LIBS = libpath + _mod.BOOST_LIBS
pass
# clean-up non existing directories
libdirs = []
for dirname in waflib.Utils.to_list(kwargs['libs']):
dirname = ctx.hwaf_subst_vars(dirname)
d = ctx.root.find_dir(dirname)
if not d: continue
libdirs.append(dirname)
pass
kwargs['libs'] = libdirs[:]
# also clean-up non existing directories in options.boost_{includes,libs}
for k in ('boost_includes', 'boost_libs'):
v = getattr(ctx.options, k, None)
if not v: continue
dirs = []
for dirname in waflib.Utils.to_list(v):
dirname = ctx.hwaf_subst_vars(dirname)
d = ctx.root.find_dir(dirname)
if not d: continue
dirs.append(dirname)
pass
setattr(ctx.options, k, dirs)
pass
# override default for uselib_store (default="BOOST")
kwargs['uselib_store'] = "boost"
# set with_boost_xxx variables for 'check_with' benefit
setattr(ctx.options, 'with_boost_incdir', kwargs['includes'])
setattr(ctx.options, 'with_boost_libdir', kwargs['libs'])
def _get_with_boost():
o = getattr(ctx.options, 'with_boost', [])
if o:
return o
libs = waflib.Utils.to_list(kwargs.get('libs', []))
if libs and len(libs)>0:
return osp.dirname(libs[0])
return None
setattr(ctx.options, 'with_boost', _get_with_boost())
ctx.check_with(
ctx.check_boost,
"boost",
**kwargs)
## hack for boost_python...
_boost_libs_list = waflib.Utils.to_list(boost_libs)
if _boost_libs_list:
_boost_lib_name = _boost_libs_list[0]
boost_lib_tmpl = [lib for lib in ctx.env['LIB_boost']
if _boost_lib_name in lib][0]
boost_python = boost_lib_tmpl.replace("boost_"+_boost_lib_name,
'boost_python')
ctx.env['LIB_boost'] = ctx.env['LIB_boost'] + [boost_python]
for libname in _boost_libs_list + ['python',]:
libname = libname.strip()
for n in ('INCLUDES',
'LIBPATH',
'LINKFLAGS'):
ctx.env['%s_boost-%s'%(n,libname)] = ctx.env['%s_boost'%n][:]
lib = []
for i in ctx.env['LIB_boost']:
if i.startswith("boost_%s-"%libname):
lib.append(i)
break
if i == "boost_%s"%libname:
lib.append(i)
break
else:
msg.warn("could not find a linkopt for [boost_%s] among: %s" %
(libname,ctx.env['LIB_boost']))
ctx.env['LIB_boost-%s'%libname] = lib[:]
# register the boost module
import sys
modname = 'waflib.extras.boost'
fname = sys.modules[modname].__file__
if fname.endswith('.pyc'): fname = fname[:-1]
ctx.hwaf_export_module(ctx.root.find_node(fname).abspath())
ctx.env.HWAF_FOUND_BOOST = 1
return