blob: a005123b32b9c4fd627270cfb31d442f27b1a2ec [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
Alexander Afanasyev00f855e2015-05-28 14:38:43 -070029CRYPTOPP_CHECK_FRAGMENT = '''
30#include "../../src/security/cryptopp.hpp"
31#include <iostream>
32
33int
34main()
35{
36 using namespace CryptoPP;
37
38 std::string buffer = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
39 SHA256 hash;
40 StringSource(buffer, true, new HashFilter(hash, new FileSink(std::cout)));
41 StringSource(reinterpret_cast<const uint8_t*>(buffer.c_str()), buffer.size(),
42 true, new HashFilter(hash, new FileSink(std::cout)));
Alexander Afanasyev00f855e2015-05-28 14:38:43 -070043}
44'''
45
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080046def options(opt):
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070047 opt.add_option('--with-cryptopp', type='string', default=None, dest='cryptopp_dir',
48 help='''Path to where CryptoPP is installed, e.g., /usr/local''')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080049
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070050@conf
51def __cryptopp_get_version_file(self, dir):
52 try:
53 return self.root.find_dir(dir).find_node('%s/%s' % ('include/cryptopp',
54 CRYPTOPP_VERSION_FILE))
55 except:
56 return None
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080057
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070058@conf
59def __cryptopp_find_root_and_version_file(self, *k, **kw):
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070060 root = k and k[0] or kw.get('path', self.options.cryptopp_dir)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080061
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070062 file = self.__cryptopp_get_version_file(root)
63 if root and file:
64 return (root, file)
65 for dir in CRYPTOPP_DIR:
66 file = self.__cryptopp_get_version_file(dir)
67 if file:
68 return (dir, file)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080069
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070070 if root:
71 self.fatal('CryptoPP not found in %s' % root)
72 else:
Mathias Gibbens16f24c52014-05-06 17:12:27 -070073 self.fatal('CryptoPP not found, please provide a --with-cryptopp=PATH argument (see help)')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070074
75@conf
76def check_cryptopp(self, *k, **kw):
77 if not self.env['CXX']:
78 self.fatal('Load a c++ compiler first, e.g., conf.load("compiler_cxx")')
79
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070080 var = kw.get('uselib_store', 'CRYPTOPP')
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070081 mandatory = kw.get('mandatory', True)
82
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070083 use = kw.get('use', 'PTHREAD')
84
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070085 self.start_msg('Checking Crypto++ lib')
86 (root, file) = self.__cryptopp_find_root_and_version_file(*k, **kw)
87
88 try:
89 txt = file.read()
90 re_version = re.compile('^#define\\s+CRYPTOPP_VERSION\\s+(.*)', re.M)
91 match = re_version.search(txt)
92
93 if match:
94 self.env.CRYPTOPP_VERSION = match.group(1)
95 self.end_msg(self.env.CRYPTOPP_VERSION)
96 else:
97 self.fatal('CryptoPP files are present, but are not recognizable')
98 except:
99 self.fatal('CryptoPP not found or is not usable')
100
Alexander Afanasyev00f855e2015-05-28 14:38:43 -0700101 isLibWorking = False
102 for defines in ['', 'CRYPTOPP_DISABLE_ASM']:
103 try:
104 self.check_cxx(msg='Checking if CryptoPP library works',
105 fragment=CRYPTOPP_CHECK_FRAGMENT,
106 lib='cryptopp',
107 includes="%s/include" % root,
108 libpath="%s/lib" % root,
109 mandatory=True,
110 use=use,
111 defines=defines,
112 uselib_store=var)
113 isLibWorking = True
114 break
115 except:
116 # try another flags
117 pass
118
119 if mandatory and not isLibWorking:
120 self.fatal('CryptoPP is present, but is not usable')