Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 3 | #! /usr/bin/env python |
| 4 | # encoding: utf-8 |
| 5 | |
| 6 | ''' |
| 7 | |
| 8 | When using this tool, the wscript will look like: |
| 9 | |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 10 | def options(opt): |
| 11 | opt.tool_options("protobuf", tooldir=["waf-tools"]) |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 12 | |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 13 | def configure(conf): |
| 14 | conf.load("compiler_cxx protobuf") |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 15 | |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 16 | def build(bld): |
| 17 | bld(source="main.cpp", target="app", use="PROTOBUF") |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 18 | |
| 19 | Options are generated, in order to specify the location of protobuf includes/libraries. |
| 20 | |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 21 | ''' |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 22 | |
| 23 | from waflib import Utils, TaskGen, Task, Logs |
| 24 | |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 25 | from waflib import Utils,Logs,Errors |
| 26 | from waflib.Configure import conf |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 27 | |
| 28 | def options(opt): |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 29 | pass |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 31 | def configure(conf): |
| 32 | """ |
| 33 | """ |
| 34 | conf.check_cfg(package='protobuf', args=['--cflags', '--libs'], uselib_store='PROTOBUF', mandatory=True) |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 36 | conf.find_program ('protoc', var='PROTOC', path_list = conf.env['PATH'], mandatory = True) |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 38 | @TaskGen.extension('.proto') |
| 39 | def 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 | |
| 49 | class 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') |
| 58 | def 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) |