使用 gRPC 的 CMake 找不到 gRPCTargets.cmake

hdo*_*adu 8 cmake grpc

我在grpc cpp helloworld使用cmake. 我建立并安装grpccmake最初,然后用make直接。

我发现这个问题过去是由其他人提出的,已解决。
它似乎没有解决,我打开了一个新问题为它,但我觉得我需要一段时间才能得到一些帮助,所以我在这里。

原始问题的 OP 为他的FindGRPC cmake 模块提供了一种解决方法,但我不确定如果gRPCTargets.cmake仍然丢失,这将如何提供帮助。
FindGRPC.cmake进入了我的 cmake 模块路径,但没有任何变化。

错误是这样的:

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
Run Code Online (Sandbox Code Playgroud)

我希望能够轻松地grpc从我的 cmake 项目中使用(使用find_package(gRPC CONFIG REQUIRED)

编辑:

运行cmake时出现grpc此错误:

gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is "module"
Run Code Online (Sandbox Code Playgroud)

这是打印自zlib.cmake

message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is \"module\"")
Run Code Online (Sandbox Code Playgroud)

显然,所有的提供者都必须是's 中"package"提到grpcCMakeLists.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\"")
Run Code Online (Sandbox Code Playgroud)

我不确定为什么zlib这里有一个模块,或者如何使它成为一个包。
我是否需要以某种方式指定cmake使用已安装的 zlib 而不是子模块之一?

Bot*_*tje 10

这个问题的原因在https://github.com/grpc/grpc/issues/13841 中有解释:

由于我们当前的 CMakeLists.txt 的一些限制,安装目标(请参阅 gRPC_INSTALL 选项)只会在您使用我们的依赖项的预安装版本进行构建时生成(在您的情况下需要将 gRPC_CARES_PROVIDER 设置为包)。

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 ../.. 
Run Code Online (Sandbox Code Playgroud)