blob: ab3f7f702dbe7136dc5221d2427e9128faedd340 [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):
9 opt.tool_options('cryptopp', tooldir=["waf-tools"])
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 Afanasyeva1ae0a12014-01-28 15:21:02 -080013
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070014 def build(bld):
15 bld(source='main.cpp', target='app', use='CRYPTOPP')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080016
17Options are generated, in order to specify the location of cryptopp includes/libraries.
18
19
20'''
21import sys
22import re
23from waflib import Utils,Logs,Errors
24from waflib.Configure import conf
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070025CRYPTOPP_DIR = ['/usr', '/usr/local', '/opt/local', '/sw']
26CRYPTOPP_VERSION_FILE = 'config.h'
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080027
28def options(opt):
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070029 opt.add_option('--cryptopp', type='string', default='', dest='cryptopp_dir',
30 help='''Path to where CryptoPP is installed, e.g. /opt/local''')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080031
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070032@conf
33def __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 Afanasyeva1ae0a12014-01-28 15:21:02 -080039
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070040@conf
41def __cryptopp_find_root_and_version_file(self, *k, **kw):
42 root = k and k[0]or kw.get('path', None)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080043
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070044 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 Afanasyeva1ae0a12014-01-28 15:21:02 -080051
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070052 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
58def 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)