10

I am having issues building the grpc cpp helloworld example with cmake. I built and installed grpc with cmake initially, and then with make directly.

I have found this issue raised by someone else in the past, which was closed as resolved.
It does not appear to be resolved and I opened a new issue for it, but I feel it will be some time until I get some help, so here I am.

The OP of the original issue offers a workaround with his FindGRPC cmake module, but I am not sure how is this suppose to help if gRPCTargets.cmake is still missing.
I dropped FindGRPC.cmake inside my cmake modules path, but nothing changes.

The error is this:

CMake Error at /usr/local/lib/cmake/grpc/gRPCConfig.cmake:8 (include):
  include could not find load file:

    /usr/local/lib/cmake/grpc/gRPCTargets.cmake
Call Stack (most recent call first):
  CMakeLists.txt:73 (find_package)


-- Using gRPC 1.20.0
-- Configuring incomplete, errors occurred

I want to be able to use grpc from my cmake projects without much hassle (using find_package(gRPC CONFIG REQUIRED))

EDIT:

When running cmake on grpc I get this error:

gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is "module"

This is printed from zlib.cmake:

message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is \"module\"")

Apparently all the providers must be "package" as mentioned in grpc's CMakeLists.txt:

set(gRPC_INSTALL ${gRPC_INSTALL_default} CACHE BOOL
    "Generate installation target: gRPC_ZLIB_PROVIDER, gRPC_CARES_PROVIDER, gRPC_SSL_PROVIDER and gRPC_PROTOBUF_PROVIDER must all be \"package\"")

I am not sure why zlib is a module here though, or how to make it a package.
Do I need to somehow specify to cmake to use the installed zlib instead of the submodule one?

codentary
  • 993
  • 1
  • 14
  • 33
  • Do you still have the grpc build directory? What is the value of gRPC_INSTALL in CMakeCache.txt? – Botje Aug 08 '19 at 14:15
  • 1
    ... And when you ran `cmake` in the gRPC dir, did it say something about "gRPC_INSTALL will be forced to FALSE" ? – Botje Aug 08 '19 at 14:26
  • `gRPC_INSTALL:BOOL=ON` I don't remember seeing something about it being forced to false. – codentary Aug 08 '19 at 14:30
  • if GRPC_INSTALL was still true at the end of CMakeLists.txt, the generated `cmake_install.cmake` should contain instructions to install `gRPCTargets.cmake`. Does it? – Botje Aug 08 '19 at 15:04
  • It does not! It only has details about `gRPCConfig.cmake` and `gRPCConfigVersion.cmake`. – codentary Aug 08 '19 at 15:33
  • And indeed `gRPCConfig.cmake` and `gRPCConfigVersion.cmake` are deployed, but `gRPCConfig.cmake` referes to `gRPCTargets.cmake` which is not there. – codentary Aug 08 '19 at 15:37
  • 1
    Yes, this is direct evidence that gRPC_INSTALL became false at some point in the cmake process, and that *must* be accompanied by a warning print. Add a `message("gRPC_INSTALL is now ${gRPC_INSTALL}")` statement right before it is set to FALSE in CMakeLists.txt (4 possible places, if I recall correctly) – Botje Aug 08 '19 at 17:10
  • You were right, I get that message: ` gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is "module"` – codentary Aug 08 '19 at 19:57
  • 1
    Try the solution in https://github.com/grpc/grpc/issues/13841#issuecomment-355510534 , if you hadn't already found it yourself. If that works I will formulate an answer so other people can find it. – Botje Aug 09 '19 at 06:15
  • This did the job, I can't believe I just had to define the providers as `package` myself. Why wouldn't this be the default if it does not work to install with `module`. It could look for the installed `package`s and default to `module` just if it does not find them. Anyway... please post your answer. Thank you. – codentary Aug 09 '19 at 08:28
  • I think the answer will be "patches welcome" ;) Defaulting to "module" ensures you know what you are building against, though. That is a good property for many users :) – Botje Aug 09 '19 at 09:19

1 Answers1

12

The cause of this problem is explained at https://github.com/grpc/grpc/issues/13841:

Because of some limitations of our current CMakeLists.txt, the install targets (see gRPC_INSTALL option) will only be generated if you are building using a pre-installed version of our dependencies (gRPC_CARES_PROVIDER in your case needs to be set to package).

The warning you saw "gRPC_INSTALL will be forced to FALSE because gRPC_CARES_PROVIDER" is "module" basically tells you that even though gRPC_INSTALL was set to ON by you, we're setting it back to OFF because your gRPC_CARES_PROVIDER is set to use c-ares from git submodule (which wouldn't work well with the current CMakeLists.txt) - so you shouldn't expect anything to be installed (not even grpc_cpp_plugin.

To fix this issue, you should carefully look at the output when invoking cmake. For every gRPC_*_PROVIDER that is reported as "module", you should force it to "package" with -DgRPC_CARES_PROVIDER=package (make sure to install the package as well, then!)

Or just force everything with the command-line linked in the issue:

 cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../.. 
Community
  • 1
  • 1
Botje
  • 26,269
  • 3
  • 31
  • 41