Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate Google Protocol Buffers .proto files to Visual C++ 2010

I've added a custom build step to my Visual Studio project files which generates the google protobuf .h/.cc files from the .proto input files. But I've been wondering if it's possible to start a compile only if the content of the proto files has changed?

Is there a way to tell VisualStudio from a custom build step exactly that? What is the optimal way to integrate proto files into a visual studio build solution?

At the moment, at every build the .proto file is updated which then also updates the time stamp of the output .h/.cc files ...which then issues a recompile of everything dependent from that. Is there a better way around it, while still building them directly from visual studio?

like image 205
Hhut Avatar asked Jul 12 '12 08:07

Hhut


People also ask

What is Protobuf C#?

Protobuf is used to serialize data structure efficiently. It is faster, smaller & simpler than XML. Protobuf is useful in developing programs to communicate with each other over a wire and it is created by Google. It helps us in creating gRPC services.

What is Google protocol buffer used for?

What are protocol buffers? Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.


1 Answers

Follow these detailed instructions to specify Custom Build Tool.

Considering your proto file resides together with .h/.cpp files in standard project configuration, here are values to be inserted in Custom Build Tool:

Command Line: 
path\to\protoc --proto_path=$(ProjectDir) --cpp_out=$(ProjectDir) %(FullPath)
Outputs: 
$(ProjectDir)%(Filename).pb.h;$(ProjectDir)%(Filename).pb.cc

Please note usage of item metadata macros, which replaced some of deprecated macros (like $(InputDir) and $(InputName)).

Now Protocol Buffers compiler will be run only when Input file (i.e. %(FullPath)) is newer than "Outputs".

like image 143
wmamrak Avatar answered Sep 22 '22 10:09

wmamrak