blob: 4293aabbe4bd9333188224e7bf9c83226357f873 [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:
Alexander Afanasyev1160baa2014-04-10 18:50:29 -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
63 var = kw.get('uselib_store','CRYPTOPP')
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070064 mandatory = kw.get('mandatory', True)
65
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070066 self.start_msg('Checking Crypto++ lib')
67 (root, file) = self.__cryptopp_find_root_and_version_file(*k, **kw)
68
69 try:
70 txt = file.read()
71 re_version = re.compile('^#define\\s+CRYPTOPP_VERSION\\s+(.*)', re.M)
72 match = re_version.search(txt)
73
74 if match:
75 self.env.CRYPTOPP_VERSION = match.group(1)
76 self.end_msg(self.env.CRYPTOPP_VERSION)
77 else:
78 self.fatal('CryptoPP files are present, but are not recognizable')
79 except:
80 self.fatal('CryptoPP not found or is not usable')
81
82 val = self.check_cxx(msg='Checking if CryptoPP library works',
83 header_name='cryptopp/config.h',
84 lib='cryptopp',
85 cxxflags="-I%s/include" % root,
86 linkflags="-L%s/lib" % root,
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070087 mandatory=mandatory,
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070088 uselib_store=var)