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: