blob: 684a9451075bd7b529472b04e2a592a7b30f89d0 [file] [log] [blame]
Alexander Afanasyev6af3c152012-06-07 21:14:24 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -07003#! /usr/bin/env python
4# encoding: utf-8
5
6'''
7
8When using this tool, the wscript will look like:
9
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070010def options(opt):
11 opt.tool_options("protobuf", tooldir=["waf-tools"])
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070012
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070013def configure(conf):
14 conf.load("compiler_cxx protobuf")
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070015
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070016def build(bld):
17 bld(source="main.cpp", target="app", use="PROTOBUF")
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070018
19Options are generated, in order to specify the location of protobuf includes/libraries.
20
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070021'''
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070022
23from waflib import Utils, TaskGen, Task, Logs
24
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070025from waflib import Utils,Logs,Errors
26from waflib.Configure import conf
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070027
28def options(opt):
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070029 pass
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070030
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070031def configure(conf):
32 """
33 """
34 conf.check_cfg(package='protobuf', args=['--cflags', '--libs'], uselib_store='PROTOBUF', mandatory=True)
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070035
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070036 conf.find_program ('protoc', var='PROTOC', path_list = conf.env['PATH'], mandatory = True)
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070037
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070038@TaskGen.extension('.proto')
39def add_proto(self, node):
40 """
41 Compile PROTOBUF protocol specifications
42 """
43 prototask = self.create_task ("protobuf", node, node.change_ext (".pb"))
44 try:
45 self.compiled_tasks.append (prototask)
46 except AttributeError:
47 self.compiled_tasks = [prototask]
48
49class protobuf(Task.Task):
50 """
51 Task for compiling PROTOBUF protocol specifications
52 """
53 run_str = '${PROTOC} --cpp_out ${TGT[0].parent.abspath()} --proto_path ${SRC[0].parent.abspath()} ${SRC[0].abspath()} -o${TGT[0].abspath()}'
54 color = 'BLUE'
55
56@TaskGen.feature('cxxshlib')
57@TaskGen.before_method('process_source')
58def dynamic_post(self):
59 if not getattr(self, 'dynamic_source', None):
60 return
61 self.source = Utils.to_list(self.source)
62
63 src = self.bld.path.get_bld().ant_glob (Utils.to_list(self.dynamic_source))
64
65 for cc in src:
66 # Signature for the source
67 cc.sig = Utils.h_file (cc.abspath())
68 # Signature for the header
69 h = cc.change_ext (".h")
70 h.sig = Utils.h_file (h.abspath())
71
72 self.source.extend (src)