CMakeLists.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # C++ settings
  17. set(CMAKE_CXX_STANDARD 20)
  18. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  19. set(CMAKE_CXX_EXTENSIONS OFF)
  20. # Build options
  21. option(SMARTBOTIC_DB_BUILD_CLIENT "Build the database client library" ON)
  22. option(SMARTBOTIC_DB_BUILD_SERVICE "Build the database service executable" ${SMARTBOTIC_DB_STANDALONE})
  23. # Find required packages
  24. find_package(Protobuf REQUIRED)
  25. find_package(gRPC CONFIG QUIET)
  26. if(NOT gRPC_FOUND)
  27. find_package(PkgConfig REQUIRED)
  28. pkg_check_modules(GRPC REQUIRED grpc++)
  29. endif()
  30. find_package(nlohmann_json 3.2.0 QUIET)
  31. if(NOT nlohmann_json_FOUND)
  32. find_package(PkgConfig QUIET)
  33. if(PKG_CONFIG_FOUND)
  34. pkg_check_modules(NLOHMANN_JSON QUIET nlohmann_json)
  35. endif()
  36. if(NOT nlohmann_json_FOUND AND NOT NLOHMANN_JSON_FOUND)
  37. # Not available on system - parent project or FetchContent provides it
  38. if(NOT TARGET nlohmann_json::nlohmann_json)
  39. include(FetchContent)
  40. FetchContent_Declare(
  41. nlohmann_json
  42. GIT_REPOSITORY https://github.com/nlohmann/json.git
  43. GIT_TAG v3.11.3
  44. GIT_SHALLOW TRUE
  45. )
  46. set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
  47. set(JSON_Install OFF CACHE BOOL "" FORCE)
  48. FetchContent_MakeAvailable(nlohmann_json)
  49. endif()
  50. elseif(NLOHMANN_JSON_FOUND AND NOT TARGET nlohmann_json::nlohmann_json)
  51. add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
  52. set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
  53. INTERFACE_INCLUDE_DIRECTORIES "${NLOHMANN_JSON_INCLUDE_DIRS}"
  54. )
  55. endif()
  56. endif()
  57. # Find spdlog
  58. find_package(spdlog QUIET)
  59. if(NOT spdlog_FOUND)
  60. find_package(PkgConfig REQUIRED)
  61. pkg_check_modules(SPDLOG REQUIRED spdlog)
  62. endif()
  63. # Optional: systemd support
  64. find_package(PkgConfig)
  65. if(PKG_CONFIG_FOUND)
  66. pkg_check_modules(SYSTEMD QUIET libsystemd)
  67. endif()
  68. # Proto compilation
  69. add_subdirectory(proto)
  70. # Client library
  71. if(SMARTBOTIC_DB_BUILD_CLIENT)
  72. add_subdirectory(client)
  73. endif()
  74. # Service executable
  75. if(SMARTBOTIC_DB_BUILD_SERVICE)
  76. add_subdirectory(service)
  77. endif()
  78. # Tests (standalone build only)
  79. option(SMARTBOTIC_DB_BUILD_TESTS "Build unit/integration tests" ${SMARTBOTIC_DB_STANDALONE})
  80. if(SMARTBOTIC_DB_BUILD_TESTS)
  81. add_subdirectory(tests)
  82. endif()
  83. # Print configuration summary
  84. if(SMARTBOTIC_DB_STANDALONE)
  85. message(STATUS "")
  86. message(STATUS "Smartbotic Database ${SMARTBOTIC_DB_VERSION}")
  87. message(STATUS " Build client library: ${SMARTBOTIC_DB_BUILD_CLIENT}")
  88. message(STATUS " Build service: ${SMARTBOTIC_DB_BUILD_SERVICE}")
  89. message(STATUS " Build tests: ${SMARTBOTIC_DB_BUILD_TESTS}")
  90. message(STATUS " Systemd support: ${SYSTEMD_FOUND}")
  91. message(STATUS "")
  92. endif()