4

I'm currently working on a C++ project that reference gRPC as a git submodule and I'm using CMake to compile the dependencies and my sources. For that I basically have this in my CMakeLists.txt:

ADD_SUBDIRECTORY(lib/grpc)

Then I run:

make grpc_cpp_plugin
make my_project

Even though I specify cpp_plugin here, when it's time to compile protoc I'm actually compiling for all the languages supported, eg (Java, Csharp, ...) :

/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc.o
/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc.o
/src/google/protobuf/compiler/java/java_context.cc.o
/src/google/protobuf/compiler/java/java_doc_comment.cc.o

After looking around for some info on how to build protoc only for C++, I found that someone opened an issue on the github protobuf directory (link). However, it doesn't seem to give a clear answer.

Is there a 'clean' way to only compile the c++ dependency here ?

Clément Jean
  • 1,735
  • 1
  • 14
  • 32
  • Does hint from issue you have provided work: "if you only need C++, download protobuf-cpp-[VERSION].tar.gz;" – R2RT Feb 12 '20 at 11:45
  • No it still compile everything, at least last time I tried. But here I’m add gRPC as submodule so I can’t choose the protobuff – Clément Jean Feb 12 '20 at 11:49
  • You could update your CMake to download only the `protobuf-cpp-[VERSION].tar.gz` file, unzip it, then build it (which should only be the cpp portion). – Kevin Feb 12 '20 at 13:28

1 Answers1

3

After doing tons of grep in gRPC's CMake files I finally compiled only the c++ version of protoc, protobuf and gRPC. And I did it in 3 steps:

  1. go to grpc/third_party/protobuf/cmake/libprotoc.cmake and remove the lines including csharp, java, ruby, ... (Be careful to keep cpp and the langage agnostic ones)
  2. go to grpc/CMakeLists.txt and you should be able to find this:
add_library(grpc_plugin_support
  src/compiler/cpp_generator.cc
  src/compiler/csharp_generator.cc
  src/compiler/node_generator.cc
  src/compiler/objective_c_generator.cc
  src/compiler/php_generator.cc
  src/compiler/python_generator.cc
  src/compiler/ruby_generator.cc
)

so remove what's not needed.

  1. and finally, grpc/third_party/protobuf/src/google/protobuf/compiler/main.cc and remove all the references to the other langage.
Clément Jean
  • 1,735
  • 1
  • 14
  • 32