CMakeLists.txt 7.7 KB

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