CMakeLists.txt 1.9 KB

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