Yingdi Yu | c9843cf | 2014-08-04 17:52:19 -0700 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | # encoding: utf-8 |
| 3 | |
| 4 | ''' |
| 5 | |
| 6 | When using this tool, the wscript will look like: |
| 7 | |
| 8 | def options(opt): |
| 9 | opt.load('compiler_cxx cryptopp') |
| 10 | |
| 11 | def configure(conf): |
| 12 | conf.load('compiler_cxx cryptopp') |
| 13 | conf.check_cryptopp() |
| 14 | |
| 15 | def build(bld): |
| 16 | bld(source='main.cpp', target='app', use='CRYPTOPP') |
| 17 | |
| 18 | Options are generated, in order to specify the location of cryptopp includes/libraries. |
| 19 | |
| 20 | |
| 21 | ''' |
| 22 | import sys |
| 23 | import re |
| 24 | from waflib import Utils,Logs,Errors |
| 25 | from waflib.Configure import conf |
| 26 | CRYPTOPP_DIR = ['/usr', '/usr/local', '/opt/local', '/sw', '/usr/local/ndn', '/opt/ndn'] |
| 27 | CRYPTOPP_VERSION_FILE = 'config.h' |
| 28 | |
| 29 | def options(opt): |
| 30 | opt.add_option('--with-cryptopp', type='string', default=None, dest='cryptopp_dir', |
| 31 | help='''Path to where CryptoPP is installed, e.g., /usr/local''') |
| 32 | |
| 33 | @conf |
| 34 | def __cryptopp_get_version_file(self, dir): |
| 35 | try: |
| 36 | return self.root.find_dir(dir).find_node('%s/%s' % ('include/cryptopp', |
| 37 | CRYPTOPP_VERSION_FILE)) |
| 38 | except: |
| 39 | return None |
| 40 | |
| 41 | @conf |
| 42 | def __cryptopp_find_root_and_version_file(self, *k, **kw): |
| 43 | root = k and k[0] or kw.get('path', self.options.cryptopp_dir) |
| 44 | |
| 45 | file = self.__cryptopp_get_version_file(root) |
| 46 | if root and file: |
| 47 | return (root, file) |
| 48 | for dir in CRYPTOPP_DIR: |
| 49 | file = self.__cryptopp_get_version_file(dir) |
| 50 | if file: |
| 51 | return (dir, file) |
| 52 | |
| 53 | if root: |
| 54 | self.fatal('CryptoPP not found in %s' % root) |
| 55 | else: |
| 56 | self.fatal('CryptoPP not found, please provide a --with-cryptopp=PATH argument (see help)') |
| 57 | |
| 58 | @conf |
| 59 | def check_cryptopp(self, *k, **kw): |
| 60 | if not self.env['CXX']: |
| 61 | self.fatal('Load a c++ compiler first, e.g., conf.load("compiler_cxx")') |
| 62 | |
| 63 | var = kw.get('uselib_store', 'CRYPTOPP') |
| 64 | mandatory = kw.get('mandatory', True) |
| 65 | |
| 66 | use = kw.get('use', 'PTHREAD') |
| 67 | |
| 68 | self.start_msg('Checking Crypto++ lib') |
| 69 | (root, file) = self.__cryptopp_find_root_and_version_file(*k, **kw) |
| 70 | |
| 71 | try: |
| 72 | txt = file.read() |
| 73 | re_version = re.compile('^#define\\s+CRYPTOPP_VERSION\\s+(.*)', re.M) |
| 74 | match = re_version.search(txt) |
| 75 | |
| 76 | if match: |
| 77 | self.env.CRYPTOPP_VERSION = match.group(1) |
| 78 | self.end_msg(self.env.CRYPTOPP_VERSION) |
| 79 | else: |
| 80 | self.fatal('CryptoPP files are present, but are not recognizable') |
| 81 | except: |
| 82 | self.fatal('CryptoPP not found or is not usable') |
| 83 | |
| 84 | val = self.check_cxx(msg='Checking if CryptoPP library works', |
| 85 | header_name='cryptopp/config.h', |
| 86 | lib='cryptopp', |
| 87 | includes="%s/include" % root, |
| 88 | libpath="%s/lib" % root, |
| 89 | mandatory=mandatory, |
| 90 | use=use, |
| 91 | uselib_store=var) |