You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 3.0 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. cmake_minimum_required(VERSION 3.5.1)
  2. project(MSClient C CXX)
  3. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  4. find_package(Threads REQUIRED)
  5. # This branch assumes that gRPC and all its dependencies are already installed
  6. # on this system, so they can be located by find_package().
  7. # Find Protobuf installation
  8. # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
  9. option(GRPC_PATH "set grpc path")
  10. if(GRPC_PATH)
  11. set(CMAKE_PREFIX_PATH ${GRPC_PATH})
  12. set(protobuf_MODULE_COMPATIBLE TRUE)
  13. find_package(Protobuf CONFIG REQUIRED)
  14. message(STATUS "Using protobuf ${protobuf_VERSION}, CMAKE_PREFIX_PATH : ${CMAKE_PREFIX_PATH}")
  15. elseif(NOT GRPC_PATH AND grpc_ROOT)
  16. add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
  17. if (EXISTS ${grpc_ROOT}/lib64)
  18. set(gRPC_DIR "${grpc_ROOT}/lib64/cmake/grpc")
  19. elseif(EXISTS ${grpc_ROOT}/lib)
  20. set(gRPC_DIR "${grpc_ROOT}/lib/cmake/grpc")
  21. endif()
  22. add_library(protobuf::libprotobuf ALIAS protobuf::protobuf)
  23. add_executable(protobuf::libprotoc ALIAS protobuf::protoc)
  24. message(STATUS "serving using grpc_DIR : " ${gRPC_DIR})
  25. elseif(NOT gRPC_DIR AND NOT GRPC_PATH)
  26. message(FATAL_ERROR "please check gRPC. If the client is compiled separately,you can use the command: cmake -D GRPC_PATH=xxx\n" "XXX is the gRPC installation path")
  27. endif()
  28. if(CMAKE_CROSSCOMPILING)
  29. find_program(_PROTOBUF_PROTOC protoc)
  30. else()
  31. set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
  32. endif()
  33. # Find gRPC installation
  34. # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
  35. find_package(gRPC CONFIG REQUIRED)
  36. message(STATUS "Using gRPC ${gRPC_VERSION}")
  37. if(CMAKE_CROSSCOMPILING)
  38. find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
  39. else()
  40. set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
  41. endif()
  42. # Proto file
  43. get_filename_component(hw_proto "../../ms_service.proto" ABSOLUTE)
  44. get_filename_component(hw_proto_path "${hw_proto}" PATH)
  45. # Generated sources
  46. set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.pb.cc")
  47. set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.pb.h")
  48. set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.grpc.pb.cc")
  49. set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.grpc.pb.h")
  50. add_custom_command(
  51. OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
  52. COMMAND ${_PROTOBUF_PROTOC}
  53. ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
  54. --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
  55. -I "${hw_proto_path}"
  56. --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  57. "${hw_proto}"
  58. DEPENDS "${hw_proto}")
  59. # Include generated *.pb.h files
  60. include_directories("${CMAKE_CURRENT_BINARY_DIR}")
  61. # Targets greeter_[async_](client|server)
  62. add_executable(ms_client "ms_client.cc"
  63. ${hw_proto_srcs}
  64. ${hw_grpc_srcs})
  65. target_link_libraries(ms_client
  66. gRPC::grpc++_reflection
  67. gRPC::grpc++
  68. protobuf::libprotobuf)