build: Mechanically generate ABI versions from version number

If we're strict about applying something resembling semantic versioning
to the "marketing" version number, then we can mechanically generate
the ABI version from it.

This limits the range of valid micro versions (patchlevels) to 0-99.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-05-04 16:40:11 +01:00 committed by Sam Lantinga
parent 60d702ac74
commit fff97c95eb
5 changed files with 57 additions and 35 deletions

View File

@ -60,12 +60,7 @@ include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
set(SDL_MAJOR_VERSION 2)
set(SDL_MINOR_VERSION 23)
set(SDL_MICRO_VERSION 0)
set(SDL_INTERFACE_AGE 0)
set(SDL_BINARY_AGE 23)
set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
# the following should match the versions in Xcode project file:
set(DYLIB_CURRENT_VERSION 24.0.0)
set(DYLIB_COMPATIBILITY_VERSION 1.0.0)
# Set defaults preventing destination file conflicts
set(SDL_CMAKE_DEBUG_POSTFIX "d"
@ -74,9 +69,22 @@ set(SDL_CMAKE_DEBUG_POSTFIX "d"
mark_as_advanced(CMAKE_IMPORT_LIBRARY_SUFFIX SDL_CMAKE_DEBUG_POSTFIX)
# Calculate a libtool-like version number
math(EXPR LT_CURRENT "${SDL_MINOR_VERSION} - ${SDL_INTERFACE_AGE}")
math(EXPR SDL_BINARY_AGE "${SDL_MINOR_VERSION} * 100 + ${SDL_MICRO_VERSION}")
if(SDL_MINOR_VERSION MATCHES "[02468]$")
# Stable branch, 2.24.1 -> libSDL2-2.0.so.0.2400.1
set(SDL_INTERFACE_AGE ${SDL_MICRO_VERSION})
else()
# Development branch, 2.23.1 -> libSDL2-2.0.so.0.2301.0
set(SDL_INTERFACE_AGE 0)
endif()
# Increment this if there is an incompatible change - but if that happens,
# we should rename the library from SDL2 to SDL3, at which point this would
# reset to 0 anyway.
set(LT_MAJOR "0")
math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
math(EXPR LT_MAJOR "${LT_CURRENT}- ${LT_AGE}")
math(EXPR LT_CURRENT "${LT_MAJOR} + ${LT_AGE}")
set(LT_REVISION "${SDL_INTERFACE_AGE}")
# For historical reasons, the library name redundantly includes the major
# version twice: libSDL2-2.0.so.0.
@ -85,6 +93,16 @@ set(LT_REVISION "${SDL_INTERFACE_AGE}")
set(LT_RELEASE "2.0")
set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
# The following should match the versions in the Xcode project file.
# Each version is 1 higher than you might expect, for compatibility
# with libtool: macOS ABI versioning is 1-based, unlike other platforms
# which are normally 0-based.
math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${LT_MAJOR} + ${LT_AGE} + 1")
math(EXPR DYLIB_CURRENT_VERSION_MINOR "${LT_REVISION}")
math(EXPR DYLIB_COMPAT_VERSION_MAJOR "${LT_MAJOR} + 1")
set(DYLIB_CURRENT_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.${DYLIB_CURRENT_VERSION_MINOR}.0")
set(DYLIB_COMPATIBILITY_VERSION "${DYLIB_COMPAT_VERSION_MAJOR}.0.0")
#message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
# General settings & flags

View File

@ -9208,7 +9208,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEPLOYMENT_POSTPROCESSING = YES;
DYLIB_COMPATIBILITY_VERSION = 1.0.0;
DYLIB_CURRENT_VERSION = 24.0.0;
DYLIB_CURRENT_VERSION = 2301.0.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_ALTIVEC_EXTENSIONS = YES;
@ -9292,7 +9292,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_COMPATIBILITY_VERSION = 1.0.0;
DYLIB_CURRENT_VERSION = 24.0.0;
DYLIB_CURRENT_VERSION = 2301.0.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;

View File

@ -14,10 +14,17 @@ dnl Set various version strings - taken gratefully from the GTk sources
SDL_MAJOR_VERSION=2
SDL_MINOR_VERSION=23
SDL_MICRO_VERSION=0
SDL_INTERFACE_AGE=0
SDL_BINARY_AGE=23
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION
SDL_BINARY_AGE=`expr $SDL_MINOR_VERSION \* 100 + $SDL_MICRO_VERSION`
AS_CASE(["$SDL_MINOR_VERSION"],
[*[02468]],
dnl Stable branch, 2.24.1 -> libSDL2-2.0.so.0.2400.1
[SDL_INTERFACE_AGE="$SDL_MICRO_VERSION"],
[*],
dnl Development branch, 2.23.1 -> libSDL2-2.0.so.0.2301.0
[SDL_INTERFACE_AGE=0])
AC_SUBST(SDL_MAJOR_VERSION)
AC_SUBST(SDL_MINOR_VERSION)
AC_SUBST(SDL_MICRO_VERSION)
@ -33,9 +40,13 @@ LT_LANG([Windows Resource])
# version twice: libSDL2-2.0.so.0.
# TODO: in SDL 3, stop using -release, which will simplify it to libSDL3.so.0
LT_RELEASE=2.0
LT_CURRENT=`expr $SDL_MINOR_VERSION - $SDL_INTERFACE_AGE`
LT_REVISION=$SDL_INTERFACE_AGE
# Increment this if there is an incompatible change - but if that happens,
# we should rename the library from SDL2 to SDL3, at which point this would
# reset to 0 anyway.
LT_MAJOR=0
LT_AGE=`expr $SDL_BINARY_AGE - $SDL_INTERFACE_AGE`
LT_CURRENT=`expr $LT_MAJOR + $LT_AGE`
LT_REVISION=$SDL_INTERFACE_AGE
m4_pattern_allow([^LT_])
AC_SUBST(LT_RELEASE)

View File

@ -17,14 +17,10 @@
* Bump ABI version information
* `configure.ac`: `CMakeLists.txt`: `SDL_INTERFACE_AGE`, `SDL_BINARY_AGE`
* `SDL_BINARY_AGE += 1`
* set `SDL_INTERFACE_AGE` to 0
* if backwards compatibility has been broken,
set both `SDL_BINARY_AGE` and `SDL_INTERFACE_AGE` to 0
* `Xcode/SDL/SDL.xcodeproj/project.pbxproj`: `DYLIB_CURRENT_VERSION`,
`DYLIB_COMPATIBILITY_VERSION`
* increment first number in `DYLIB_CURRENT_VERSION`
* `CMakeLists.txt`, `Xcode/SDL/SDL.xcodeproj/project.pbxproj`:
`DYLIB_CURRENT_VERSION`, `DYLIB_COMPATIBILITY_VERSION`
* set first number in `DYLIB_CURRENT_VERSION` to
(100 * *minor*) + 1
* set second number in `DYLIB_CURRENT_VERSION` to 0
* if backwards compatibility has been broken,
increase `DYLIB_COMPATIBILITY_VERSION` (?)
@ -45,12 +41,9 @@
* Bump ABI version information
* `configure.ac`: `CMakeLists.txt`: `SDL_INTERFACE_AGE`, `SDL_BINARY_AGE`
* `SDL_INTERFACE_AGE += 1`
* `SDL_BINARY_AGE += 1`
* `Xcode/SDL/SDL.xcodeproj/project.pbxproj`: `DYLIB_CURRENT_VERSION`,
`DYLIB_COMPATIBILITY_VERSION`
* increment second number in `DYLIB_CURRENT_VERSION`
* `CMakeLists.txt`, `Xcode/SDL/SDL.xcodeproj/project.pbxproj`:
`DYLIB_CURRENT_VERSION`, `DYLIB_COMPATIBILITY_VERSION`
* set second number in `DYLIB_CURRENT_VERSION` to *patchlevel*
* Regenerate `configure`
@ -77,8 +70,13 @@
* Bump ABI version information
* Same places as listed above
* Assume that the next feature release will contain new API/ABI
* `CMakeLists.txt`, `Xcode/SDL/SDL.xcodeproj/project.pbxproj`:
`DYLIB_CURRENT_VERSION`, `DYLIB_COMPATIBILITY_VERSION`
* set first number in `DYLIB_CURRENT_VERSION` to
(100 * *minor*) + *patchlevel* + 1
* set second number in `DYLIB_CURRENT_VERSION` to 0
* if backwards compatibility has been broken,
increase `DYLIB_COMPATIBILITY_VERSION` (?)
* Regenerate `configure`

View File

@ -80,13 +80,8 @@ SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_min, SDL_MINOR_VERSION >= 0);
SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_max, SDL_MINOR_VERSION <= 255);
SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_min, SDL_PATCHLEVEL >= 0);
#if SDL_MAJOR_VERSION < 3
/* Limited by its encoding in SDL_VERSIONNUM */
/* Limited by its encoding in SDL_VERSIONNUM and in the ABI versions */
SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_max, SDL_PATCHLEVEL <= 99);
#else
/* Limited only by the need to fit in SDL_version */
SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_max, SDL_PATCHLEVEL <= 255);
#endif
/* This is not declared in any header, although it is shared between some
parts of SDL, because we don't want anything calling it without an