CMake安装grpc生成gRPCTargets.cmake文件

以下是安装语句:

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:
如果您觉得我的文章对您有帮助,可以扫码领取下红包,谢谢!

猜你喜欢

转载自www.cnblogs.com/jason1990/p/10381320.html
今日推荐