CMakeLists.txt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Protocol Buffers and gRPC service definitions
  2. # Uses system-installed protobuf and gRPC packages
  3. # Proto files directory
  4. set(PROTO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/proto)
  5. # Generated files directory
  6. set(PROTO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
  7. file(MAKE_DIRECTORY ${PROTO_GEN_DIR})
  8. # Proto source files
  9. set(PROTO_FILES
  10. ${PROTO_DIR}/crm.proto
  11. ${PROTO_DIR}/database.proto
  12. )
  13. # Generate C++ sources from proto files
  14. set(PROTO_SRCS)
  15. set(PROTO_HDRS)
  16. set(GRPC_SRCS)
  17. set(GRPC_HDRS)
  18. foreach(PROTO_FILE ${PROTO_FILES})
  19. get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
  20. list(APPEND PROTO_SRCS "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.cc")
  21. list(APPEND PROTO_HDRS "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.h")
  22. list(APPEND GRPC_SRCS "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.cc")
  23. list(APPEND GRPC_HDRS "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.h")
  24. add_custom_command(
  25. OUTPUT
  26. "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.cc"
  27. "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.h"
  28. "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.cc"
  29. "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.h"
  30. COMMAND ${PROTOC_EXECUTABLE}
  31. --cpp_out=${PROTO_GEN_DIR}
  32. --grpc_out=${PROTO_GEN_DIR}
  33. --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
  34. -I${PROTO_DIR}
  35. ${PROTO_FILE}
  36. DEPENDS ${PROTO_FILE}
  37. COMMENT "Generating protobuf/gRPC sources for ${PROTO_NAME}"
  38. )
  39. endforeach()
  40. # Proto library
  41. add_library(smartbotic_proto STATIC
  42. ${PROTO_SRCS}
  43. ${GRPC_SRCS}
  44. )
  45. target_include_directories(smartbotic_proto
  46. PUBLIC
  47. ${PROTO_GEN_DIR}
  48. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  49. )
  50. # Link against system gRPC and protobuf
  51. target_link_libraries(smartbotic_proto
  52. PUBLIC
  53. PkgConfig::GRPC
  54. grpc_reflection
  55. protobuf::libprotobuf
  56. )
  57. add_library(smartbotic::proto ALIAS smartbotic_proto)