CMakeLists.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. cmake_minimum_required(VERSION 3.8)
  2. project(grpc_ex CXX)
  3. get_filename_component(ex_proto "grpc_ex.proto" ABSOLUTE)
  4. get_filename_component(ex_proto_path "${ex_proto}" PATH)
  5. # Generated sources
  6. set(ex_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/../grpc_ex.pb.cc")
  7. set(ex_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/../grpc_ex.pb.h")
  8. set(ex_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/../grpc_ex.grpc.pb.cc")
  9. set(ex_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/../grpc_ex.grpc.pb.h")
  10. #[[
  11. find_package(Protobuf REQUIRED)
  12. add_custom_command(
  13. OUTPUT "${ex_proto_srcs}" "${ex_proto_hdrs}" "${ex_grpc_srcs}" "${ex_grpc_hdrs}"
  14. COMMAND ${_PROTOBUF_PROTOC}
  15. ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}/.."
  16. --cpp_out="${CMAKE_CURRENT_BINARY_DIR}/.."
  17. -I "${ex_proto_path}/.."
  18. --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  19. "${ex_proto}"
  20. DEPENDS "${ex_proto}")
  21. ]]
  22. # Include generated *.pb.h files
  23. include_directories("${CMAKE_CURRENT_BINARY_DIR}/..")
  24. find_package(Protobuf CONFIG REQUIRED)
  25. message(STATUS "Using protobuf ${Protobuf_VERSION}")
  26. find_package(gRPC CONFIG REQUIRED)
  27. message(STATUS "Using gRPC ${gRPC_VERSION}")
  28. set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
  29. set(_REFLECTION gRPC::grpc++_reflection)
  30. set(_GRPC_GRPCPP gRPC::grpc++)
  31. # ex_grpc_proto
  32. add_library(ex_grpc_proto
  33. ${ex_grpc_srcs}
  34. ${ex_grpc_hdrs}
  35. ${ex_proto_srcs}
  36. ${ex_proto_hdrs})
  37. target_link_libraries(ex_grpc_proto
  38. ${_REFLECTION}
  39. ${_GRPC_GRPCPP}
  40. ${_PROTOBUF_LIBPROTOBUF})
  41. add_executable(server "server.cpp")
  42. target_link_libraries(server
  43. ex_grpc_proto
  44. ${_REFLECTION}
  45. ${_GRPC_GRPCPP}
  46. ${_PROTOBUF_LIBPROTOBUF})
  47. add_executable(client "client.cpp")
  48. target_link_libraries(client
  49. ex_grpc_proto
  50. ${_REFLECTION}
  51. ${_GRPC_GRPCPP}
  52. ${_PROTOBUF_LIBPROTOBUF})