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

一个人想着一个人 提交于 2020-12-24 16:11:32

问题


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?


回答1:


Maybe this helps. Especially look at the post of Igor Zavoychinskiy:

Solution of this nasty problem is actually simple: in outputs sections you should specify full path(s). This isn't explicitly stated anywhere but without this checker just fails to find the files and, hence, assumes they don't exist. For example for protobuffers compiling outputs section will be like this:

$(InputDir)\$(InputName).pb.cc;$(InputDir)\$(InputName).pb.h

and (maybe?) kmote00:

... Bottom line: I just had to make sure my "Outputs" entry exactly matched the Default Value in the (user-defined) "OutputFile" property. (Thankfully this also obviated the need for a two-pass build, which was another annoyance I had previously put up with.)




回答2:


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".



来源:https://stackoverflow.com/questions/11447950/integrate-google-protocol-buffers-proto-files-to-visual-c-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!