CMakeLists.txt 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. cmake_minimum_required(VERSION 3.20)
  2. project(SmartBotic VERSION 1.0.0 LANGUAGES CXX C)
  3. set(CMAKE_CXX_STANDARD 20)
  4. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  5. set(CMAKE_CXX_EXTENSIONS OFF)
  6. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  7. # Include CMake modules
  8. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  9. include(CompilerFlags)
  10. include(Dependencies)
  11. include(FindPackages)
  12. # Common library
  13. add_library(smartbotic_common STATIC
  14. lib/common/uuid.cpp
  15. lib/common/time_utils.cpp
  16. lib/common/error.cpp
  17. lib/common/string_utils.cpp
  18. )
  19. target_include_directories(smartbotic_common PUBLIC
  20. ${CMAKE_CURRENT_SOURCE_DIR}/lib
  21. )
  22. target_link_libraries(smartbotic_common PUBLIC
  23. nlohmann_json::nlohmann_json
  24. OpenSSL::Crypto
  25. )
  26. # Logging library
  27. add_library(smartbotic_logging STATIC
  28. lib/logging/logger.cpp
  29. )
  30. target_include_directories(smartbotic_logging PUBLIC
  31. ${CMAKE_CURRENT_SOURCE_DIR}/lib
  32. )
  33. target_link_libraries(smartbotic_logging PUBLIC
  34. spdlog::spdlog
  35. smartbotic_common
  36. )
  37. # Config library
  38. add_library(smartbotic_config STATIC
  39. lib/config/config_loader.cpp
  40. )
  41. target_include_directories(smartbotic_config PUBLIC
  42. ${CMAKE_CURRENT_SOURCE_DIR}/lib
  43. )
  44. target_link_libraries(smartbotic_config PUBLIC
  45. smartbotic_common
  46. smartbotic_logging
  47. nlohmann_json::nlohmann_json
  48. )
  49. # Storage client library
  50. add_library(smartbotic_storage STATIC
  51. lib/storage/storage_client.cpp
  52. )
  53. target_include_directories(smartbotic_storage PUBLIC
  54. ${CMAKE_CURRENT_SOURCE_DIR}/lib
  55. ${CMAKE_CURRENT_BINARY_DIR}
  56. )
  57. target_link_libraries(smartbotic_storage PUBLIC
  58. smartbotic_common
  59. smartbotic_logging
  60. smartbotic_proto
  61. )
  62. # Crypto library
  63. add_library(smartbotic_crypto STATIC
  64. lib/crypto/aes_gcm.cpp
  65. )
  66. target_include_directories(smartbotic_crypto PUBLIC
  67. ${CMAKE_CURRENT_SOURCE_DIR}/lib
  68. )
  69. target_link_libraries(smartbotic_crypto PUBLIC
  70. smartbotic_common
  71. OpenSSL::Crypto
  72. nlohmann_json::nlohmann_json
  73. )
  74. # Credentials library
  75. add_library(smartbotic_credentials STATIC
  76. lib/credentials/credential_types.cpp
  77. lib/credentials/credential_store.cpp
  78. lib/credentials/credential_client.cpp
  79. )
  80. target_include_directories(smartbotic_credentials PUBLIC
  81. ${CMAKE_CURRENT_SOURCE_DIR}/lib
  82. ${CMAKE_CURRENT_BINARY_DIR}
  83. )
  84. target_link_libraries(smartbotic_credentials PUBLIC
  85. smartbotic_common
  86. smartbotic_logging
  87. smartbotic_crypto
  88. smartbotic_storage
  89. smartbotic_proto
  90. CURL::libcurl
  91. )
  92. # Proto library
  93. add_library(smartbotic_proto STATIC
  94. ${CMAKE_CURRENT_BINARY_DIR}/proto/common.pb.cc
  95. ${CMAKE_CURRENT_BINARY_DIR}/proto/common.grpc.pb.cc
  96. ${CMAKE_CURRENT_BINARY_DIR}/proto/storage.pb.cc
  97. ${CMAKE_CURRENT_BINARY_DIR}/proto/storage.grpc.pb.cc
  98. ${CMAKE_CURRENT_BINARY_DIR}/proto/workflow.pb.cc
  99. ${CMAKE_CURRENT_BINARY_DIR}/proto/workflow.grpc.pb.cc
  100. ${CMAKE_CURRENT_BINARY_DIR}/proto/runner.pb.cc
  101. ${CMAKE_CURRENT_BINARY_DIR}/proto/runner.grpc.pb.cc
  102. ${CMAKE_CURRENT_BINARY_DIR}/proto/credentials.pb.cc
  103. ${CMAKE_CURRENT_BINARY_DIR}/proto/credentials.grpc.pb.cc
  104. )
  105. target_include_directories(smartbotic_proto PUBLIC
  106. ${CMAKE_CURRENT_BINARY_DIR}
  107. )
  108. target_link_libraries(smartbotic_proto PUBLIC
  109. gRPC::grpc++
  110. protobuf::libprotobuf
  111. )
  112. # Generate proto files
  113. find_program(PROTOC protoc REQUIRED)
  114. find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin REQUIRED)
  115. set(PROTO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/proto)
  116. set(PROTO_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)
  117. file(MAKE_DIRECTORY ${PROTO_OUT_DIR})
  118. set(PROTO_FILES common storage workflow runner credentials)
  119. foreach(PROTO ${PROTO_FILES})
  120. add_custom_command(
  121. OUTPUT
  122. ${PROTO_OUT_DIR}/${PROTO}.pb.cc
  123. ${PROTO_OUT_DIR}/${PROTO}.pb.h
  124. ${PROTO_OUT_DIR}/${PROTO}.grpc.pb.cc
  125. ${PROTO_OUT_DIR}/${PROTO}.grpc.pb.h
  126. COMMAND ${PROTOC}
  127. --proto_path=${PROTO_DIR}
  128. --cpp_out=${PROTO_OUT_DIR}
  129. --grpc_out=${PROTO_OUT_DIR}
  130. --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
  131. ${PROTO_DIR}/${PROTO}.proto
  132. DEPENDS ${PROTO_DIR}/${PROTO}.proto
  133. COMMENT "Generating protobuf files for ${PROTO}.proto"
  134. )
  135. endforeach()
  136. # Database service
  137. add_executable(smartbotic-database
  138. src/database/main.cpp
  139. src/database/memory_store.cpp
  140. src/database/database_service.cpp
  141. src/database/persistence/wal.cpp
  142. src/database/persistence/snapshot.cpp
  143. )
  144. target_include_directories(smartbotic-database PRIVATE
  145. ${CMAKE_CURRENT_SOURCE_DIR}/src
  146. ${CMAKE_CURRENT_BINARY_DIR}
  147. )
  148. target_link_libraries(smartbotic-database PRIVATE
  149. smartbotic_common
  150. smartbotic_logging
  151. smartbotic_config
  152. smartbotic_proto
  153. gRPC::grpc++
  154. )
  155. # WebServer service
  156. add_executable(smartbotic-webserver
  157. src/webserver/main.cpp
  158. src/webserver/http_server.cpp
  159. src/webserver/websocket_server.cpp
  160. src/webserver/webserver_service.cpp
  161. src/webserver/auth/bcrypt_utils.cpp
  162. src/webserver/auth/jwt_utils.cpp
  163. src/webserver/auth/auth_store.cpp
  164. src/webserver/auth/auth_middleware.cpp
  165. src/webserver/runners/runner_registry.cpp
  166. src/webserver/runners/load_balancer.cpp
  167. src/webserver/nodes/node_store.cpp
  168. src/webserver/scheduler/workflow_scheduler.cpp
  169. src/webserver/grpc/node_sync_service.cpp
  170. src/webserver/grpc/credential_service.cpp
  171. src/webserver/api/auth_controller.cpp
  172. src/webserver/api/credential_controller.cpp
  173. src/webserver/api/user_controller.cpp
  174. src/webserver/api/workflow_controller.cpp
  175. src/webserver/api/workflow_group_controller.cpp
  176. src/webserver/api/execution_controller.cpp
  177. src/webserver/api/node_controller.cpp
  178. src/webserver/api/runner_controller.cpp
  179. src/webserver/api/webhook_controller.cpp
  180. src/webserver/api/database_controller.cpp
  181. )
  182. target_include_directories(smartbotic-webserver PRIVATE
  183. ${CMAKE_CURRENT_SOURCE_DIR}/src
  184. ${CMAKE_CURRENT_BINARY_DIR}
  185. )
  186. target_link_libraries(smartbotic-webserver PRIVATE
  187. smartbotic_common
  188. smartbotic_logging
  189. smartbotic_config
  190. smartbotic_storage
  191. smartbotic_credentials
  192. smartbotic_proto
  193. httplib::httplib
  194. websockets
  195. bcrypt_lib
  196. gRPC::grpc++
  197. OpenSSL::SSL
  198. OpenSSL::Crypto
  199. )
  200. # Runner service
  201. set(RUNNER_SOURCES
  202. src/runner/main.cpp
  203. src/runner/workflow_engine.cpp
  204. src/runner/node_registry.cpp
  205. src/runner/error_handler.cpp
  206. src/runner/runner_service.cpp
  207. src/runner/collection_permissions.cpp
  208. src/runner/engine/script_engine.cpp
  209. src/runner/imap/imap_client.cpp
  210. )
  211. # Add MySQL client if library is found
  212. if(MYSQL_CLIENT_FOUND)
  213. list(APPEND RUNNER_SOURCES src/runner/mysql/mysql_client.cpp)
  214. endif()
  215. # Add PostgreSQL client if library is found
  216. if(POSTGRESQL_CLIENT_FOUND)
  217. list(APPEND RUNNER_SOURCES src/runner/postgresql/postgresql_client.cpp)
  218. endif()
  219. add_executable(smartbotic-runner ${RUNNER_SOURCES})
  220. target_include_directories(smartbotic-runner PRIVATE
  221. ${CMAKE_CURRENT_SOURCE_DIR}/src
  222. ${CMAKE_CURRENT_BINARY_DIR}
  223. )
  224. target_link_libraries(smartbotic-runner PRIVATE
  225. smartbotic_common
  226. smartbotic_logging
  227. smartbotic_config
  228. smartbotic_storage
  229. smartbotic_credentials
  230. smartbotic_proto
  231. quickjs_lib
  232. CURL::libcurl
  233. gRPC::grpc++
  234. )
  235. # Add MySQL client library if found
  236. if(MYSQL_CLIENT_FOUND)
  237. target_link_libraries(smartbotic-runner PRIVATE mysql_client)
  238. target_compile_definitions(smartbotic-runner PRIVATE MYSQL_SUPPORT=1)
  239. endif()
  240. # Add PostgreSQL client library if found
  241. if(POSTGRESQL_CLIENT_FOUND)
  242. target_link_libraries(smartbotic-runner PRIVATE postgresql_client)
  243. target_compile_definitions(smartbotic-runner PRIVATE POSTGRESQL_SUPPORT=1)
  244. endif()
  245. # Migration tool
  246. add_executable(smartbotic-migrate-nodes
  247. src/tools/migrate_nodes.cpp
  248. )
  249. target_include_directories(smartbotic-migrate-nodes PRIVATE
  250. ${CMAKE_CURRENT_SOURCE_DIR}/lib
  251. )
  252. target_link_libraries(smartbotic-migrate-nodes PRIVATE
  253. nlohmann_json::nlohmann_json
  254. CURL::libcurl
  255. )
  256. # Install targets
  257. install(TARGETS
  258. smartbotic-database
  259. smartbotic-webserver
  260. smartbotic-runner
  261. smartbotic-migrate-nodes
  262. RUNTIME DESTINATION bin
  263. )
  264. install(DIRECTORY nodes/ DESTINATION share/smartbotic/nodes)
  265. install(DIRECTORY config/ DESTINATION etc/smartbotic)