Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # encoding: utf-8 |
| 3 | |
| 4 | ''' |
| 5 | |
| 6 | When 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 | |
| 17 | Options are generated, in order to specify the location of cryptopp includes/libraries. |
| 18 | |
| 19 | |
| 20 | ''' |
| 21 | import sys |
| 22 | import re |
| 23 | from waflib import Utils,Logs,Errors |
| 24 | from waflib.Configure import conf |
| 25 | CRYPTOPP_DIR=['/usr','/usr/local','/opt/local','/sw'] |
| 26 | CRYPTOPP_VERSION_FILE='config.h' |
| 27 | CRYPTOPP_VERSION_CODE=''' |
| 28 | #include <iostream> |
| 29 | #include <cryptopp/config.h> |
| 30 | int main() { std::cout << CRYPTOPP_VERSION; } |
| 31 | ''' |
| 32 | |
| 33 | def 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 |
| 36 | def __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 |
| 42 | def 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 |
| 46 | def 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 |
| 59 | def 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 | |