I have an OMNeT++ project that communicates with an external process by exchanging Protobuf-encoded messages. I would like to integrate the compilation of the .proto files into .pb.cc and .pb.h into the build process.
It seems to me that the intended hook for doing something like this is the makefrag file. I can add a goal for the C++ source files like this:
messages/ExternalMessage.pb.cc messages/ExternalMessage.pb.h: ../protobuf/ExternalMessage.proto protoc --cpp_out=messages -I../protobuf ExternalMessage.proto (I know, this could be improved using wildcards.) This way, I can invoke make messages/ExternalMessage.pb.cc to recreate the C++ sources.
However, I cannot quite figure out how to automatically invoke this when building the main target. I did try adding it to the OBJS or EXTRA_OBJS variables like so:
EXTRA_OBJS += $O/messages/message.pb.o However, this does not seem to cause the files to be built, and it fails in two ways:
- Building one of the other modules fails when it tries to
#includethe generated header file. - Even if I invoke the Protobuf compilation manually, the linker complains about not finding the ExternalMessage.pb.o file.
So I seem to be missing something.
Aside: I would also be interested in getting make clean to delete the generated files, just like the files generated from OMNeT++ .msg files are deleted.