CMakeLists.txt 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright 2021 the gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. # cmake build file for C++ keyvaluestore example.
  16. # Assumes protobuf and gRPC have been installed using cmake.
  17. # See cmake_externalproject/CMakeLists.txt for all-in-one cmake build
  18. # that automatically builds all the dependencies before building keyvaluestore.
  19. cmake_minimum_required(VERSION 3.5.1)
  20. project(KeyValueStore C CXX)
  21. include(../cmake/common.cmake)
  22. # Proto file
  23. get_filename_component(kvs_proto "../../protos/keyvaluestore.proto" ABSOLUTE)
  24. get_filename_component(kvs_proto_path "${kvs_proto}" PATH)
  25. # Generated sources
  26. set(kvs_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.pb.cc")
  27. set(kvs_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.pb.h")
  28. set(kvs_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.grpc.pb.cc")
  29. set(kvs_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.grpc.pb.h")
  30. add_custom_command(
  31. OUTPUT "${kvs_proto_srcs}" "${kvs_proto_hdrs}" "${kvs_grpc_srcs}" "${kvs_grpc_hdrs}"
  32. COMMAND ${_PROTOBUF_PROTOC}
  33. ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
  34. --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
  35. -I "${kvs_proto_path}"
  36. --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  37. "${kvs_proto}"
  38. DEPENDS "${kvs_proto}")
  39. # Include generated *.pb.h files
  40. include_directories("${CMAKE_CURRENT_BINARY_DIR}")
  41. # kvs_grpc_proto
  42. add_library(kvs_grpc_proto
  43. ${kvs_grpc_srcs}
  44. ${kvs_grpc_hdrs}
  45. ${kvs_proto_srcs}
  46. ${kvs_proto_hdrs})
  47. target_link_libraries(kvs_grpc_proto
  48. ${_REFLECTION}
  49. ${_GRPC_GRPCPP}
  50. ${_PROTOBUF_LIBPROTOBUF})
  51. # client
  52. add_executable(client "client.cc" "caching_interceptor.h")
  53. target_link_libraries(client
  54. kvs_grpc_proto
  55. ${_REFLECTION}
  56. ${_GRPC_GRPCPP}
  57. ${_PROTOBUF_LIBPROTOBUF})
  58. # server
  59. add_executable(server "server.cc")
  60. target_link_libraries(server
  61. kvs_grpc_proto
  62. ${_REFLECTION}
  63. ${_GRPC_GRPCPP}
  64. ${_PROTOBUF_LIBPROTOBUF})