I managed to compile my .proto
files like this:
def build(bld):
bld(rule='protoc --cpp_out=. -I.. ${SRC}', source='a.proto b.proto', name='genproto')
Seems to work nice, when I make changes to the source files, they are recompiled and so on. But the result would be files called build/a.pb.cc
and build/b.pb.cc
which I need to include into my main programs source list. Of course I know how to manually construct them from my protocol buffers file names, but I don't think this is the way to go. Can anyone provide me a hint?
Best regards, Philipp
UPDATE
With patient help from the IRC people I was able to manage to build 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 the bugtracker:
https://code.google.com/p/waf/issues/detail?id=1184
This kind of processing is documented in the Waf book (look for "idl").
However I'm pretty sure a protobuf tool would be welcomed by the community, so I suggest you attempt to create one and submit it for review on the bug tracker or on IRC. This way, you'll have less maintenance burden, a shorter wscript.
I would expect to use the tool like this:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With