CMakeLists.txt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. target_include_directories(smartbotic-db-client PUBLIC
  32. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  33. $<INSTALL_INTERFACE:include>
  34. )
  35. # Link dependencies
  36. target_link_libraries(smartbotic-db-client PUBLIC
  37. smartbotic_db_proto
  38. )
  39. if(TARGET nlohmann_json::nlohmann_json)
  40. target_link_libraries(smartbotic-db-client PUBLIC nlohmann_json::nlohmann_json)
  41. else()
  42. target_include_directories(smartbotic-db-client PUBLIC ${NLOHMANN_JSON_INCLUDE_DIRS})
  43. endif()
  44. if(TARGET spdlog::spdlog)
  45. target_link_libraries(smartbotic-db-client PUBLIC spdlog::spdlog)
  46. else()
  47. target_link_libraries(smartbotic-db-client PUBLIC ${SPDLOG_LIBRARIES})
  48. target_include_directories(smartbotic-db-client PUBLIC ${SPDLOG_INCLUDE_DIRS})
  49. endif()
  50. # Export alias
  51. add_library(smartbotic::db-client ALIAS smartbotic-db-client)
  52. # Installation (standalone/packaging only)
  53. if(SMARTBOTIC_DB_STANDALONE)
  54. include(GNUInstallDirs)
  55. install(TARGETS smartbotic-db-client
  56. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  57. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  58. )
  59. install(DIRECTORY include/smartbotic
  60. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  61. )
  62. endif()