CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. cmake_minimum_required(VERSION 3.20)
  2. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
  3. "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
  4. file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" SVAPI_VERSION)
  5. string(STRIP "${SVAPI_VERSION}" SVAPI_VERSION)
  6. project(smartbotic-vectorapi VERSION ${SVAPI_VERSION} LANGUAGES CXX)
  7. set(CMAKE_CXX_STANDARD 20)
  8. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  9. set(CMAKE_CXX_EXTENSIONS OFF)
  10. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  11. if(NOT CMAKE_BUILD_TYPE)
  12. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
  13. endif()
  14. option(BUILD_TESTS "Build tests" ON)
  15. option(BUILD_WEBUI "Build the React web UI via npm" ON)
  16. # The function runner vendors QuickJS over the network at configure time, so it
  17. # stays opt-in: an ordinary build and the whole existing test cycle must not
  18. # start depending on a GitHub fetch. Build it on its own with
  19. # cmake -S runner -B build-runner
  20. # which also works on the dev host, where the root project cannot configure.
  21. option(BUILD_RUNNER "Build the QuickJS function runner" OFF)
  22. include(GNUInstallDirs)
  23. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
  24. include(Dependencies)
  25. find_package(smartbotic-db-client REQUIRED)
  26. find_package(nlohmann_json REQUIRED)
  27. find_package(spdlog REQUIRED)
  28. find_package(OpenSSL REQUIRED)
  29. # Optional systemd (sd_notify)
  30. find_package(PkgConfig)
  31. if(PkgConfig_FOUND)
  32. pkg_check_modules(SYSTEMD IMPORTED_TARGET libsystemd)
  33. endif()
  34. # git commit for version banner.
  35. #
  36. # An EXPLICITLY PROVIDED value wins over the git probe, and that ordering is the
  37. # whole point: the Docker release path has no `.git` (`.dockerignore` excludes
  38. # it), so the probe fails there and every release deb reported
  39. # `commit: unknown` while the local build reported the sha. build.sh had always
  40. # computed the commit and passed it as `--build-arg BUILD_GIT_COMMIT`, and
  41. # Dockerfile.build never declared the ARG - so Docker silently dropped it and
  42. # nothing consumed it. Accepted and ignored, in the build system rather than on
  43. # a route.
  44. #
  45. # It matters because this field is the cheapest answer to "is that fix in this
  46. # release": without it, the only instruments are the deb's mtime, which is not
  47. # evidence, and mapping a commit against a bump commit, which needs you to
  48. # already know the bump.
  49. if(NOT SVAPI_GIT_COMMIT)
  50. execute_process(COMMAND git rev-parse --short HEAD
  51. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  52. OUTPUT_VARIABLE SVAPI_GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE
  53. ERROR_QUIET)
  54. endif()
  55. if(NOT SVAPI_GIT_COMMIT)
  56. set(SVAPI_GIT_COMMIT "unknown")
  57. endif()
  58. configure_file(${CMAKE_SOURCE_DIR}/cmake/version.hpp.in
  59. ${CMAKE_BINARY_DIR}/generated/svapi/version.hpp @ONLY)
  60. add_subdirectory(src)
  61. if(BUILD_TESTS)
  62. enable_testing()
  63. add_subdirectory(tests)
  64. endif()
  65. # After the BUILD_TESTS block on purpose: runner/CMakeLists.txt registers tests,
  66. # which needs enable_testing() to have run already.
  67. if(BUILD_RUNNER)
  68. add_subdirectory(runner)
  69. endif()
  70. if(BUILD_WEBUI)
  71. include(WebUI OPTIONAL) # provided by plan 2; absent is fine
  72. endif()
  73. # Install: config conffile, api docs
  74. install(FILES ${CMAKE_SOURCE_DIR}/config/config.json
  75. DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/smartbotic-vectorapi)
  76. install(FILES ${CMAKE_SOURCE_DIR}/runner/config/runner.json
  77. DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/smartbotic-vectorapi
  78. OPTIONAL)
  79. install(FILES ${CMAKE_SOURCE_DIR}/api/openapi.json
  80. ${CMAKE_SOURCE_DIR}/api/llms.txt
  81. DESTINATION ${CMAKE_INSTALL_DATADIR}/smartbotic-vectorapi
  82. OPTIONAL)