CMakeLists.txt 8.4 KB

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