Introduce SOVERSION for ABI compatibility (#771)

This commit sets the library's SOVERSION to its major version number.

Setting the soname this way establishes a clear ABI promise. This allows
users to safely upgrade to minor or patch releases without needing to
recompile their applications, as long as the major version remains the
same.
This commit is contained in:
Jan Grulich
2025-09-10 13:43:55 +02:00
committed by GitHub
parent 6c073b2833
commit dc1e76d60c
2 changed files with 3 additions and 0 deletions

View File

@@ -16,11 +16,13 @@ if(NOT ADS_VERSION)
string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GitTagVersion}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GitTagVersion}")
set(VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(VERSION_SONAME "${VERSION_MAJOR}")
else()
string(REGEX MATCHALL "[\.]" VERSION_DOT_MATCHES ${ADS_VERSION})
list(LENGTH VERSION_DOT_MATCHES VERSION_DOT_COUNT)
if(VERSION_DOT_COUNT EQUAL 2)
set(VERSION_SHORT ${ADS_VERSION})
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_SONAME "${ADS_VERSION}")
else()
message(FATAL_ERROR "ADS_VERSION must be in major.minor.patch format, e.g. 3.8.1. Got ${ADS_VERSION}")
endif()

View File

@@ -109,6 +109,7 @@ set_target_properties(${library_name} PROPERTIES
AUTORCC ON
CXX_EXTENSIONS OFF
VERSION ${VERSION_SHORT}
SOVERSION ${VERSION_SONAME}
EXPORT_NAME ${library_name}
DEBUG_POSTFIX "d"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib"