SDL_image: Fixed handling of DYLIB_COMPATIBILITY_VERSION

From 310e74f6a83b833be4dfbc1f14974b11452932ea Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Sep 2022 11:54:38 -0700
Subject: [PATCH] Fixed handling of DYLIB_COMPATIBILITY_VERSION

Also make sure we test the version in configure
---
 CMakeLists.txt                            |  3 --
 Xcode/SDL_image.xcodeproj/project.pbxproj |  4 +--
 cmake/PrivateSdlFunctions.cmake           |  1 +
 release_checklist.md                      | 22 ++++++-------
 test-versioning.sh                        | 38 ++++++++++++++++-------
 5 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f1ea7c4..a3f363c4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,9 +8,6 @@ set(MINOR_VERSION 7)
 set(MICRO_VERSION 0)
 set(SDL_REQUIRED_VERSION 2.0.9)
 
-# For historical reasons this is 3.0.0 rather than the expected 1.0.0
-set(DYLIB_COMPATIBILITY_VERSION "3.0.0")
-
 include(PrivateSdlFunctions)
 sdl_calculate_derived_version_variables()
 
diff --git a/Xcode/SDL_image.xcodeproj/project.pbxproj b/Xcode/SDL_image.xcodeproj/project.pbxproj
index 26bd10c6..70513694 100644
--- a/Xcode/SDL_image.xcodeproj/project.pbxproj
+++ b/Xcode/SDL_image.xcodeproj/project.pbxproj
@@ -632,7 +632,7 @@
 			buildSettings = {
 				ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
 				COPY_PHASE_STRIP = NO;
-				DYLIB_COMPATIBILITY_VERSION = 3.0.0;
+				DYLIB_COMPATIBILITY_VERSION = 701.0.0;
 				DYLIB_CURRENT_VERSION = 701.0.0;
 				DYLIB_INSTALL_NAME_BASE = "@rpath";
 				ENABLE_TESTABILITY = YES;
@@ -722,7 +722,7 @@
 			buildSettings = {
 				ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
 				DEPLOYMENT_POSTPROCESSING = YES;
-				DYLIB_COMPATIBILITY_VERSION = 3.0.0;
+				DYLIB_COMPATIBILITY_VERSION = 701.0.0;
 				DYLIB_CURRENT_VERSION = 701.0.0;
 				DYLIB_INSTALL_NAME_BASE = "@rpath";
 				FRAMEWORK_SEARCH_PATHS = "\"$(SRCROOT)/$(PLATFORM)\"";
diff --git a/cmake/PrivateSdlFunctions.cmake b/cmake/PrivateSdlFunctions.cmake
index 7d4dbebe..b5c63379 100644
--- a/cmake/PrivateSdlFunctions.cmake
+++ b/cmake/PrivateSdlFunctions.cmake
@@ -41,6 +41,7 @@ macro(sdl_calculate_derived_version_variables)
     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_CURRENT_VERSION_MAJOR}.0.0")
 endmacro()
 
 macro(sdl_find_sdl2 TARGET VERSION)
diff --git a/release_checklist.md b/release_checklist.md
index 84e7e73a..e4b62d47 100644
--- a/release_checklist.md
+++ b/release_checklist.md
@@ -28,16 +28,12 @@
         * 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` (?)
-	* `CMakeLists.txt`:
-		* if backwards compatibility has been broken,
-		  increase `DYLIB_COMPATIBILITY_VERSION` (?)
-
-* Run `./test-versioning.sh` to verify that everything is consistent
+        * set `DYLIB_COMPATIBILITY_VERSION` to the same value
 
 * Regenerate `configure`
 
+* Run `./test-versioning.sh` to verify that everything is consistent
+
 * Do the release
 
 ## New bugfix release
@@ -55,11 +51,12 @@
     * `Xcode/SDL_image.xcodeproj/project.pbxproj`:
         `DYLIB_CURRENT_VERSION`, `DYLIB_COMPATIBILITY_VERSION`
         * set second number in `DYLIB_CURRENT_VERSION` to *patchlevel*
-
-* Run test/versioning.sh to verify that everything is consistent
+        * Leave `DYLIB_COMPATIBILITY_VERSION` unchanged
 
 * Regenerate `configure`
 
+* Run test/versioning.sh to verify that everything is consistent
+
 * Do the release
 
 ## After a feature release
@@ -92,11 +89,10 @@
         * 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` (?)
-
-* Run test/versioning.sh to verify that everything is consistent
+        * set `DYLIB_COMPATIBILITY_VERSION` to the same value
 
 * Regenerate `configure`
 
+* Run test/versioning.sh to verify that everything is consistent
+
 * Do the release
diff --git a/test-versioning.sh b/test-versioning.sh
index eaff5947..cf1e59f7 100755
--- a/test-versioning.sh
+++ b/test-versioning.sh
@@ -39,6 +39,17 @@ else
     not_ok "configure.ac $version disagrees with SDL_image.h $ref_version"
 fi
 
+major=$(sed -ne 's/^MAJOR_VERSION=//p' configure)
+minor=$(sed -ne 's/^MINOR_VERSION=//p' configure)
+micro=$(sed -ne 's/^MICRO_VERSION=//p' configure)
+version="${major}.${minor}.${micro}"
+
+if [ "$ref_version" = "$version" ]; then
+    ok "configure $version"
+else
+    not_ok "configure $version disagrees with SDL_image.h $ref_version"
+fi
+
 major=$(sed -ne 's/^set(MAJOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
 minor=$(sed -ne 's/^set(MINOR_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
 micro=$(sed -ne 's/^set(MICRO_VERSION \([0-9]*\))$/\1/p' CMakeLists.txt)
@@ -122,22 +133,25 @@ fi
 
 # For simplicity this assumes we'll never break ABI before SDL 3.
 dylib_compat=$(sed -Ene 's/.*DYLIB_COMPATIBILITY_VERSION = (.*);$/\1/p' Xcode/SDL_image.xcodeproj/project.pbxproj)
-ref='3.0.0
-3.0.0'
 
-if [ "$ref" = "$dylib_compat" ]; then
-    ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is consistent"
-else
-    not_ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is inconsistent"
-fi
+case "$ref_minor" in
+    (*[02468])
+        major="$(( ref_minor * 100 + 1 ))"
+        minor="0"
+        ;;
+    (*)
+        major="$(( ref_minor * 100 + ref_micro + 1 ))"
+        minor="0"
+        ;;
+esac
 
-dylib_compat=$(sed -ne 's/^set(DYLIB_COMPATIBILITY_VERSION "\([0-9.]*\)")$/\1/p' CMakeLists.txt)
-ref='3.0.0'
+ref="${major}.${minor}.0
+${major}.${minor}.0"
 
 if [ "$ref" = "$dylib_compat" ]; then
-    ok "CMakeLists.txt DYLIB_COMPATIBILITY_VERSION is consistent"
+    ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is consistent"
 else
-    not_ok "CMakeLists.txt DYLIB_COMPATIBILITY_VERSION is inconsistent"
+    not_ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is inconsistent, expected $ref, got $dylib_compat"
 fi
 
 dylib_cur=$(sed -Ene 's/.*DYLIB_CURRENT_VERSION = (.*);$/\1/p' Xcode/SDL_image.xcodeproj/project.pbxproj)
@@ -159,7 +173,7 @@ ${major}.${minor}.0"
 if [ "$ref" = "$dylib_cur" ]; then
     ok "project.pbxproj DYLIB_CURRENT_VERSION is consistent"
 else
-    not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent, expected $ref"
+    not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent, expected $ref, got $dylib_cur"
 fi
 
 sdl_req=$(sed -ne 's/\$sdl2_version = "\([0-9.]*\)"$/\1/p' .github/fetch_sdl_vc.ps1)