From 6005a6260f11cc899a95414bc443a698177b33c7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mouret Date: Mon, 24 Jul 2017 12:22:49 +0200 Subject: [PATCH] improve tbb detection (for OSX support) --- waf_tools/sferes.py | 10 ++++++++++ waf_tools/tbb.py | 40 ++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/waf_tools/sferes.py b/waf_tools/sferes.py index a114e2a..1ab6c22 100644 --- a/waf_tools/sferes.py +++ b/waf_tools/sferes.py @@ -12,6 +12,16 @@ import glob +# check if a lib exists for both osx (darwin) and GNU/linux +def check_lib(self, name, path): + if self.env['DEST_OS']=='darwin': + libname = name + '.dylib' + else: + libname = name + '.so' + res = self.find_file(libname, path) + lib = res[:-len(libname)-1] + return res, lib + def create_variants(bld, source, use, uselib, variants, includes=". ../ ../../", cxxflags='', diff --git a/waf_tools/tbb.py b/waf_tools/tbb.py index 0b8e238..57793c8 100644 --- a/waf_tools/tbb.py +++ b/waf_tools/tbb.py @@ -1,14 +1,12 @@ -#! /usr/bin/env python +#!/usr/bin/env python # encoding: utf-8 -# JB Mouret - 2014 """ Quick n dirty tbb detection """ -import os from waflib.Configure import conf -from waflib import Utils, Logs +import sferes def options(opt): opt.add_option('--tbb', type='string', help='path to Intel TBB', dest='tbb') @@ -21,38 +19,28 @@ def check_tbb(self, *k, **kw): libpath_tbb = [self.options.tbb + '/lib'] else: includes_tbb = ['/usr/local/include', '/usr/include', '/opt/intel/tbb/include'] - libpath_tbb = ['/usr/local/lib/', '/usr/lib', '/opt/intel/tbb/lib', '/usr/lib/x86_64-linux-gnu', '/usr/libx86_64-linux-gnu'] - if 'CPPFLAGS' in os.environ: - includes_tbb += [path[2:] for path in os.environ['CPPFLAGS'].split() if path[0:2] == '-I'] - if 'LD_LIBRARY_PATH' in os.environ: - libpath_tbb += os.environ['LD_LIBRARY_PATH'].split(":") + libpath_tbb = ['/usr/local/lib/', '/usr/lib', '/opt/intel/tbb/lib', '/usr/lib/x86_64-linux-gnu/'] self.start_msg('Checking Intel TBB includes (optional)') + incl = '' + lib = '' try: res = self.find_file('tbb/parallel_for.h', includes_tbb) - index = includes_tbb.index(res[:-len('tbb/parallel_for.h')-1]) - includes_tbb = [includes_tbb[index]] - self.end_msg('ok') - if Logs.verbose: - Logs.pprint('CYAN', ' path : %s' % includes_tbb[0]) + incl = res[:-len('tbb/parallel_for.h')-1] + self.end_msg(incl) except: - self.end_msg('not found', 'YELLOW') + self.end_msg('Not found in %s' % str(includes_tbb), 'YELLOW') return self.start_msg('Checking Intel TBB libs (optional)') try: - res = self.find_file('libtbb.so', libpath_tbb) - index = libpath_tbb.index(res[:-len('libtbb.so')-1]) - libpath_tbb = [libpath_tbb[index]] - self.end_msg('ok') - if Logs.verbose: - Logs.pprint('CYAN', ' path : %s' % libpath_tbb[0]) - Logs.pprint('CYAN', ' libs : [\'tbb\']') + res, lib = sferes.check_lib(self, 'libtbb', libpath_tbb) + self.end_msg(lib) except: - self.end_msg('not found', 'YELLOW') + self.end_msg('Not found in %s' % str(libpath_tbb), 'YELLOW') return - self.env.LIBPATH_TBB = libpath_tbb + self.env.LIBPATH_TBB = [lib] self.env.LIB_TBB = ['tbb'] - self.env.INCLUDES_TBB = includes_tbb - self.env['TBB_ENABLED'] = True + self.env.INCLUDES_TBB = [incl] + self.env.DEFINES_TBB = ['USE_TBB']