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