CMakeLists.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. ${PROTO_DIR}/llm.proto
  13. ${PROTO_DIR}/runner.proto
  14. )
  15. # Generate C++ sources from proto files
  16. set(PROTO_SRCS)
  17. set(PROTO_HDRS)
  18. set(GRPC_SRCS)
  19. set(GRPC_HDRS)
  20. foreach(PROTO_FILE ${PROTO_FILES})
  21. get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
  22. list(APPEND PROTO_SRCS "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.cc")
  23. list(APPEND PROTO_HDRS "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.h")
  24. list(APPEND GRPC_SRCS "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.cc")
  25. list(APPEND GRPC_HDRS "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.h")
  26. add_custom_command(
  27. OUTPUT
  28. "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.cc"
  29. "${PROTO_GEN_DIR}/${PROTO_NAME}.pb.h"
  30. "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.cc"
  31. "${PROTO_GEN_DIR}/${PROTO_NAME}.grpc.pb.h"
  32. COMMAND ${PROTOC_EXECUTABLE}
  33. --cpp_out=${PROTO_GEN_DIR}
  34. --grpc_out=${PROTO_GEN_DIR}
  35. --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
  36. -I${PROTO_DIR}
  37. ${PROTO_FILE}
  38. DEPENDS ${PROTO_FILE}
  39. COMMENT "Generating protobuf/gRPC sources for ${PROTO_NAME}"
  40. )
  41. endforeach()
  42. # Proto library
  43. add_library(smartbotic_proto STATIC
  44. ${PROTO_SRCS}
  45. ${GRPC_SRCS}
  46. )
  47. target_include_directories(smartbotic_proto
  48. PUBLIC
  49. ${PROTO_GEN_DIR}
  50. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  51. )
  52. # Link against system gRPC and protobuf
  53. target_link_libraries(smartbotic_proto
  54. PUBLIC
  55. PkgConfig::GRPC
  56. grpc_reflection
  57. protobuf::libprotobuf
  58. )
  59. add_library(smartbotic::proto ALIAS smartbotic_proto)