CMakeLists.txt 9.5 KB

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