blob: 3908b3855fb17abfc47eda64fa8d74bb296d6c16 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001#! /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('tinyxml', tooldir=["waf-tools"])
10
11 def configure(conf):
12 conf.load('compiler_cxx tiny')
13
14 def build(bld):
15 bld(source='main.cpp', target='app', use='TINYXML')
16
17Options are generated, in order to specify the location of tinyxml includes/libraries.
18
19
20'''
21import sys
22import re
23from waflib import Utils,Logs,Errors
24from waflib.Configure import conf
25TINYXML_DIR=['/usr','/usr/local','/opt/local','/sw']
26TINYXML_VERSION_FILE='tinyxml.h'
27TINYXML_VERSION_CODE='''
28#include <iostream>
29#include <tinyxml.h>
30int main() { std::cout << TIXML_MAJOR_VERSION << "." << TIXML_MINOR_VERSION << "." << TIXML_PATCH_VERSION; }
31'''
32
33def options(opt):
34 opt.add_option('--tinyxml',type='string',default='',dest='tinyxml_dir',help='''path to where TinyXML is installed, e.g. /usr/local''')
35@conf
36def __tinyxml_get_version_file(self,dir):
37 try:
38 return self.root.find_dir(dir).find_node('%s/%s' % ('include', TINYXML_VERSION_FILE))
39 except:
40 return None
41@conf
42def tinyxml_get_version(self,dir):
43 val=self.check_cxx(fragment=TINYXML_VERSION_CODE,includes=['%s/%s' % (dir, 'include')], execute=True, define_ret = True, mandatory=True)
44 return val
45@conf
46def tinyxml_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.__tinyxml_get_version_file(root):
50 return root
51 for dir in TINYXML_DIR:
52 if self.__tinyxml_get_version_file(dir):
53 return dir
54 if root:
55 self.fatal('TinyXML not found in %s'%root)
56 else:
57 self.fatal('TinyXML not found, please provide a --tinyxml argument (see help)')
58@conf
59def check_tinyxml(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','TINYXML')
64 self.start_msg('Checking TinyXML')
65 root = self.tinyxml_get_root(*k,**kw);
66 self.env.TINYXML_VERSION=self.tinyxml_get_version(root)
67
68 self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include");
69 self.env['LIB_%s'%var] = "tinyxml"
70 self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
71
72 self.end_msg(self.env.TINYXML_VERSION)
73 if Logs.verbose:
74 Logs.pprint('CYAN',' TinyXML include : %s'%self.env['INCLUDES_%s'%var])
75 Logs.pprint('CYAN',' TinyXML lib : %s'%self.env['LIB_%s'%var])
76 Logs.pprint('CYAN',' TinyXML libpath : %s'%self.env['LIBPATH_%s'%var])