Protocol Buffer Integration in WAF

I managed to compile my .proto files as follows:

 def build(bld): bld(rule='protoc --cpp_out=. -I.. ${SRC}', source='a.proto b.proto', name='genproto') 

It seems nice when I make changes to the source files, they are recompiled and so on. But the result will be files called build/a.pb.cc and build/b.pb.cc , which I need to include in the list of source files for the main programs. Of course, I know how to manually create them from protocol file names, but I don't think this is the way to go. Can someone give me a hint?

Regards Philippe

UPDATE

With the help of patients from the IRC, I was able to create a tool as suggested below.

 #!/usr/bin/env python # encoding: utf-8 # Philipp Bender, 2012 from waflib.Task import Task from waflib.TaskGen import extension """ A simple tool to integrate protocol buffers into your build system. def configure(conf): conf.load('compiler_cxx cxx protoc_cxx') def build(bld): bld.program(source = "main.cpp file1.proto proto/file2.proto", target = "executable") """ class protoc(Task): run_str = '${PROTOC} ${SRC} --cpp_out=. -I..' color = 'BLUE' ext_out = ['.h', 'pb.cc'] @extension('.proto') def process_protoc(self, node): cpp_node = node.change_ext('.pb.cc') hpp_node = node.change_ext('.pb.h') self.create_task('protoc', node, [cpp_node, hpp_node]) self.source.append(cpp_node) self.env.append_value('INCLUDES', ['.'] ) self.use = self.to_list(getattr(self, 'use', '')) + ['PROTOBUF'] def configure(conf): conf.check_cfg(package="protobuf", uselib_store="PROTOBUF", args=['--cflags', '--libs']) conf.find_program('protoc', var='PROTOC') 

You can also find it in bugtracker:

https://code.google.com/p/waf/issues/detail?id=1184

+4
source share
1 answer

This kind of processing is documented in the Waf book (see "idl").

However, I am pretty sure that the community of supporters is welcomed by the protobuf tool, so I suggest you try to create it and send it for viewing on the error tracker or on the IRC. Thus, you will have less maintenance load, shorter than wscript.

I would like to use this tool as follows:

 bld( name="protobufs", features="protoc cxx", source=["protobuf/a.proto", "protobuf/b.proto"], includes=["protobuf", "..."], ) bld( target="test", features="cxx cxxprogram", source="test.cpp", use="protobufs", # uses the generated C++ code, links to -lprotobuf ) 

Or something like that.

+1
source

All Articles