CMakeLists.txt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Smartbotic Database Client Library
  2. if(BUILD_SHARED_LIBS)
  3. add_library(smartbotic-db-client SHARED
  4. src/client.cpp
  5. $<TARGET_OBJECTS:smartbotic_db_proto>
  6. )
  7. # SOVERSION stays 2 — and the rule that keeps it honest:
  8. #
  9. # BUMP THIS whenever a public struct changes size or layout. It stayed at 2
  10. # across v2.1-v2.7.0 while Client::CollectionConfig (v2.4.5) and FileRecord
  11. # (v2.6.0) both gained members, on the reasoning that "consumers must
  12. # rebuild". That reasoning failed the moment it was tested: a v2.7.1 attempt
  13. # to add `projection` to Client::QueryOptions changed the struct size without
  14. # changing the soname, and the already-installed smartbotic-webserver -
  15. # compiled against the v2.7.0 layout - bound to the new library and SIGSEGV'd
  16. # in a restart loop until the packages were rolled back.
  17. #
  18. # A changelog note is not an enforcement mechanism; a soname is. v2.7.1
  19. # therefore adds projection as an OVERLOAD rather than a struct member, so
  20. # existing binaries keep working untouched. The next deliberate layout change
  21. # bumps this to 3 and renames the package alongside it.
  22. set_target_properties(smartbotic-db-client PROPERTIES
  23. VERSION ${SMARTBOTIC_DB_VERSION}
  24. SOVERSION 2
  25. )
  26. else()
  27. add_library(smartbotic-db-client STATIC
  28. src/client.cpp
  29. )
  30. endif()
  31. # v2.11.1 — clientLibraryVersion()/clientLibraryCommit() report what the loaded
  32. # .so actually is. Same two macros the service and CLI targets define.
  33. target_compile_definitions(smartbotic-db-client PRIVATE
  34. SMARTBOTIC_DB_VERSION_STRING="${SMARTBOTIC_DB_VERSION}"
  35. SMARTBOTIC_DB_GIT_COMMIT_STRING="${SMARTBOTIC_DB_GIT_COMMIT}"
  36. )
  37. target_include_directories(smartbotic-db-client PUBLIC
  38. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  39. $<INSTALL_INTERFACE:include>
  40. )
  41. # Link dependencies
  42. target_link_libraries(smartbotic-db-client PUBLIC
  43. smartbotic_db_proto
  44. )
  45. if(TARGET nlohmann_json::nlohmann_json)
  46. target_link_libraries(smartbotic-db-client PUBLIC nlohmann_json::nlohmann_json)
  47. else()
  48. target_include_directories(smartbotic-db-client PUBLIC ${NLOHMANN_JSON_INCLUDE_DIRS})
  49. endif()
  50. if(TARGET spdlog::spdlog)
  51. target_link_libraries(smartbotic-db-client PUBLIC spdlog::spdlog)
  52. else()
  53. target_link_libraries(smartbotic-db-client PUBLIC ${SPDLOG_LIBRARIES})
  54. target_include_directories(smartbotic-db-client PUBLIC ${SPDLOG_INCLUDE_DIRS})
  55. endif()
  56. # Export alias
  57. add_library(smartbotic::db-client ALIAS smartbotic-db-client)
  58. # Installation (standalone/packaging only)
  59. if(SMARTBOTIC_DB_STANDALONE)
  60. include(GNUInstallDirs)
  61. install(TARGETS smartbotic-db-client
  62. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  63. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  64. )
  65. install(DIRECTORY include/smartbotic
  66. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  67. )
  68. endif()