Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | # partially based on boost.py written by Gernot Vormayr |
| 2 | # written by Ruediger Sonderfeld <ruediger@c-plusplus.de>, 2008 |
| 3 | # modified by Bjoern Michaelsen, 2008 |
| 4 | # modified by Luca Fossati, 2008 |
| 5 | # rewritten for waf 1.5.1, Thomas Nagy, 2008 |
| 6 | # rewritten for waf 1.6.2, Sylvain Rouquette, 2011 |
| 7 | |
| 8 | ''' |
| 9 | |
| 10 | This is an extra tool, not bundled with the default waf binary. |
| 11 | To add the boost tool to the waf file: |
| 12 | $ ./waf-light --tools=compat15,boost |
| 13 | or, if you have waf >= 1.6.2 |
| 14 | $ ./waf update --files=boost |
| 15 | |
| 16 | When using this tool, the wscript will look like: |
| 17 | |
| 18 | def options(opt): |
| 19 | opt.load('compiler_cxx boost') |
| 20 | |
| 21 | def configure(conf): |
| 22 | conf.load('compiler_cxx boost') |
| 23 | conf.check_boost(lib='system filesystem') |
| 24 | |
| 25 | def build(bld): |
| 26 | bld(source='main.cpp', target='app', use='BOOST') |
| 27 | |
| 28 | Options are generated, in order to specify the location of boost includes/libraries. |
| 29 | The `check_boost` configuration function allows to specify the used boost libraries. |
| 30 | It can also provide default arguments to the --boost-mt command-line arguments. |
| 31 | Everything will be packaged together in a BOOST component that you can use. |
| 32 | |
| 33 | When using MSVC, a lot of compilation flags need to match your BOOST build configuration: |
| 34 | - you may have to add /EHsc to your CXXFLAGS or define boost::throw_exception if BOOST_NO_EXCEPTIONS is defined. |
| 35 | Errors: C4530 |
| 36 | - boost libraries will try to be smart and use the (pretty but often not useful) auto-linking feature of MSVC |
| 37 | So before calling `conf.check_boost` you might want to disabling by adding |
| 38 | conf.env.DEFINES_BOOST += ['BOOST_ALL_NO_LIB'] |
| 39 | Errors: |
| 40 | - boost might also be compiled with /MT, which links the runtime statically. |
| 41 | If you have problems with redefined symbols, |
| 42 | self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB'] |
| 43 | self.env['CXXFLAGS_%s' % var] += ['/MD', '/EHsc'] |
| 44 | Passing `--boost-linkage_autodetect` might help ensuring having a correct linkage in some basic cases. |
| 45 | |
| 46 | ''' |
| 47 | |
| 48 | import sys |
| 49 | import re |
| 50 | from waflib import Utils, Logs, Errors |
| 51 | from waflib.Configure import conf |
| 52 | from waflib.TaskGen import feature, after_method |
| 53 | |
Davide Pesavento | da1a4d3 | 2022-08-19 19:03:24 -0400 | [diff] [blame] | 54 | BOOST_LIBS = ['/usr/lib', '/usr/local/lib', '/opt/homebrew/lib', '/opt/local/lib', '/sw/lib', '/lib'] |
| 55 | BOOST_INCLUDES = ['/usr/include', '/usr/local/include', '/opt/homebrew/include', '/opt/local/include', '/sw/include'] |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 56 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 57 | BOOST_VERSION_FILE = 'boost/version.hpp' |
| 58 | BOOST_VERSION_CODE = ''' |
| 59 | #include <iostream> |
| 60 | #include <boost/version.hpp> |
| 61 | int main() { std::cout << BOOST_LIB_VERSION << ":" << BOOST_VERSION << std::endl; } |
| 62 | ''' |
| 63 | |
| 64 | BOOST_ERROR_CODE = ''' |
| 65 | #include <boost/system/error_code.hpp> |
| 66 | int main() { boost::system::error_code c; } |
| 67 | ''' |
| 68 | |
| 69 | PTHREAD_CODE = ''' |
| 70 | #include <pthread.h> |
| 71 | static void* f(void*) { return 0; } |
| 72 | int main() { |
| 73 | pthread_t th; |
| 74 | pthread_attr_t attr; |
| 75 | pthread_attr_init(&attr); |
| 76 | pthread_create(&th, &attr, &f, 0); |
| 77 | pthread_join(th, 0); |
| 78 | pthread_cleanup_push(0, 0); |
| 79 | pthread_cleanup_pop(0); |
| 80 | pthread_attr_destroy(&attr); |
| 81 | } |
| 82 | ''' |
| 83 | |
| 84 | BOOST_THREAD_CODE = ''' |
| 85 | #include <boost/thread.hpp> |
| 86 | int main() { boost::thread t; } |
| 87 | ''' |
| 88 | |
| 89 | BOOST_LOG_CODE = ''' |
| 90 | #include <boost/log/trivial.hpp> |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 91 | int main() { BOOST_LOG_TRIVIAL(info) << "boost_log is working"; } |
| 92 | ''' |
| 93 | |
| 94 | BOOST_LOG_SETUP_CODE = ''' |
| 95 | #include <boost/log/trivial.hpp> |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 96 | #include <boost/log/utility/setup/console.hpp> |
| 97 | #include <boost/log/utility/setup/common_attributes.hpp> |
| 98 | int main() { |
| 99 | using namespace boost::log; |
| 100 | add_common_attributes(); |
| 101 | add_console_log(std::clog, keywords::format = "%Message%"); |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 102 | BOOST_LOG_TRIVIAL(info) << "boost_log_setup is working"; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 103 | } |
| 104 | ''' |
| 105 | |
| 106 | # toolsets from {boost_dir}/tools/build/v2/tools/common.jam |
| 107 | PLATFORM = Utils.unversioned_sys_platform() |
| 108 | detect_intel = lambda env: (PLATFORM == 'win32') and 'iw' or 'il' |
| 109 | detect_clang = lambda env: (PLATFORM == 'darwin') and 'clang-darwin' or 'clang' |
| 110 | detect_mingw = lambda env: (re.search('MinGW', env.CXX[0])) and 'mgw' or 'gcc' |
| 111 | BOOST_TOOLSETS = { |
| 112 | 'borland': 'bcb', |
| 113 | 'clang': detect_clang, |
| 114 | 'como': 'como', |
| 115 | 'cw': 'cw', |
| 116 | 'darwin': 'xgcc', |
| 117 | 'edg': 'edg', |
| 118 | 'g++': detect_mingw, |
| 119 | 'gcc': detect_mingw, |
| 120 | 'icpc': detect_intel, |
| 121 | 'intel': detect_intel, |
| 122 | 'kcc': 'kcc', |
| 123 | 'kylix': 'bck', |
| 124 | 'mipspro': 'mp', |
| 125 | 'mingw': 'mgw', |
| 126 | 'msvc': 'vc', |
| 127 | 'qcc': 'qcc', |
| 128 | 'sun': 'sw', |
| 129 | 'sunc++': 'sw', |
| 130 | 'tru64cxx': 'tru', |
| 131 | 'vacpp': 'xlc' |
| 132 | } |
| 133 | |
| 134 | |
| 135 | def options(opt): |
| 136 | opt = opt.add_option_group('Boost Options') |
| 137 | opt.add_option('--boost-includes', type='string', |
| 138 | default='', dest='boost_includes', |
| 139 | help='''path to the directory where the boost includes are, |
| 140 | e.g., /path/to/boost_1_55_0/stage/include''') |
| 141 | opt.add_option('--boost-libs', type='string', |
| 142 | default='', dest='boost_libs', |
| 143 | help='''path to the directory where the boost libs are, |
| 144 | e.g., path/to/boost_1_55_0/stage/lib''') |
| 145 | opt.add_option('--boost-mt', action='store_true', |
| 146 | default=False, dest='boost_mt', |
| 147 | help='select multi-threaded libraries') |
| 148 | opt.add_option('--boost-abi', type='string', default='', dest='boost_abi', |
| 149 | help='''select libraries with tags (gd for debug, static is automatically added), |
| 150 | see doc Boost, Getting Started, chapter 6.1''') |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 151 | opt.add_option('--boost-linkage_autodetect', action='store_true', dest='boost_linkage_autodetect', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 152 | help="auto-detect boost linkage options (don't get used to it / might break other stuff)") |
| 153 | opt.add_option('--boost-toolset', type='string', |
| 154 | default='', dest='boost_toolset', |
| 155 | help='force a toolset e.g. msvc, vc90, \ |
| 156 | gcc, mingw, mgw45 (default: auto)') |
| 157 | py_version = '%d%d' % (sys.version_info[0], sys.version_info[1]) |
| 158 | opt.add_option('--boost-python', type='string', |
| 159 | default=py_version, dest='boost_python', |
| 160 | help='select the lib python with this version \ |
| 161 | (default: %s)' % py_version) |
| 162 | |
| 163 | |
| 164 | @conf |
| 165 | def __boost_get_version_file(self, d): |
| 166 | if not d: |
| 167 | return None |
| 168 | dnode = self.root.find_dir(d) |
| 169 | if dnode: |
| 170 | return dnode.find_node(BOOST_VERSION_FILE) |
| 171 | return None |
| 172 | |
| 173 | @conf |
| 174 | def boost_get_version(self, d): |
| 175 | """silently retrieve the boost version number""" |
| 176 | node = self.__boost_get_version_file(d) |
| 177 | if node: |
| 178 | try: |
| 179 | txt = node.read() |
| 180 | except EnvironmentError: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 181 | Logs.error('Could not read the file %r' % node.abspath()) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 182 | else: |
| 183 | re_but1 = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.+)"', re.M) |
| 184 | m1 = re_but1.search(txt) |
| 185 | re_but2 = re.compile('^#define\\s+BOOST_VERSION\\s+(\\d+)', re.M) |
| 186 | m2 = re_but2.search(txt) |
| 187 | if m1 and m2: |
| 188 | return (m1.group(1), m2.group(1)) |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 189 | return self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[d], execute=True, define_ret=True).split(':') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 190 | |
| 191 | @conf |
| 192 | def boost_get_includes(self, *k, **kw): |
| 193 | includes = k and k[0] or kw.get('includes', None) |
| 194 | if includes and self.__boost_get_version_file(includes): |
| 195 | return includes |
| 196 | for d in self.environ.get('INCLUDE', '').split(';') + BOOST_INCLUDES: |
| 197 | if self.__boost_get_version_file(d): |
| 198 | return d |
| 199 | if includes: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 200 | self.end_msg('headers not found in %s' % includes, 'YELLOW') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 201 | self.fatal('The configuration failed') |
| 202 | else: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 203 | self.end_msg('headers not found, please provide a --boost-includes argument (see help)', 'YELLOW') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 204 | self.fatal('The configuration failed') |
| 205 | |
| 206 | |
| 207 | @conf |
| 208 | def boost_get_toolset(self, cc): |
| 209 | toolset = cc |
| 210 | if not cc: |
| 211 | build_platform = Utils.unversioned_sys_platform() |
| 212 | if build_platform in BOOST_TOOLSETS: |
| 213 | cc = build_platform |
| 214 | else: |
| 215 | cc = self.env.CXX_NAME |
| 216 | if cc in BOOST_TOOLSETS: |
| 217 | toolset = BOOST_TOOLSETS[cc] |
| 218 | return isinstance(toolset, str) and toolset or toolset(self.env) |
| 219 | |
| 220 | |
| 221 | @conf |
| 222 | def __boost_get_libs_path(self, *k, **kw): |
| 223 | ''' return the lib path and all the files in it ''' |
| 224 | if 'files' in kw: |
| 225 | return self.root.find_dir('.'), Utils.to_list(kw['files']) |
| 226 | libs = k and k[0] or kw.get('libs', None) |
| 227 | if libs: |
| 228 | path = self.root.find_dir(libs) |
| 229 | files = path.ant_glob('*boost_*') |
| 230 | if not libs or not files: |
| 231 | for d in self.environ.get('LIB', '').split(';') + BOOST_LIBS: |
| 232 | if not d: |
| 233 | continue |
| 234 | path = self.root.find_dir(d) |
| 235 | if path: |
| 236 | files = path.ant_glob('*boost_*') |
| 237 | if files: |
| 238 | break |
| 239 | path = self.root.find_dir(d + '64') |
| 240 | if path: |
| 241 | files = path.ant_glob('*boost_*') |
| 242 | if files: |
| 243 | break |
| 244 | if not path: |
| 245 | if libs: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 246 | self.end_msg('libs not found in %s' % libs, 'YELLOW') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 247 | self.fatal('The configuration failed') |
| 248 | else: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 249 | self.end_msg('libs not found, please provide a --boost-libs argument (see help)', 'YELLOW') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 250 | self.fatal('The configuration failed') |
| 251 | |
| 252 | self.to_log('Found the boost path in %r with the libraries:' % path) |
| 253 | for x in files: |
| 254 | self.to_log(' %r' % x) |
| 255 | return path, files |
| 256 | |
| 257 | @conf |
| 258 | def boost_get_libs(self, *k, **kw): |
| 259 | ''' |
| 260 | return the lib path and the required libs |
| 261 | according to the parameters |
| 262 | ''' |
| 263 | path, files = self.__boost_get_libs_path(**kw) |
| 264 | files = sorted(files, key=lambda f: (len(f.name), f.name), reverse=True) |
| 265 | toolset = self.boost_get_toolset(kw.get('toolset', '')) |
| 266 | toolset_pat = '(-%s[0-9]{0,3})' % toolset |
| 267 | version = '-%s' % self.env.BOOST_VERSION |
| 268 | |
| 269 | def find_lib(re_lib, files): |
| 270 | for file in files: |
| 271 | if re_lib.search(file.name): |
| 272 | self.to_log('Found boost lib %s' % file) |
| 273 | return file |
| 274 | return None |
| 275 | |
| 276 | def format_lib_name(name): |
| 277 | if name.startswith('lib') and self.env.CC_NAME != 'msvc': |
| 278 | name = name[3:] |
| 279 | return name[:name.rfind('.')] |
| 280 | |
| 281 | def match_libs(lib_names, is_static): |
| 282 | libs = [] |
| 283 | lib_names = Utils.to_list(lib_names) |
| 284 | if not lib_names: |
| 285 | return libs |
| 286 | t = [] |
| 287 | if kw.get('mt', False): |
| 288 | t.append('-mt') |
| 289 | if kw.get('abi', None): |
| 290 | t.append('%s%s' % (is_static and '-s' or '-', kw['abi'])) |
| 291 | elif is_static: |
| 292 | t.append('-s') |
| 293 | tags_pat = t and ''.join(t) or '' |
| 294 | ext = is_static and self.env.cxxstlib_PATTERN or self.env.cxxshlib_PATTERN |
| 295 | ext = ext.partition('%s')[2] # remove '%s' or 'lib%s' from PATTERN |
| 296 | |
| 297 | for lib in lib_names: |
| 298 | if lib == 'python': |
| 299 | # for instance, with python='27', |
| 300 | # accepts '-py27', '-py2', '27' and '2' |
| 301 | # but will reject '-py3', '-py26', '26' and '3' |
| 302 | tags = '({0})?((-py{2})|(-py{1}(?=[^0-9]))|({2})|({1}(?=[^0-9]))|(?=[^0-9])(?!-py))'.format(tags_pat, kw['python'][0], kw['python']) |
| 303 | else: |
| 304 | tags = tags_pat |
| 305 | # Trying libraries, from most strict match to least one |
| 306 | for pattern in ['boost_%s%s%s%s%s$' % (lib, toolset_pat, tags, version, ext), |
| 307 | 'boost_%s%s%s%s$' % (lib, tags, version, ext), |
| 308 | # Give up trying to find the right version |
| 309 | 'boost_%s%s%s%s$' % (lib, toolset_pat, tags, ext), |
| 310 | 'boost_%s%s%s$' % (lib, tags, ext), |
| 311 | 'boost_%s%s$' % (lib, ext), |
| 312 | 'boost_%s' % lib]: |
| 313 | self.to_log('Trying pattern %s' % pattern) |
| 314 | file = find_lib(re.compile(pattern), files) |
| 315 | if file: |
| 316 | libs.append(format_lib_name(file.name)) |
| 317 | break |
| 318 | else: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 319 | self.end_msg('lib %s not found in %s' % (lib, path.abspath()), 'YELLOW') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 320 | self.fatal('The configuration failed') |
| 321 | return libs |
| 322 | |
| 323 | return path.abspath(), match_libs(kw.get('lib', None), False), match_libs(kw.get('stlib', None), True) |
| 324 | |
| 325 | @conf |
| 326 | def _check_pthread_flag(self, *k, **kw): |
| 327 | ''' |
| 328 | Computes which flags should be added to CXXFLAGS and LINKFLAGS to compile in multi-threading mode |
| 329 | |
| 330 | Yes, we *need* to put the -pthread thing in CPPFLAGS because with GCC3, |
| 331 | boost/thread.hpp will trigger a #error if -pthread isn't used: |
| 332 | boost/config/requires_threads.hpp:47:5: #error "Compiler threading support |
| 333 | is not turned on. Please set the correct command line options for |
| 334 | threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)" |
| 335 | |
| 336 | Based on _BOOST_PTHREAD_FLAG(): https://github.com/tsuna/boost.m4/blob/master/build-aux/boost.m4 |
| 337 | ''' |
| 338 | |
| 339 | var = kw.get('uselib_store', 'BOOST') |
| 340 | |
| 341 | self.start_msg('Checking the flags needed to use pthreads') |
| 342 | |
| 343 | # The ordering *is* (sometimes) important. Some notes on the |
| 344 | # individual items follow: |
| 345 | # (none): in case threads are in libc; should be tried before -Kthread and |
| 346 | # other compiler flags to prevent continual compiler warnings |
| 347 | # -lpthreads: AIX (must check this before -lpthread) |
| 348 | # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) |
| 349 | # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) |
| 350 | # -llthread: LinuxThreads port on FreeBSD (also preferred to -pthread) |
| 351 | # -pthread: GNU Linux/GCC (kernel threads), BSD/GCC (userland threads) |
| 352 | # -pthreads: Solaris/GCC |
| 353 | # -mthreads: MinGW32/GCC, Lynx/GCC |
| 354 | # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it |
| 355 | # doesn't hurt to check since this sometimes defines pthreads too; |
| 356 | # also defines -D_REENTRANT) |
| 357 | # ... -mt is also the pthreads flag for HP/aCC |
| 358 | # -lpthread: GNU Linux, etc. |
| 359 | # --thread-safe: KAI C++ |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 360 | if Utils.unversioned_sys_platform() == 'sunos': |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 361 | # On Solaris (at least, for some versions), libc contains stubbed |
| 362 | # (non-functional) versions of the pthreads routines, so link-based |
| 363 | # tests will erroneously succeed. (We need to link with -pthreads/-mt/ |
| 364 | # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather |
| 365 | # a function called by this macro, so we could check for that, but |
| 366 | # who knows whether they'll stub that too in a future libc.) So, |
| 367 | # we'll just look for -pthreads and -lpthread first: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 368 | boost_pthread_flags = ['-pthreads', '-lpthread', '-mt', '-pthread'] |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 369 | else: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 370 | boost_pthread_flags = ['', '-lpthreads', '-Kthread', '-kthread', '-llthread', '-pthread', |
| 371 | '-pthreads', '-mthreads', '-lpthread', '--thread-safe', '-mt'] |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 372 | |
| 373 | for boost_pthread_flag in boost_pthread_flags: |
| 374 | try: |
| 375 | self.env.stash() |
| 376 | self.env['CXXFLAGS_%s' % var] += [boost_pthread_flag] |
| 377 | self.env['LINKFLAGS_%s' % var] += [boost_pthread_flag] |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 378 | self.check_cxx(code=PTHREAD_CODE, msg=None, use=var, execute=False, quiet=True) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 379 | self.end_msg(boost_pthread_flag) |
| 380 | return |
| 381 | except self.errors.ConfigurationError: |
| 382 | self.env.revert() |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 383 | self.end_msg('none') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 384 | |
| 385 | @conf |
| 386 | def check_boost(self, *k, **kw): |
| 387 | """ |
| 388 | Initialize boost libraries to be used. |
| 389 | |
| 390 | Keywords: you can pass the same parameters as with the command line (without "--boost-"). |
| 391 | Note that the command line has the priority, and should preferably be used. |
| 392 | """ |
| 393 | if not self.env['CXX']: |
| 394 | self.fatal('load a c++ compiler first, conf.load("compiler_cxx")') |
| 395 | |
| 396 | params = { |
| 397 | 'lib': k and k[0] or kw.get('lib', None), |
| 398 | 'stlib': kw.get('stlib', None) |
| 399 | } |
| 400 | for key, value in self.options.__dict__.items(): |
| 401 | if not key.startswith('boost_'): |
| 402 | continue |
| 403 | key = key[len('boost_'):] |
| 404 | params[key] = value and value or kw.get(key, '') |
| 405 | |
| 406 | var = kw.get('uselib_store', 'BOOST') |
| 407 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 408 | if not self.env.DONE_FIND_BOOST_COMMON: |
| 409 | self.find_program('dpkg-architecture', var='DPKG_ARCHITECTURE', mandatory=False) |
| 410 | if self.env.DPKG_ARCHITECTURE: |
| 411 | deb_host_multiarch = self.cmd_and_log([self.env.DPKG_ARCHITECTURE[0], '-qDEB_HOST_MULTIARCH']) |
| 412 | BOOST_LIBS.insert(0, '/usr/lib/%s' % deb_host_multiarch.strip()) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 413 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 414 | self.start_msg('Checking boost includes') |
| 415 | self.env['INCLUDES_%s' % var] = inc = self.boost_get_includes(**params) |
| 416 | versions = self.boost_get_version(inc) |
| 417 | self.env.BOOST_VERSION = versions[0] |
| 418 | self.env.BOOST_VERSION_NUMBER = int(versions[1]) |
| 419 | self.end_msg('%d.%d.%d' % (int(versions[1]) / 100000, |
| 420 | int(versions[1]) / 100 % 1000, |
| 421 | int(versions[1]) % 100)) |
| 422 | if Logs.verbose: |
| 423 | Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var]) |
| 424 | |
| 425 | self.env.DONE_FIND_BOOST_COMMON = True |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 426 | |
| 427 | if not params['lib'] and not params['stlib']: |
| 428 | return |
| 429 | if 'static' in kw or 'static' in params: |
| 430 | Logs.warn('boost: static parameter is deprecated, use stlib instead.') |
| 431 | self.start_msg('Checking boost libs') |
| 432 | path, libs, stlibs = self.boost_get_libs(**params) |
| 433 | self.env['LIBPATH_%s' % var] = [path] |
| 434 | self.env['STLIBPATH_%s' % var] = [path] |
| 435 | self.env['LIB_%s' % var] = libs |
| 436 | self.env['STLIB_%s' % var] = stlibs |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 437 | self.end_msg(' '.join(libs + stlibs)) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 438 | if Logs.verbose: |
| 439 | Logs.pprint('CYAN', ' path : %s' % path) |
| 440 | Logs.pprint('CYAN', ' shared libs : %s' % libs) |
| 441 | Logs.pprint('CYAN', ' static libs : %s' % stlibs) |
| 442 | |
| 443 | def has_shlib(lib): |
| 444 | return params['lib'] and lib in params['lib'] |
| 445 | def has_stlib(lib): |
| 446 | return params['stlib'] and lib in params['stlib'] |
| 447 | def has_lib(lib): |
| 448 | return has_shlib(lib) or has_stlib(lib) |
| 449 | if has_lib('thread'): |
| 450 | # not inside try_link to make check visible in the output |
| 451 | self._check_pthread_flag(k, kw) |
| 452 | |
| 453 | def try_link(): |
| 454 | if has_lib('system'): |
| 455 | self.check_cxx(fragment=BOOST_ERROR_CODE, use=var, execute=False) |
| 456 | if has_lib('thread'): |
| 457 | self.check_cxx(fragment=BOOST_THREAD_CODE, use=var, execute=False) |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 458 | if has_lib('log') or has_lib('log_setup'): |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 459 | if not has_lib('thread'): |
| 460 | self.env['DEFINES_%s' % var] += ['BOOST_LOG_NO_THREADS'] |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 461 | if has_shlib('log') or has_shlib('log_setup'): |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 462 | self.env['DEFINES_%s' % var] += ['BOOST_LOG_DYN_LINK'] |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 463 | if has_lib('log_setup'): |
| 464 | self.check_cxx(fragment=BOOST_LOG_SETUP_CODE, use=var, execute=False) |
| 465 | else: |
| 466 | self.check_cxx(fragment=BOOST_LOG_CODE, use=var, execute=False) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 467 | |
| 468 | if params.get('linkage_autodetect', False): |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 469 | self.start_msg('Attempting to detect boost linkage flags') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 470 | toolset = self.boost_get_toolset(kw.get('toolset', '')) |
| 471 | if toolset in ('vc',): |
| 472 | # disable auto-linking feature, causing error LNK1181 |
| 473 | # because the code wants to be linked against |
| 474 | self.env['DEFINES_%s' % var] += ['BOOST_ALL_NO_LIB'] |
| 475 | |
| 476 | # if no dlls are present, we guess the .lib files are not stubs |
| 477 | has_dlls = False |
| 478 | for x in Utils.listdir(path): |
| 479 | if x.endswith(self.env.cxxshlib_PATTERN % ''): |
| 480 | has_dlls = True |
| 481 | break |
| 482 | if not has_dlls: |
| 483 | self.env['STLIBPATH_%s' % var] = [path] |
| 484 | self.env['STLIB_%s' % var] = libs |
| 485 | del self.env['LIB_%s' % var] |
| 486 | del self.env['LIBPATH_%s' % var] |
| 487 | |
| 488 | # we attempt to play with some known-to-work CXXFLAGS combinations |
| 489 | for cxxflags in (['/MD', '/EHsc'], []): |
| 490 | self.env.stash() |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 491 | self.env['CXXFLAGS_%s' % var] += cxxflags |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 492 | try: |
| 493 | try_link() |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 494 | self.end_msg('ok: winning cxxflags combination: %s' % (self.env['CXXFLAGS_%s' % var])) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 495 | exc = None |
| 496 | break |
| 497 | except Errors.ConfigurationError as e: |
| 498 | self.env.revert() |
| 499 | exc = e |
| 500 | |
| 501 | if exc is not None: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 502 | self.end_msg('Could not auto-detect boost linking flags combination, you may report it to boost.py author', ex=exc) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 503 | self.fatal('The configuration failed') |
| 504 | else: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 505 | self.end_msg('Boost linkage flags auto-detection not implemented (needed ?) for this toolchain') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 506 | self.fatal('The configuration failed') |
| 507 | else: |
| 508 | self.start_msg('Checking for boost linkage') |
| 509 | try: |
| 510 | try_link() |
| 511 | except Errors.ConfigurationError as e: |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 512 | self.end_msg('Could not link against boost libraries using supplied options', 'YELLOW') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 513 | self.fatal('The configuration failed') |
| 514 | self.end_msg('ok') |
| 515 | |
| 516 | |
| 517 | @feature('cxx') |
| 518 | @after_method('apply_link') |
| 519 | def install_boost(self): |
| 520 | if install_boost.done or not Utils.is_win32 or not self.bld.cmd.startswith('install'): |
| 521 | return |
| 522 | install_boost.done = True |
| 523 | inst_to = getattr(self, 'install_path', '${BINDIR}') |
| 524 | for lib in self.env.LIB_BOOST: |
| 525 | try: |
| 526 | file = self.bld.find_file(self.env.cxxshlib_PATTERN % lib, self.env.LIBPATH_BOOST) |
| 527 | self.bld.install_files(inst_to, self.bld.root.find_node(file)) |
| 528 | except: |
| 529 | continue |
| 530 | install_boost.done = False |