For a simple proto file:
message Person { required int32 id = 1; required string name = 2; optional string email = 3; }
It\'s been compiled by pr
You can hack the source of the protoc compiler to have it inject the pragmas into the generated files automatically.
In src/google/protobuf/compiler/cpp/cpp_file.cc in GenerateHeader(io::Printer* printer)
around line 94, change the first printer->Print
call to:
// Generate top of header.
printer->Print(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n"
"\n"
"#ifndef PROTOBUF_$filename_identifier$__INCLUDED\n"
"#define PROTOBUF_$filename_identifier$__INCLUDED\n"
"\n"
"#ifdef _MSC_VER\n"
"# pragma warning(push)\n"
"# pragma warning(disable: 4127 4244 4267)\n"
"#endif\n"
"\n"
"#include \n"
"\n",
"filename", file_->name(),
"filename_identifier", filename_identifier);
Then at the end of the same function at around line 294, change the last printer->Print
call to:
printer->Print(
"#ifdef _MSC_VER\n"
"# pragma warning(pop)\n"
"#endif\n"
"\n"
"#endif // PROTOBUF_$filename_identifier$__INCLUDED\n",
"filename_identifier", filename_identifier);
Now you just need to compile the protoc target and run the new protoc.exe to have the pragmas in the generated headers.