CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Smartbotic Database
  2. # Standalone document database with gRPC API
  3. cmake_minimum_required(VERSION 3.20)
  4. # Read version from VERSION file
  5. file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" SMARTBOTIC_DB_VERSION)
  6. string(STRIP "${SMARTBOTIC_DB_VERSION}" SMARTBOTIC_DB_VERSION)
  7. # Detect standalone vs embedded mode
  8. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  9. # Building as standalone project
  10. project(smartbotic-database VERSION ${SMARTBOTIC_DB_VERSION} LANGUAGES CXX C)
  11. set(SMARTBOTIC_DB_STANDALONE ON)
  12. else()
  13. # Building as embedded submodule
  14. set(SMARTBOTIC_DB_STANDALONE OFF)
  15. endif()
  16. # Shared libraries for standalone (packaging), static for embedded (submodule)
  17. option(BUILD_SHARED_LIBS "Build shared libraries" ${SMARTBOTIC_DB_STANDALONE})
  18. # C++ settings
  19. set(CMAKE_CXX_STANDARD 20)
  20. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  21. set(CMAKE_CXX_EXTENSIONS OFF)
  22. # Build options
  23. option(SMARTBOTIC_DB_BUILD_CLIENT "Build the database client library" ON)
  24. option(SMARTBOTIC_DB_BUILD_SERVICE "Build the database service executable" ${SMARTBOTIC_DB_STANDALONE})
  25. # Find required packages
  26. find_package(Protobuf REQUIRED)
  27. find_package(gRPC CONFIG QUIET)
  28. if(NOT gRPC_FOUND)
  29. find_package(PkgConfig REQUIRED)
  30. pkg_check_modules(GRPC REQUIRED grpc++)
  31. endif()
  32. find_package(nlohmann_json 3.2.0 QUIET)
  33. if(NOT nlohmann_json_FOUND)
  34. find_package(PkgConfig QUIET)
  35. if(PKG_CONFIG_FOUND)
  36. pkg_check_modules(NLOHMANN_JSON QUIET nlohmann_json)
  37. endif()
  38. if(NOT nlohmann_json_FOUND AND NOT NLOHMANN_JSON_FOUND)
  39. # Not available on system - parent project or FetchContent provides it
  40. if(NOT TARGET nlohmann_json::nlohmann_json)
  41. include(FetchContent)
  42. FetchContent_Declare(
  43. nlohmann_json
  44. GIT_REPOSITORY https://github.com/nlohmann/json.git
  45. GIT_TAG v3.11.3
  46. GIT_SHALLOW TRUE
  47. )
  48. set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
  49. set(JSON_Install OFF CACHE BOOL "" FORCE)
  50. FetchContent_MakeAvailable(nlohmann_json)
  51. endif()
  52. elseif(NLOHMANN_JSON_FOUND AND NOT TARGET nlohmann_json::nlohmann_json)
  53. add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
  54. set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
  55. INTERFACE_INCLUDE_DIRECTORIES "${NLOHMANN_JSON_INCLUDE_DIRS}"
  56. )
  57. endif()
  58. endif()
  59. # Find spdlog
  60. find_package(spdlog QUIET)
  61. if(NOT spdlog_FOUND)
  62. find_package(PkgConfig REQUIRED)
  63. pkg_check_modules(SPDLOG REQUIRED spdlog)
  64. endif()
  65. # Optional: systemd support
  66. find_package(PkgConfig)
  67. if(PKG_CONFIG_FOUND)
  68. pkg_check_modules(SYSTEMD QUIET libsystemd)
  69. endif()
  70. # Proto compilation
  71. add_subdirectory(proto)
  72. # Client library
  73. if(SMARTBOTIC_DB_BUILD_CLIENT)
  74. add_subdirectory(client)
  75. endif()
  76. # Service executable
  77. if(SMARTBOTIC_DB_BUILD_SERVICE)
  78. add_subdirectory(service)
  79. endif()
  80. # CLI admin tool (standalone build only)
  81. option(SMARTBOTIC_DB_BUILD_CLI "Build CLI admin tool" ${SMARTBOTIC_DB_STANDALONE})
  82. if(SMARTBOTIC_DB_BUILD_CLI)
  83. add_subdirectory(cli)
  84. endif()
  85. # Tests (standalone build only)
  86. option(SMARTBOTIC_DB_BUILD_TESTS "Build unit/integration tests" ${SMARTBOTIC_DB_STANDALONE})
  87. if(SMARTBOTIC_DB_BUILD_TESTS)
  88. add_subdirectory(tests)
  89. endif()
  90. # Print configuration summary
  91. if(SMARTBOTIC_DB_STANDALONE)
  92. message(STATUS "")
  93. message(STATUS "Smartbotic Database ${SMARTBOTIC_DB_VERSION}")
  94. message(STATUS " Build client library: ${SMARTBOTIC_DB_BUILD_CLIENT}")
  95. message(STATUS " Build service: ${SMARTBOTIC_DB_BUILD_SERVICE}")
  96. message(STATUS " Build tests: ${SMARTBOTIC_DB_BUILD_TESTS}")
  97. message(STATUS " Systemd support: ${SYSTEMD_FOUND}")
  98. message(STATUS "")
  99. endif()