SDL: Set DYLIB_COMPATIBILITY_VERSION to DYLIB_CURRENT_VERSION to match autotools

From 4e98ba612b455016aa6d2b084bcb463ba9530b1d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Sep 2022 08:28:06 -0700
Subject: [PATCH] Set DYLIB_COMPATIBILITY_VERSION to DYLIB_CURRENT_VERSION to
 match autotools

Autotools sets both versions to the same value, so Xcode and CMake need to match for the libraries to be compatible between the different builds.

See these for details:
https://github.com/libsdl-org/sdl12-compat/pull/207
https://github.com/libsdl-org/SDL/issues/2934
https://stackoverflow.com/questions/67055770/usage-of-current-version-and-compatibility-version-on-macos
---
 CMakeLists.txt                          |  2 +-
 Xcode/SDL/SDL.xcodeproj/project.pbxproj |  4 ++--
 docs/release_checklist.md               |  3 +--
 test/versioning.sh                      | 17 +++++++----------
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 92aef4f9718..ae388a3e890 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -123,7 +123,7 @@ 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")
+set(DYLIB_COMPATIBILITY_VERSION "${DYLIB_CURRENT_VERSION}")
 
 # This list holds all generated headers.
 # To avoid generating them twice, these are added to a dummy target on which all sdl targets depend.
diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
index 5a30009f2ca..f71afab9ba2 100644
--- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj
+++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
@@ -9436,7 +9436,7 @@
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
 				DEPLOYMENT_POSTPROCESSING = YES;
-				DYLIB_COMPATIBILITY_VERSION = 1.0.0;
+				DYLIB_COMPATIBILITY_VERSION = 2501.0.0;
 				DYLIB_CURRENT_VERSION = 2501.0.0;
 				DYLIB_INSTALL_NAME_BASE = "@rpath";
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -9521,7 +9521,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				DEBUG_INFORMATION_FORMAT = dwarf;
-				DYLIB_COMPATIBILITY_VERSION = 1.0.0;
+				DYLIB_COMPATIBILITY_VERSION = 2501.0.0;
 				DYLIB_CURRENT_VERSION = 2501.0.0;
 				DYLIB_INSTALL_NAME_BASE = "@rpath";
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
diff --git a/docs/release_checklist.md b/docs/release_checklist.md
index 33769949e01..809a5012ec1 100644
--- a/docs/release_checklist.md
+++ b/docs/release_checklist.md
@@ -22,8 +22,7 @@
         * 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` (?)
+        * set `DYLIB_COMPATIBILITY_VERSION` to the same value
 
 * Run test/versioning.sh to verify that everything is consistent
 
diff --git a/test/versioning.sh b/test/versioning.sh
index 893727cf806..f0e8182ab0e 100755
--- a/test/versioning.sh
+++ b/test/versioning.sh
@@ -130,15 +130,6 @@ 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/SDL.xcodeproj/project.pbxproj)
-ref='1.0.0
-1.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
-
 dylib_cur=$(sed -Ene 's/.*DYLIB_CURRENT_VERSION = (.*);$/\1/p' Xcode/SDL/SDL.xcodeproj/project.pbxproj)
 
 case "$ref_minor" in
@@ -155,10 +146,16 @@ esac
 ref="${major}.${minor}.0
 ${major}.${minor}.0"
 
+if [ "$ref" = "$dylib_compat" ]; then
+    ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is consistent"
+else
+    not_ok "project.pbxproj DYLIB_COMPATIBILITY_VERSION is inconsistent, expected $ref, got $dylib_compat"
+fi
+
 if [ "$ref" = "$dylib_cur" ]; then
     ok "project.pbxproj DYLIB_CURRENT_VERSION is consistent"
 else
-    not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent"
+    not_ok "project.pbxproj DYLIB_CURRENT_VERSION is inconsistent, expected $ref, got $dylib_cur"
 fi
 
 echo "1..$tests"