CMakeLists.txt 9.1 KB

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