Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # encoding: utf-8 |
| 3 | # Philipp Bender, 2012 |
| 4 | # Matt Clarkson, 2012 |
| 5 | |
| 6 | from waflib.Task import Task |
| 7 | from waflib.TaskGen import extension |
| 8 | |
| 9 | """ |
| 10 | A simple tool to integrate protocol buffers into your build system. |
| 11 | |
| 12 | def configure(conf): |
| 13 | conf.load('compiler_cxx cxx protoc') |
| 14 | |
| 15 | def build(bld): |
| 16 | bld( |
| 17 | features = 'cxx cxxprogram' |
| 18 | source = 'main.cpp file1.proto proto/file2.proto', |
| 19 | include = '. proto', |
| 20 | target = 'executable') |
| 21 | |
| 22 | """ |
| 23 | |
| 24 | class protoc(Task): |
| 25 | run_str = '${PROTOC} ${PROTOC_FLAGS} ${PROTOC_ST:INCPATHS} ${SRC[0].abspath()}' |
| 26 | color = 'BLUE' |
| 27 | ext_out = ['.h', 'pb.cc'] |
| 28 | |
| 29 | @extension('.proto') |
| 30 | def process_protoc(self, node): |
| 31 | cpp_node = node.change_ext('.pb.cc') |
| 32 | hpp_node = node.change_ext('.pb.h') |
| 33 | self.create_task('protoc', node, [cpp_node, hpp_node]) |
| 34 | self.source.append(cpp_node) |
| 35 | |
| 36 | if 'cxx' in self.features and not self.env.PROTOC_FLAGS: |
| 37 | self.env.PROTOC_FLAGS = '--cpp_out=%s' % node.parent.get_bld().abspath() |
| 38 | |
| 39 | use = getattr(self, 'use', '') |
| 40 | if not 'PROTOBUF' in use: |
| 41 | self.use = self.to_list(use) + ['PROTOBUF'] |
| 42 | |
| 43 | def configure(conf): |
| 44 | conf.check_cfg(package="protobuf", uselib_store="PROTOBUF", args=['--cflags', '--libs']) |
| 45 | conf.find_program('protoc', var='PROTOC') |
| 46 | conf.env.PROTOC_ST = '-I%s' |
| 47 | |