7 from waflib.Task import Task
8 from waflib.TaskGen import extension
11 A simple tool to integrate protocol buffers into your build system.
16 conf.load('compiler_cxx cxx protoc')
20 features = 'cxx cxxprogram'
21 source = 'main.cpp file1.proto proto/file2.proto',
23 target = 'executable')
25 Notes when using this tool:
27 - protoc command line parsing is tricky.
29 The generated files can be put in subfolders which depend on
30 the order of the include paths.
32 Try to be simple when creating task generators
33 containing protoc stuff.
38 # protoc expects the input proto file to be an absolute path.
39 run_str = '${PROTOC} ${PROTOC_FLAGS} ${PROTOC_ST:INCPATHS} ${SRC[0].abspath()}'
41 ext_out = ['.h', 'pb.cc']
44 Scan .proto dependencies
52 if not node: return (nodes, names)
58 code = node.read().splitlines()
60 m = re.search(r'^import\s+"(.*)";.*(//)?.*', line)
63 for incpath in self.env.INCPATHS:
64 found = incpath.find_resource(dep)
75 def process_protoc(self, node):
76 cpp_node = node.change_ext('.pb.cc')
77 hpp_node = node.change_ext('.pb.h')
78 self.create_task('protoc', node, [cpp_node, hpp_node])
79 self.source.append(cpp_node)
81 if 'cxx' in self.features and not self.env.PROTOC_FLAGS:
82 #self.env.PROTOC_FLAGS = '--cpp_out=%s' % node.parent.get_bld().abspath() # <- this does not work
83 self.env.PROTOC_FLAGS = '--cpp_out=%s' % node.parent.get_bld().bldpath()
85 use = getattr(self, 'use', '')
86 if not 'PROTOBUF' in use:
87 self.use = self.to_list(use) + ['PROTOBUF']
90 conf.check_cfg(package="protobuf", uselib_store="PROTOBUF", args=['--cflags', '--libs'])
91 conf.find_program('protoc', var='PROTOC')
92 conf.env.PROTOC_ST = '-I%s'