blob: 320c81f8891619abd5e21893945f8141618b05be [file] [log] [blame]
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08001#! /usr/bin/env python
2# encoding: utf-8
3
4'''
5
6When using this tool, the wscript will look like:
7
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07008 def options(opt):
Alexander Afanasyev1160baa2014-04-10 18:50:29 -07009 opt.load('compiler_cxx cryptopp')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080010
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070011 def configure(conf):
12 conf.load('compiler_cxx cryptopp')
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070013 conf.check_cryptopp()
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080014
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070015 def build(bld):
16 bld(source='main.cpp', target='app', use='CRYPTOPP')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080017
18Options are generated, in order to specify the location of cryptopp includes/libraries.
19
20
21'''
22import sys
23import re
24from waflib import Utils,Logs,Errors
25from waflib.Configure import conf
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070026CRYPTOPP_DIR = ['/usr', '/usr/local', '/opt/local', '/sw', '/usr/local/ndn', '/opt/ndn']
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070027CRYPTOPP_VERSION_FILE = 'config.h'
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080028
29def options(opt):
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070030 opt.add_option('--with-cryptopp', type='string', default=None, dest='cryptopp_dir',
31 help='''Path to where CryptoPP is installed, e.g., /usr/local''')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080032
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070033@conf
34def __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
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080040
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070041@conf
42def __cryptopp_find_root_and_version_file(self, *k, **kw):
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070043 root = k and k[0] or kw.get('path', self.options.cryptopp_dir)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080044
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070045 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)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080052
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070053 if root:
54 self.fatal('CryptoPP not found in %s' % root)
55 else:
Mathias Gibbens16f24c52014-05-06 17:12:27 -070056 self.fatal('CryptoPP not found, please provide a --with-cryptopp=PATH argument (see help)')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070057
58@conf
59def 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
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070063 var = kw.get('uselib_store', 'CRYPTOPP')
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070064 mandatory = kw.get('mandatory', True)
65
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070066 use = kw.get('use', 'PTHREAD')
67
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070068 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',
Alexander Afanasyevae80f102014-05-12 17:20:46 -070087 includes="%s/include" % root,
88 libpath="%s/lib" % root,
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070089 mandatory=mandatory,
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070090 use=use,
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070091 uselib_store=var)