blob: a05326b7f3850c6ab208b6d3bc6246102cf1e7ad [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
8 def options(opt):
9 opt.tool_options('cryptopp', tooldir=["waf-tools"])
10
11 def configure(conf):
12 conf.load('compiler_cxx cryptopp')
13
14 def build(bld):
15 bld(source='main.cpp', target='app', use='CRYPTOPP')
16
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
25CRYPTOPP_DIR=['/usr','/usr/local','/opt/local','/sw']
26CRYPTOPP_VERSION_FILE='config.h'
27CRYPTOPP_VERSION_CODE='''
28#include <iostream>
29#include <cryptopp/config.h>
30int main() { std::cout << CRYPTOPP_VERSION; }
31'''
32
33def options(opt):
34 opt.add_option('--cryptopp',type='string',default='',dest='cryptopp_dir',help='''path to where cryptopp is installed, e.g. /opt/local''')
35@conf
36def __cryptopp_get_version_file(self,dir):
37 try:
38 return self.root.find_dir(dir).find_node('%s/%s' % ('include/cryptopp', CRYPTOPP_VERSION_FILE))
39 except:
40 return None
41@conf
42def cryptopp_get_version(self,dir):
43 val=self.check_cxx(fragment=CRYPTOPP_VERSION_CODE,includes=['%s/%s' % (dir, 'include')], execute=True, define_ret = True, mandatory=True)
44 return val
45@conf
46def cryptopp_get_root(self,*k,**kw):
47 root=k and k[0]or kw.get('path',None)
48 # Logs.pprint ('RED', ' %s' %root)
49 if root and self.__cryptopp_get_version_file(root):
50 return root
51 for dir in CRYPTOPP_DIR:
52 if self.__cryptopp_get_version_file(dir):
53 return dir
54 if root:
55 self.fatal('CryptoPP not found in %s'%root)
56 else:
57 self.fatal('CryptoPP not found, please provide a --cryptopp argument (see help)')
58@conf
59def check_cryptopp(self,*k,**kw):
60 if not self.env['CXX']:
61 self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
62
63 var=kw.get('uselib_store','CRYPTOPP')
64 self.start_msg('Checking Crypto++ lib')
65 root = self.cryptopp_get_root(*k,**kw)
66 self.env.CRYPTOPP_VERSION=self.cryptopp_get_version(root)
67
68 self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include")
69 self.env['LIB_%s'%var] = "cryptopp"
70 self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
71
72 self.end_msg(self.env.CRYPTOPP_VERSION)
73 if Logs.verbose:
74 Logs.pprint('CYAN',' CRYPTOPP include : %s'%self.env['INCLUDES_%s'%var])
75 Logs.pprint('CYAN',' CRYPTOPP lib : %s'%self.env['LIB_%s'%var])
76 Logs.pprint('CYAN',' CRYPTOPP libpath : %s'%self.env['LIBPATH_%s'%var])
77