CMakeLists.txt 9.4 KB

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