当前位置: 移动技术网 > IT编程>开发语言>C/C++ > CMake安装grpc生成gRPCTargets.cmake文件

CMake安装grpc生成gRPCTargets.cmake文件

2019年02月15日  | 移动技术网IT编程  | 我要评论

武清体,阿卡姆骑士,战国之天下人

以下是安装语句:

cd grpc_folder
git submodule update --init
cmake ..
make -j 4
sudo make install

然而编写依赖grpc的程序,发现无法调用grpccmake文件,错误提示如下所示:

  include could not find load file:

    /usr/local/lib/cmake/grpc/grpctargets.cmake

grpcissue列表中,寻找到解决方案(cmake安装时,如果第三方依赖在未指明的情况下,默认均通过源码安装,如果无法通过源码安装,则无法生成grpctargets.cmake文件):
因此需要指定第三方依赖是通过源码安装,还是已经通过包管理器安装完毕.
因为已经安装了zlibprotobuf以及cares,因此修改cmake ..为:

cmake  -dgrpc_install=on -dgrpc_zlib_provider=package -dgrpc_cares_provider=package -dgrpc_protobuf_provider=package -dgrpc_ssl_provider=package ..

依赖grpc的工程可以使用如下语句添加grpc依赖:

if (with_grpc)
    find_package(grpc config)
    # first attempt to set up grpc via cmake; but if cmake config files aren't
    # available, fallback to pkg-config.
    if (grpc_found)
        set(grpc_cpp_plugin $<target_file:grpc::grpc_cpp_plugin>)
        list(append lightstep_link_libraries grpc::grpc++)
        include_directories(system
                $<target_property:grpc::grpc++,interface_include_directories>)
    else()
        message("falling back to finding grpc with pkg-config")
        find_program(grpc_cpp_plugin grpc_cpp_plugin)
        if (not grpc_cpp_plugin)
            message(fatal_error "grpc_cpp_plugin not found!")
        endif()
        find_package(pkgconfig required)
        pkg_search_module(grpc required grpc)
        pkg_search_module(grpcpp required grpc++)
        list(append lightstep_link_libraries ${grpcpp_ldflags} ${grpc_ldflags})
        include_directories(system ${grpc_include_dirs} ${grpcpp_include_dirs})
    endif()
endif()

ps:
如果您觉得我的文章对您有帮助,可以扫码领取下红包,谢谢!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网