• cmake 常用指令,变量


    源码目录: ${CMAKE_SOURCE_DIR}

    This is the full path to the top level of the current CMake source tree. For an in-source build, this would be the same as CMAKE_BINARY_DIR.

    grpc helloword 改造

    cmake_minimum_required(VERSION 3.20.1)
    
    project(HelloWorld C CXX)
    
    add_definitions( -D_WIN32_WINNT=0x0600 )
    add_definitions( -DGRPC_CALLBACK_API_NONEXPERIMENTAL )
    
    set(protobuf_MODULE_COMPATIBLE TRUE)
    find_package(Protobuf CONFIG REQUIRED)
    message(STATUS "Using protobuf ${Protobuf_VERSION}")
    
    set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
    set(_REFLECTION gRPC::grpc++_reflection)
    if(CMAKE_CROSSCOMPILING)
      find_program(_PROTOBUF_PROTOC protoc)
    else()
      set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
    endif()
    
     # Find gRPC installation
     # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
    find_package(gRPC CONFIG REQUIRED)
    message(STATUS "Using gRPC ${gRPC_VERSION}")
    
    set(_GRPC_GRPCPP gRPC::grpc++)
    if(CMAKE_CROSSCOMPILING)
      find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
    else()
      set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
    endif()
    
    get_filename_component(proto_dir "./protos" ABSOLUTE)
    get_filename_component(gen_dir "./protos_generated" ABSOLUTE)
    # 获取所有proto文件
    file(GLOB proto_src CONFIGURE_DEPENDS "${proto_dir}/*.proto")
    # 设置生成文件列表
    set(gen_files "")
    # 拼接生成文件
    foreach(_proto ${proto_src})
      get_filename_component(gen_file_name  ${_proto} NAME_WE)
      get_filename_component(gen_file_pb_h "${gen_dir}/${gen_file_name}.pb.h" ABSOLUTE)
      get_filename_component(gen_file_pb_cc "${gen_dir}/${gen_file_name}.pb.cc" ABSOLUTE)
      get_filename_component(gen_file_grpc_pb_h "${gen_dir}/${gen_file_name}.grpc.pb.h" ABSOLUTE)
      get_filename_component(gen_file_grpc_pb_cc "${gen_dir}/${gen_file_name}.grpc.pb.cc" ABSOLUTE)
      list(APPEND gen_files ${gen_file_pb_h} ${gen_file_pb_cc} ${gen_file_grpc_pb_h} ${gen_file_grpc_pb_cc})
    endforeach()
    
    
    add_custom_command(
          OUTPUT ${gen_files}
          COMMAND ${_PROTOBUF_PROTOC}
          ARGS --grpc_out "${gen_dir}"
            --cpp_out "${gen_dir}"
            -I "${proto_dir}"
            --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
            ${proto_src}
          DEPENDS ${proto_src})
    
    # Include generated *.pb.h files
    include_directories("${gen_dir}")
    
    
    
    # hw_grpc_proto
    add_library(hw_grpc_proto
      ${gen_files})
    target_link_libraries(hw_grpc_proto
      ${_REFLECTION}
      ${_GRPC_GRPCPP}
      ${_PROTOBUF_LIBPROTOBUF})
    
    # Targets greeter_[async_](client|server)
    foreach(_target
      greeter_client greeter_server 
       greeter_callback_client greeter_callback_server 
      greeter_async_client greeter_async_client2 greeter_async_server
     )
      add_executable(${_target} "${_target}.cc")
      target_link_libraries(${_target}
        hw_grpc_proto
        ${_REFLECTION}
        ${_GRPC_GRPCPP}
        ${_PROTOBUF_LIBPROTOBUF})
    endforeach()
  • 相关阅读:
    安装 windows 2008 解决 gpt 分区问题
    you have not created a boot efi partition
    echarts gauge 仪表盘去除外发光效果
    上国际网络——通过配置host
    juery 选择器 选择多个元素
    html5 <input> placeholder 属性
    PHP——字符串统一转码为GBK,自动判断是否UTF8并转码
    sublime text2 解决中文乱码
    PHP超级全局变量——Session 变量
    js为元素添加onclick事件
  • 原文地址:https://www.cnblogs.com/wolbo/p/15140361.html
Copyright © 2020-2023  润新知