|
|
| 1 |
#!/usr/bin/env python |
1 |
#!/usr/bin/env python |
| 2 |
# encoding: utf-8 |
2 |
# encoding: utf-8 |
| 3 |
# |
3 |
# |
| 4 |
# partially based on boost.py written by Gernot Vormayr |
4 |
# partially based on boost.py written by Gernot Vormayr |
| 5 |
# written by Ruediger Sonderfeld <ruediger@c-plusplus.de>, 2008 |
5 |
# written by Ruediger Sonderfeld <ruediger@c-plusplus.de>, 2008 |
| 6 |
# modified by Bjoern Michaelsen, 2008 |
6 |
# modified by Bjoern Michaelsen, 2008 |
| 7 |
# modified by Luca Fossati, 2008 |
7 |
# modified by Luca Fossati, 2008 |
| 8 |
# rewritten for waf 1.5.1, Thomas Nagy, 2008 |
8 |
# rewritten for waf 1.5.1, Thomas Nagy, 2008 |
| 9 |
# rewritten for waf 1.6.2, Sylvain Rouquette, 2011 |
9 |
# rewritten for waf 1.6.2, Sylvain Rouquette, 2011 |
| 10 |
|
10 |
|
| 11 |
''' |
11 |
''' |
| 12 |
To add the boost tool to the waf file: |
12 |
|
| 13 |
$ ./waf-light --tools=compat15,boost |
13 |
This is an extra tool, not bundled with the default waf binary. |
| 14 |
or, if you have waf >= 1.6.2 |
14 |
To add the boost tool to the waf file: |
| 15 |
$ ./waf update --files=boost |
15 |
$ ./waf-light --tools=compat15,boost |
| 16 |
|
16 |
or, if you have waf >= 1.6.2 |
| 17 |
The wscript will look like: |
17 |
$ ./waf update --files=boost |
| 18 |
|
18 |
|
| 19 |
def options(opt): |
19 |
When using this tool, the wscript will look like: |
| 20 |
opt.load('compiler_cxx boost') |
20 |
|
| 21 |
|
21 |
def options(opt): |
| 22 |
def configure(conf): |
22 |
opt.load('compiler_cxx boost') |
| 23 |
conf.load('compiler_cxx boost') |
23 |
|
| 24 |
conf.check_boost(lib='system filesystem', mt=True, static=True) |
24 |
def configure(conf): |
| 25 |
|
25 |
conf.load('compiler_cxx boost') |
| 26 |
def build(bld): |
26 |
conf.check_boost(lib='system filesystem') |
| 27 |
bld(source='main.cpp', target='app', use='BOOST') |
27 |
|
| 28 |
''' |
28 |
def build(bld): |
| 29 |
|
29 |
bld(source='main.cpp', target='app', use='BOOST') |
| 30 |
import sys |
30 |
|
| 31 |
import re |
31 |
Options are generated, in order to specify the location of boost includes/libraries. |
| 32 |
from waflib import Utils, Logs |
32 |
The `check_boost` configuration function allows to specify the used boost libraries. |
| 33 |
from waflib.Configure import conf |
33 |
It can also provide default arguments to the --boost-static and --boost-mt command-line arguments. |
| 34 |
from waflib.Errors import WafError |
34 |
Everything will be packaged together in a BOOST component that you can use. |
| 35 |
|
35 |
|
| 36 |
BOOST_LIBS = ('/usr/lib', '/usr/local/lib', |
36 |
When using MSVC, a lot of compilation flags need to match your BOOST build configuration: |
| 37 |
'/opt/local/lib', '/sw/lib', '/lib') |
37 |
- you may have to add /EHsc to your CXXFLAGS or define boost::throw_exception if BOOST_NO_EXCEPTIONS is defined. |
| 38 |
BOOST_INCLUDES = ('/usr/include', '/usr/local/include', |
38 |
Errors: C4530 |
| 39 |
'/opt/local/include', '/sw/include') |
39 |
- boost libraries will try to be smart and use the (pretty but often not useful) auto-linking feature of MSVC |
| 40 |
BOOST_VERSION_FILE = 'boost/version.hpp' |
40 |
So before calling `conf.check_boost` you might want to disabling by adding: |
| 41 |
BOOST_VERSION_CODE = ''' |
41 |
conf.env.DEFINES_BOOST += ['BOOST_ALL_NO_LIB'] |
| 42 |
#include <iostream> |
42 |
Errors: |
| 43 |
#include <boost/version.hpp> |
43 |
- boost might also be compiled with /MT, which links the runtime statically. |
| 44 |
int main() { std::cout << BOOST_LIB_VERSION << std::endl; } |
44 |
If you have problems with redefined symbols, |
| 45 |
''' |
45 |
self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB'] |
| 46 |
|
46 |
self.env['CXXFLAGS_%s' % var] += ['/MD', '/EHsc'] |
| 47 |
# toolsets from {boost_dir}/tools/build/v2/tools/common.jam |
47 |
Passing `--boost-linkage_autodetect` might help ensuring having a correct linkage in some basic cases. |
| 48 |
PLATFORM = Utils.unversioned_sys_platform() |
48 |
|
| 49 |
detect_intel = lambda env: (PLATFORM == 'win32') and 'iw' or 'il' |
49 |
''' |
| 50 |
detect_clang = lambda env: (PLATFORM == 'darwin') and 'clang-darwin' or 'clang' |
50 |
|
| 51 |
detect_mingw = lambda env: (re.search('MinGW', env.CXX[0])) and 'mgw' or 'gcc' |
51 |
import sys |
| 52 |
BOOST_TOOLSETS = { |
52 |
import re |
| 53 |
'borland': 'bcb', |
53 |
from waflib import Utils, Logs, Errors |
| 54 |
'clang': detect_clang, |
54 |
from waflib.Configure import conf |
| 55 |
'como': 'como', |
55 |
|
| 56 |
'cw': 'cw', |
56 |
BOOST_LIBS = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib'] |
| 57 |
'darwin': 'xgcc', |
57 |
BOOST_INCLUDES = ['/usr/include', '/usr/local/include', '/opt/local/include', '/sw/include'] |
| 58 |
'edg': 'edg', |
58 |
BOOST_VERSION_FILE = 'boost/version.hpp' |
| 59 |
'g++': detect_mingw, |
59 |
BOOST_VERSION_CODE = ''' |
| 60 |
'gcc': detect_mingw, |
60 |
#include <iostream> |
| 61 |
'icpc': detect_intel, |
61 |
#include <boost/version.hpp> |
| 62 |
'intel': detect_intel, |
62 |
int main() { std::cout << BOOST_LIB_VERSION << std::endl; } |
| 63 |
'kcc': 'kcc', |
63 |
''' |
| 64 |
'kylix': 'bck', |
64 |
|
| 65 |
'mipspro': 'mp', |
65 |
# toolsets from {boost_dir}/tools/build/v2/tools/common.jam |
| 66 |
'mingw': 'mgw', |
66 |
PLATFORM = Utils.unversioned_sys_platform() |
| 67 |
'msvc': 'vc', |
67 |
detect_intel = lambda env: (PLATFORM == 'win32') and 'iw' or 'il' |
| 68 |
'qcc': 'qcc', |
68 |
detect_clang = lambda env: (PLATFORM == 'darwin') and 'clang-darwin' or 'clang' |
| 69 |
'sun': 'sw', |
69 |
detect_mingw = lambda env: (re.search('MinGW', env.CXX[0])) and 'mgw' or 'gcc' |
| 70 |
'sunc++': 'sw', |
70 |
BOOST_TOOLSETS = { |
| 71 |
'tru64cxx': 'tru', |
71 |
'borland': 'bcb', |
| 72 |
'vacpp': 'xlc' |
72 |
'clang': detect_clang, |
| 73 |
} |
73 |
'como': 'como', |
| 74 |
|
74 |
'cw': 'cw', |
| 75 |
|
75 |
'darwin': 'xgcc', |
| 76 |
def options(opt): |
76 |
'edg': 'edg', |
| 77 |
opt.add_option('--boost-includes', type='string', |
77 |
'g++': detect_mingw, |
| 78 |
default='', dest='boost_includes', |
78 |
'gcc': detect_mingw, |
| 79 |
help='''path to the boost directory where the includes are |
79 |
'icpc': detect_intel, |
| 80 |
e.g. /boost_1_45_0/include''') |
80 |
'intel': detect_intel, |
| 81 |
opt.add_option('--boost-libs', type='string', |
81 |
'kcc': 'kcc', |
| 82 |
default='', dest='boost_libs', |
82 |
'kylix': 'bck', |
| 83 |
help='''path to the directory where the boost libs are |
83 |
'mipspro': 'mp', |
| 84 |
e.g. /boost_1_45_0/stage/lib''') |
84 |
'mingw': 'mgw', |
| 85 |
opt.add_option('--boost-static', action='store_true', |
85 |
'msvc': 'vc', |
| 86 |
default=False, dest='boost_static', |
86 |
'qcc': 'qcc', |
| 87 |
help='link static libraries') |
87 |
'sun': 'sw', |
| 88 |
opt.add_option('--boost-mt', action='store_true', |
88 |
'sunc++': 'sw', |
| 89 |
default=False, dest='boost_mt', |
89 |
'tru64cxx': 'tru', |
| 90 |
help='select multi-threaded libraries') |
90 |
'vacpp': 'xlc' |
| 91 |
opt.add_option('--boost-abi', type='string', default='', dest='boost_abi', |
91 |
} |
| 92 |
help='''select libraries with tags (dgsyp, d for debug), |
92 |
|
| 93 |
see doc Boost, Getting Started, chapter 6.1''') |
93 |
|
| 94 |
opt.add_option('--boost-toolset', type='string', |
94 |
def options(opt): |
| 95 |
default='', dest='boost_toolset', |
95 |
opt.add_option('--boost-includes', type='string', |
| 96 |
help='force a toolset e.g. msvc, vc90, \ |
96 |
default='', dest='boost_includes', |
| 97 |
gcc, mingw, mgw45 (default: auto)') |
97 |
help='''path to the boost includes root (~boost root) |
| 98 |
py_version = '%d%d' % (sys.version_info[0], sys.version_info[1]) |
98 |
e.g. /path/to/boost_1_47_0''') |
| 99 |
opt.add_option('--boost-python', type='string', |
99 |
opt.add_option('--boost-libs', type='string', |
| 100 |
default=py_version, dest='boost_python', |
100 |
default='', dest='boost_libs', |
| 101 |
help='select the lib python with this version \ |
101 |
help='''path to the directory where the boost libs are |
| 102 |
(default: %s)' % py_version) |
102 |
e.g. /path/to/boost_1_47_0/stage/lib''') |
| 103 |
|
103 |
opt.add_option('--boost-static', action='store_true', |
| 104 |
|
104 |
default=False, dest='boost_static', |
| 105 |
@conf |
105 |
help='link with static boost libraries (.lib/.a)') |
| 106 |
def __boost_get_version_file(self, dir): |
106 |
opt.add_option('--boost-mt', action='store_true', |
| 107 |
try: |
107 |
default=False, dest='boost_mt', |
| 108 |
return self.root.find_dir(dir).find_node(BOOST_VERSION_FILE) |
108 |
help='select multi-threaded libraries') |
| 109 |
except: |
109 |
opt.add_option('--boost-abi', type='string', default='', dest='boost_abi', |
| 110 |
return None |
110 |
help='''select libraries with tags (dgsyp, d for debug), |
| 111 |
|
111 |
see doc Boost, Getting Started, chapter 6.1''') |
| 112 |
|
112 |
opt.add_option('--boost-linkage_autodetect', action="store_true", dest='boost_linkage_autodetect', |
| 113 |
@conf |
113 |
help="auto-detect boost linkage options (don't get used to it / might break other stuff)") |
| 114 |
def boost_get_version(self, dir): |
114 |
opt.add_option('--boost-toolset', type='string', |
| 115 |
"""silently retrieve the boost version number""" |
115 |
default='', dest='boost_toolset', |
| 116 |
re_but = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.*)"$', re.M) |
116 |
help='force a toolset e.g. msvc, vc90, \ |
| 117 |
try: |
117 |
gcc, mingw, mgw45 (default: auto)') |
| 118 |
val = re_but.search(self.__boost_get_version_file(dir).read()).group(1) |
118 |
py_version = '%d%d' % (sys.version_info[0], sys.version_info[1]) |
| 119 |
except: |
119 |
opt.add_option('--boost-python', type='string', |
| 120 |
val = self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[dir], |
120 |
default=py_version, dest='boost_python', |
| 121 |
execute=True, define_ret=True) |
121 |
help='select the lib python with this version \ |
| 122 |
return val |
122 |
(default: %s)' % py_version) |
| 123 |
|
123 |
|
| 124 |
|
124 |
|
| 125 |
@conf |
125 |
@conf |
| 126 |
def boost_get_includes(self, *k, **kw): |
126 |
def __boost_get_version_file(self, dir): |
| 127 |
includes = k and k[0] or kw.get('includes', None) |
127 |
try: |
| 128 |
if includes and self.__boost_get_version_file(includes): |
128 |
return self.root.find_dir(dir).find_node(BOOST_VERSION_FILE) |
| 129 |
return includes |
129 |
except: |
| 130 |
for dir in BOOST_INCLUDES: |
130 |
return None |
| 131 |
if self.__boost_get_version_file(dir): |
131 |
|
| 132 |
return dir |
132 |
|
| 133 |
if includes: |
133 |
@conf |
| 134 |
self.fatal('headers not found in %s' % includes) |
134 |
def boost_get_version(self, dir): |
| 135 |
else: |
135 |
"""silently retrieve the boost version number""" |
| 136 |
self.fatal('headers not found, use --boost-includes=/path/to/boost') |
136 |
re_but = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.*)"$', re.M) |
| 137 |
|
137 |
try: |
| 138 |
|
138 |
val = re_but.search(self.__boost_get_version_file(dir).read()).group(1) |
| 139 |
@conf |
139 |
except: |
| 140 |
def boost_get_toolset(self, cc): |
140 |
val = self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[dir], execute=False, define_ret=True) |
| 141 |
toolset = cc |
141 |
return val |
| 142 |
if not cc: |
142 |
|
| 143 |
build_platform = Utils.unversioned_sys_platform() |
143 |
|
| 144 |
if build_platform in BOOST_TOOLSETS: |
144 |
@conf |
| 145 |
cc = build_platform |
145 |
def boost_get_includes(self, *k, **kw): |
| 146 |
else: |
146 |
includes = k and k[0] or kw.get('includes', None) |
| 147 |
cc = self.env.CXX_NAME |
147 |
if includes and self.__boost_get_version_file(includes): |
| 148 |
if cc in BOOST_TOOLSETS: |
148 |
return includes |
| 149 |
toolset = BOOST_TOOLSETS[cc] |
149 |
for dir in BOOST_INCLUDES: |
| 150 |
return isinstance(toolset, str) and toolset or toolset(self.env) |
150 |
if self.__boost_get_version_file(dir): |
| 151 |
|
151 |
return dir |
| 152 |
|
152 |
if includes: |
| 153 |
@conf |
153 |
self.fatal('headers not found in %s' % includes) |
| 154 |
def __boost_get_libs_path(self, *k, **kw): |
154 |
else: |
| 155 |
''' return the lib path and all the files in it ''' |
155 |
self.fatal('headers not found, please provide a --boost-includes argument (see help)') |
| 156 |
if 'files' in kw: |
156 |
|
| 157 |
return self.root.find_dir('.'), Utils.to_list(kw['files']) |
157 |
|
| 158 |
libs = k and k[0] or kw.get('libs', None) |
158 |
@conf |
| 159 |
if libs: |
159 |
def boost_get_toolset(self, cc): |
| 160 |
path = self.root.find_dir(libs) |
160 |
toolset = cc |
| 161 |
files = path.ant_glob('*boost_*') |
161 |
if not cc: |
| 162 |
if not libs or not files: |
162 |
build_platform = Utils.unversioned_sys_platform() |
| 163 |
for dir in BOOST_LIBS: |
163 |
if build_platform in BOOST_TOOLSETS: |
| 164 |
try: |
164 |
cc = build_platform |
| 165 |
path = self.root.find_dir(dir) |
165 |
else: |
| 166 |
files = path.ant_glob('*boost_*') |
166 |
cc = self.env.CXX_NAME |
| 167 |
if files: |
167 |
if cc in BOOST_TOOLSETS: |
| 168 |
break |
168 |
toolset = BOOST_TOOLSETS[cc] |
| 169 |
path = self.root.find_dir(dir + '64') |
169 |
return isinstance(toolset, str) and toolset or toolset(self.env) |
| 170 |
files = path.ant_glob('*boost_*') |
170 |
|
| 171 |
if files: |
171 |
|
| 172 |
break |
172 |
@conf |
| 173 |
except: |
173 |
def __boost_get_libs_path(self, *k, **kw): |
| 174 |
path = None |
174 |
''' return the lib path and all the files in it ''' |
| 175 |
if not path: |
175 |
if 'files' in kw: |
| 176 |
if libs: |
176 |
return self.root.find_dir('.'), Utils.to_list(kw['files']) |
| 177 |
self.fatal('libs not found in %s' % libs) |
177 |
libs = k and k[0] or kw.get('libs', None) |
| 178 |
else: |
178 |
if libs: |
| 179 |
self.fatal('libs not found, \ |
179 |
path = self.root.find_dir(libs) |
| 180 |
use --boost-includes=/path/to/boost/lib') |
180 |
files = path.ant_glob('*boost_*') |
| 181 |
return path, files |
181 |
if not libs or not files: |
| 182 |
|
182 |
for dir in BOOST_LIBS: |
| 183 |
|
183 |
try: |
| 184 |
@conf |
184 |
path = self.root.find_dir(dir) |
| 185 |
def boost_get_libs(self, *k, **kw): |
185 |
files = path.ant_glob('*boost_*') |
| 186 |
''' |
186 |
if files: |
| 187 |
return the lib path and the required libs |
187 |
break |
| 188 |
according to the parameters |
188 |
path = self.root.find_dir(dir + '64') |
| 189 |
''' |
189 |
files = path.ant_glob('*boost_*') |
| 190 |
path, files = self.__boost_get_libs_path(**kw) |
190 |
if files: |
| 191 |
t = [] |
191 |
break |
| 192 |
if kw.get('mt', False): |
192 |
except: |
| 193 |
t.append('mt') |
193 |
path = None |
| 194 |
if kw.get('abi', None): |
194 |
if not path: |
| 195 |
t.append(kw['abi']) |
195 |
if libs: |
| 196 |
tags = t and '(-%s)+' % '-'.join(t) or '' |
196 |
self.fatal('libs not found in %s' % libs) |
| 197 |
toolset = '(-%s[0-9]{0,3})+' % self.boost_get_toolset(kw.get('toolset', '')) |
197 |
else: |
| 198 |
version = '(-%s)+' % self.env.BOOST_VERSION |
198 |
self.fatal('libs not found, please provide a --boost-libs argument (see help)') |
| 199 |
|
199 |
|
| 200 |
def find_lib(re_lib, files): |
200 |
self.to_log('Found the boost path in %r with the libraries:' % path) |
| 201 |
for file in files: |
201 |
for x in files: |
| 202 |
if re_lib.search(file.name): |
202 |
self.to_log(' %r' % x) |
| 203 |
return file |
203 |
return path, files |
| 204 |
return None |
204 |
|
| 205 |
|
205 |
@conf |
| 206 |
def format_lib_name(name): |
206 |
def boost_get_libs(self, *k, **kw): |
| 207 |
if name.startswith('lib'): |
207 |
''' |
| 208 |
name = name[3:] |
208 |
return the lib path and the required libs |
| 209 |
return name.split('.')[0] |
209 |
according to the parameters |
| 210 |
|
210 |
''' |
| 211 |
libs = [] |
211 |
path, files = self.__boost_get_libs_path(**kw) |
| 212 |
for lib in Utils.to_list(k and k[0] or kw.get('lib', None)): |
212 |
t = [] |
| 213 |
py = (lib == 'python') and '(-py%s)+' % kw['python'] or '' |
213 |
if kw.get('mt', False): |
| 214 |
# Trying libraries, from most strict match to least one |
214 |
t.append('mt') |
| 215 |
for pattern in ['boost_%s%s%s%s%s' % (lib, toolset, tags, py, version), |
215 |
if kw.get('abi', None): |
| 216 |
'boost_%s%s%s%s' % (lib, tags, py, version), |
216 |
t.append(kw['abi']) |
| 217 |
'boost_%s%s%s' % (lib, tags, version), |
217 |
tags = t and '(-%s)+' % '-'.join(t) or '' |
| 218 |
# Give up trying to find the right version |
218 |
toolset = self.boost_get_toolset(kw.get('toolset', '')) |
| 219 |
'boost_%s%s%s%s' % (lib, toolset, tags, py), |
219 |
toolset_pat = '(-%s[0-9]{0,3})+' % toolset |
| 220 |
'boost_%s%s%s' % (lib, tags, py), |
220 |
version = '(-%s)+' % self.env.BOOST_VERSION |
| 221 |
'boost_%s%s' % (lib, tags)]: |
221 |
|
| 222 |
file = find_lib(re.compile(pattern), files) |
222 |
def find_lib(re_lib, files): |
| 223 |
if file: |
223 |
for file in files: |
| 224 |
libs.append(format_lib_name(file.name)) |
224 |
if re_lib.search(file.name): |
| 225 |
break |
225 |
self.to_log('Found boost lib %s' % file) |
| 226 |
else: |
226 |
return file |
| 227 |
self.fatal('lib %s not found in %s' % (lib, path)) |
227 |
return None |
| 228 |
|
228 |
|
| 229 |
return path.abspath(), libs |
229 |
def format_lib_name(name): |
| 230 |
|
230 |
if name.startswith('lib') and self.env.CC_NAME != 'msvc': |
| 231 |
|
231 |
name = name[3:] |
| 232 |
@conf |
232 |
return name[:name.rfind('.')] |
| 233 |
def check_boost(self, *k, **kw): |
233 |
|
| 234 |
""" |
234 |
found_libs = [] |
| 235 |
initialize boost |
235 |
libs = [] |
| 236 |
|
236 |
for lib in Utils.to_list(k and k[0] or kw.get('lib', None)): |
| 237 |
You can pass the same parameters as the command line (without "--boost-"), |
237 |
py = (lib == 'python') and '(-py%s)+' % kw['python'] or '' |
| 238 |
but the command line has the priority. |
238 |
# Trying libraries, from most strict match to least one |
| 239 |
""" |
239 |
for pattern in ['boost_%s%s%s%s%s' % (lib, toolset_pat, tags, py, version), |
| 240 |
if not self.env['CXX']: |
240 |
'boost_%s%s%s%s' % (lib, tags, py, version), |
| 241 |
self.fatal('load a c++ compiler first, conf.load("compiler_cxx")') |
241 |
'boost_%s%s%s' % (lib, tags, version), |
| 242 |
|
242 |
# Give up trying to find the right version |
| 243 |
params = {'lib': k and k[0] or kw.get('lib', None)} |
243 |
'boost_%s%s%s%s' % (lib, toolset_pat, tags, py), |
| 244 |
for key, value in self.options.__dict__.items(): |
244 |
'boost_%s%s%s' % (lib, tags, py), |
| 245 |
if not key.startswith('boost_'): |
245 |
'boost_%s%s' % (lib, tags)]: |
| 246 |
continue |
246 |
self.to_log('Trying pattern %s' % pattern) |
| 247 |
key = key[len('boost_'):] |
247 |
file = find_lib(re.compile(pattern), files) |
| 248 |
params[key] = value and value or kw.get(key, '') |
248 |
if file: |
| 249 |
|
249 |
found_libs.append (lib) |
| 250 |
var = kw.get('uselib_store', 'BOOST') |
250 |
libs.append(format_lib_name(file.name)) |
| 251 |
|
251 |
break |
| 252 |
self.start_msg('Checking boost includes') |
252 |
else: |
| 253 |
try: |
253 |
# Don't fail, but just ignore failed library |
| 254 |
self.env['INCLUDES_%s' % var] = self.boost_get_includes(**params) |
254 |
Logs.error ('lib %s not found in %s' % (lib, path.abspath())) |
| 255 |
self.env.BOOST_VERSION = self.boost_get_version(self.env['INCLUDES_%s' % var]) |
255 |
|
| 256 |
except WafError: |
256 |
return path.abspath(), libs, found_libs |
| 257 |
self.end_msg("not found", 'YELLOW') |
257 |
|
| 258 |
raise |
258 |
|
| 259 |
self.end_msg(self.env.BOOST_VERSION) |
259 |
@conf |
| 260 |
if Logs.verbose: |
260 |
def check_boost(self, *k, **kw): |
| 261 |
Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var]) |
261 |
""" |
| 262 |
|
262 |
Initialize boost libraries to be used. |
| 263 |
if not params['lib']: |
263 |
|
| 264 |
return |
264 |
Keywords: you can pass the same parameters as with the command line (without "--boost-"). |
| 265 |
self.start_msg('Checking boost libs') |
265 |
Note that the command line has the priority, and should preferably be used. |
| 266 |
try: |
266 |
""" |
| 267 |
suffix = params.get('static', 'ST') or '' |
267 |
if not self.env['CXX']: |
| 268 |
path, libs = self.boost_get_libs(**params) |
268 |
self.fatal('load a c++ compiler first, conf.load("compiler_cxx")') |
| 269 |
except WafError: |
269 |
|
| 270 |
self.end_msg("not found", 'YELLOW') |
270 |
params = {'lib': k and k[0] or kw.get('lib', None)} |
| 271 |
raise |
271 |
for key, value in self.options.__dict__.items(): |
| 272 |
self.env['%sLIBPATH_%s' % (suffix, var)] = [path] |
272 |
if not key.startswith('boost_'): |
| 273 |
self.env['%sLIB_%s' % (suffix, var)] = libs |
273 |
continue |
| 274 |
self.end_msg('ok') |
274 |
key = key[len('boost_'):] |
| 275 |
if Logs.verbose: |
275 |
params[key] = value and value or kw.get(key, '') |
| 276 |
Logs.pprint('CYAN', ' path : %s' % path) |
276 |
|
| 277 |
Logs.pprint('CYAN', ' libs : %s' % libs) |
277 |
var = kw.get('uselib_store', 'BOOST') |
| 278 |
|
278 |
|
|
|
279 |
self.start_msg('Checking boost includes') |
| 280 |
self.env['INCLUDES_%s' % var] = inc = self.boost_get_includes(**params) |
| 281 |
self.env.BOOST_VERSION = self.boost_get_version(inc) |
| 282 |
self.end_msg(self.env.BOOST_VERSION) |
| 283 |
if Logs.verbose: |
| 284 |
Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var]) |
| 285 |
|
| 286 |
if not params['lib']: |
| 287 |
return |
| 288 |
self.start_msg('Checking boost libs') |
| 289 |
suffix = params.get('static', None) and 'ST' or '' |
| 290 |
path, libs, found_libs = self.boost_get_libs(**params) |
| 291 |
self.env['%sLIBPATH_%s' % (suffix, var)] = [path] |
| 292 |
self.env['%sLIB_%s' % (suffix, var)] = libs |
| 293 |
self.env['%s_FOUND_LIBS' % var] = found_libs |
| 294 |
|
| 295 |
if kw.get('require_all', True): |
| 296 |
if found_libs != Utils.to_list(k and k[0] or kw.get('lib', None)): |
| 297 |
required_libs = Utils.to_list(k and k[0] or kw.get('lib', None)) |
| 298 |
not_found = [lib for lib in required_libs if lib not in found_libs] |
| 299 |
self.fatal('boost libraries %s not found' % (str(not_found))) |
| 300 |
|
| 301 |
self.end_msg('ok') |
| 302 |
if Logs.verbose: |
| 303 |
Logs.pprint('CYAN', ' path : %s' % path) |
| 304 |
Logs.pprint('CYAN', ' libs : %s' % libs) |
| 305 |
|
| 306 |
|
| 307 |
def try_link(): |
| 308 |
if 'system' in params['lib']: |
| 309 |
self.check_cxx( |
| 310 |
fragment="\n".join([ |
| 311 |
'#include <boost/system/error_code.hpp>', |
| 312 |
'int main() { boost::system::error_code c; }', |
| 313 |
]), |
| 314 |
use=var, |
| 315 |
execute=False, |
| 316 |
) |
| 317 |
if 'thread' in params['lib']: |
| 318 |
self.check_cxx( |
| 319 |
fragment="\n".join([ |
| 320 |
'#include <boost/thread.hpp>', |
| 321 |
'int main() { boost::thread t; }', |
| 322 |
]), |
| 323 |
use=var, |
| 324 |
execute=False, |
| 325 |
) |
| 326 |
|
| 327 |
if params.get('linkage_autodetect', False): |
| 328 |
self.start_msg("Attempting to detect boost linkage flags") |
| 329 |
toolset = self.boost_get_toolset(kw.get('toolset', '')) |
| 330 |
if toolset in ['vc']: |
| 331 |
# disable auto-linking feature, causing error LNK1181 |
| 332 |
# because the code wants to be linked against |
| 333 |
self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB'] |
| 334 |
|
| 335 |
# if no dlls are present, we guess the .lib files are not stubs |
| 336 |
has_dlls = False |
| 337 |
for x in Utils.listdir(path): |
| 338 |
if x.endswith(self.env.cxxshlib_PATTERN % ''): |
| 339 |
has_dlls = True |
| 340 |
break |
| 341 |
if not has_dlls: |
| 342 |
self.env['STLIBPATH_%s' % var] = [path] |
| 343 |
self.env['STLIB_%s' % var] = libs |
| 344 |
del self.env['LIB_%s' % var] |
| 345 |
del self.env['LIBPATH_%s' % var] |
| 346 |
|
| 347 |
# we attempt to play with some known-to-work CXXFLAGS combinations |
| 348 |
for cxxflags in (['/MD', '/EHsc'], []): |
| 349 |
self.env.stash() |
| 350 |
self.env["CXXFLAGS_%s" % var] += cxxflags |
| 351 |
try: |
| 352 |
try_link() |
| 353 |
self.end_msg("ok: winning cxxflags combination: %s" % (self.env["CXXFLAGS_%s" % var])) |
| 354 |
e = None |
| 355 |
break |
| 356 |
except Errors.ConfigurationError as exc: |
| 357 |
self.env.revert() |
| 358 |
e = exc |
| 359 |
|
| 360 |
if e is not None: |
| 361 |
self.fatal("Could not auto-detect boost linking flags combination, you may report it to boost.py author", ex=e) |
| 362 |
else: |
| 363 |
self.fatal("Boost linkage flags auto-detection not implemented (needed ?) for this toolchain") |
| 364 |
else: |
| 365 |
self.start_msg('Checking for boost linkage') |
| 366 |
try: |
| 367 |
try_link() |
| 368 |
except Errors.ConfigurationError as e: |
| 369 |
self.fatal("Could not link against boost libraries using supplied options") |
| 370 |
self.end_msg('ok') |
| 371 |
|