diff --git a/Makefile.am b/Makefile.am index d8feb0d..1e1e1df 100644 --- a/Makefile.am +++ b/Makefile.am @@ -164,7 +164,8 @@ noinst_PROGRAMS += \ t_generated_code2_cxx_generate_packed_data_SOURCES = \ t/generated-code2/cxx-generate-packed-data.cc \ - t/test-full.pb.cc + t/test-full.pb.cc \ + protobuf-c/protobuf-c.pb.cc $(t_generated_code2_cxx_generate_packed_data_OBJECTS): t/test-full.pb.h t_generated_code2_cxx_generate_packed_data_CXXFLAGS = \ $(AM_CXXFLAGS) \ diff --git a/protobuf-c/protobuf-c.proto b/protobuf-c/protobuf-c.proto index 1c54cf8..66de032 100644 --- a/protobuf-c/protobuf-c.proto +++ b/protobuf-c/protobuf-c.proto @@ -30,7 +30,13 @@ syntax = "proto2"; import "google/protobuf/descriptor.proto"; +// We never need to generate protobuf-c.pb-c.{c,h}, the options are used +// only by protoc-gen-c, never by the protobuf-c runtime itself +option (pb_c_file).no_generate = true; + message ProtobufCFileOptions { + // Suppresses pb-c.{c,h} file output completely. + optional bool no_generate = 1 [default = false]; } extend google.protobuf.FileOptions { diff --git a/protoc-c/c_file.cc b/protoc-c/c_file.cc index f291679..9ea788b 100644 --- a/protoc-c/c_file.cc +++ b/protoc-c/c_file.cc @@ -157,9 +157,13 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { "protoc_version", SimpleItoa(PROTOBUF_C_VERSION_NUMBER)); for (int i = 0; i < file_->dependency_count(); i++) { - printer->Print( - "#include \"$dependency$.pb-c.h\"\n", - "dependency", StripProto(file_->dependency(i)->name())); + const ProtobufCFileOptions opt = + file_->dependency(i)->options().GetExtension(pb_c_file); + if (!opt.no_generate()) { + printer->Print( + "#include \"$dependency$.pb-c.h\"\n", + "dependency", StripProto(file_->dependency(i)->name())); + } } printer->Print("\n"); diff --git a/protoc-c/c_generator.cc b/protoc-c/c_generator.cc index e30cf7b..e2fccdf 100644 --- a/protoc-c/c_generator.cc +++ b/protoc-c/c_generator.cc @@ -106,6 +106,9 @@ bool CGenerator::Generate(const FileDescriptor* file, const std::string& parameter, OutputDirectory* output_directory, std::string* error) const { + if (file->options().GetExtension(pb_c_file).no_generate()) + return true; + std::vector > options; ParseOptions(parameter, &options); diff --git a/t/test-full.proto b/t/test-full.proto index c04fce7..2ebd690 100644 --- a/t/test-full.proto +++ b/t/test-full.proto @@ -1,5 +1,7 @@ package foo; +import "protobuf-c/protobuf-c.proto"; + message SubMess { required int32 test = 4;