Skip to content

Commit

Permalink
Embed versioning information in the library
Browse files Browse the repository at this point in the history
C (and C++) libraries embed version information, and when shared
objects are distributed, the versioning information is used to ensure
that the library is appropriately compatible with the code it was
built against.

This change makes the library have a version that matches the major
version.  That is, it commits the project to maintaining backward ABI
compatibility unless the major version number changes.

This is concretely useful for any system that distributes library
updates independently from the software (e.g. to fix a security bug in
the underlying library).  For example, this includes most GNU/Linux
distributions.
  • Loading branch information
dkg committed Jun 21, 2023
1 parent 32ff6f7 commit 102b416
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,18 @@ target_include_directories(sexp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

string(REGEX MATCH "^([0-9]+)\\.[0-9]+\\.[0-9]+$" vmatches "${SEXP_VERSION}")
if (NOT vmatches)
message(FATAL_ERROR "Failed to extract major version from SEXP_VERSION (${SEXP_VERSION}).")
endif()
set(SEXP_MAJOR_VERSION "${CMAKE_MATCH_1}")

set_target_properties(sexp PROPERTIES
POSITION_INDEPENDENT_CODE ON
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
VERSION "${SEXP_VERSION}"
SOVERSION "${SEXP_MAJOR_VERSION}"
)

if(WITH_SEXP_CLI)
Expand Down

0 comments on commit 102b416

Please sign in to comment.