]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix SOVERSION computation logic in CMake to match libtool's (#1976)
authorjaimergp <jaimergp@users.noreply.github.com>
Fri, 13 Sep 2024 19:24:48 +0000 (21:24 +0200)
committerGitHub <noreply@github.com>
Fri, 13 Sep 2024 19:24:48 +0000 (21:24 +0200)
Fix SOVERSION computation logic in CMake to match libtool's

Closes #1857

Co-authored-by: isuruf <isuruf@users.noreply.github.com>
Co-authored-by: Timothy Lyanguzov <theta682@gmail.com>
CMakeLists.txt
libarchive/CMakeLists.txt

index 70d0db43e375db2fa7c315313bcbc78281120921..a24e1dcfdec59bd4ac46112060cce6365f2c3507 100644 (file)
@@ -1,5 +1,9 @@
 #
 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
+if(APPLE AND CMAKE_VERSION VERSION_LESS "3.17.0")
+  message(WARNING "CMake>=3.17.0 required to make the generated shared library have the same Mach-O headers as autotools")
+endif()
+
 if(POLICY CMP0065)
   cmake_policy(SET CMP0065 NEW) #3.4 don't use `-rdynamic` with executables
 endif()
@@ -83,9 +87,21 @@ SET(LIBARCHIVE_VERSION_STRING  "${VERSION}")
 # libarchive 3.1 == interface version 13
 math(EXPR INTERFACE_VERSION  "13 + ${_minor}")
 
-# Set SOVERSION == Interface version
-# ?? Should there be more here ??
-SET(SOVERSION "${INTERFACE_VERSION}")
+# Set SOVERSION so it matches libtool's conventions
+# libtool accepts a string "current:revision:age"; in libarchive, that's set to
+# - current: ${INTERFACE_VERSION} = 13 + ${_minor}
+# - revision: ${_revision}
+# - age: ${_minor}
+# Since libtool computes SOVERSION as "current - age", it's just '13' again
+math(EXPR SOVERSION "${INTERFACE_VERSION} - ${_minor}")
+set(SOVERSION_FULL "${SOVERSION}.${_trimmed_minor}.${_trimmed_revision}")
+
+# Override CMake's default shared library versioning scheme, which uses SOVERSION and VERSION,
+# to match libtool's conventions (see https://github.com/mesonbuild/meson/issues/1451)
+# - compatibility version: current + 1 = ${INTERFACE_VERSION} + 1
+# - current version: ${current + 1}.${revision}
+math(EXPR MACHO_COMPATIBILITY_VERSION "${INTERFACE_VERSION} + 1")
+set(MACHO_CURRENT_VERSION "${MACHO_COMPATIBILITY_VERSION}.${_revision}")
 
 # Enable CMAKE_PUSH_CHECK_STATE() and CMAKE_POP_CHECK_STATE() macros
 # saving and restoring the state of the variables.
index b79091cac582b99f987a43075ffc8bdfd9664457..dd0b2808d9c88a1e0ca86da061397f3b6e577d0c 100644 (file)
@@ -247,7 +247,11 @@ IF(BUILD_SHARED_LIBS)
   ADD_LIBRARY(archive SHARED ${libarchive_SOURCES} ${include_HEADERS})
   TARGET_INCLUDE_DIRECTORIES(archive PUBLIC .)
   TARGET_LINK_LIBRARIES(archive ${ADDITIONAL_LIBS})
-  SET_TARGET_PROPERTIES(archive PROPERTIES SOVERSION ${SOVERSION})
+  SET_TARGET_PROPERTIES(archive PROPERTIES 
+                        VERSION ${SOVERSION_FULL}
+                        SOVERSION ${SOVERSION}
+                        MACHO_COMPATIBILITY_VERSION ${MACHO_COMPATIBILITY_VERSION}
+                        MACHO_CURRENT_VERSION ${MACHO_CURRENT_VERSION})
 ENDIF(BUILD_SHARED_LIBS)
 
 # archive_static is a static library