Blob Blame History Raw
From 144bf56aa281390aad13558fe11e190e507ca17c Mon Sep 17 00:00:00 2001
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
Date: Fri, 27 Oct 2023 12:56:58 -0400
Subject: [PATCH] Downstream-only: add an SONAME version
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Upstream was asked about .so versioning and setting SONAME properly and
seemed unprepared to handle the request:
https://github.com/PixarAnimationStudios/USD/issues/1259#issuecomment-657120216

A patch was offered:
https://github.com/PixarAnimationStudios/USD/issues/1387
but it was not sufficient for the general case, since (1) it only handled the
monolithic build, and (2) it derived the .so version from PXR_MAJOR_VERSION,
which is *not* reliably bumped on API or ABI changes, and currently is still
zero.

We will therefore probably need to keep doing downstream .so versioning for
the foreseeable future. Currently we are assuming that the ABI is likely to
change on every release (an appropriate assumption for a large C++ project
with no ABI stability policy), so we build the .so version from the project
version. Note that the “hidden” major version is zero, so this complies with
the “0.” prefix recommended in the packaging guidelines.

https://docs.fedoraproject.org/en-US/packaging-guidelines/#_downstream_so_name_versioning

A known defect of this patch is that it causes the hdTiny.so example plugin
to be versioned as well, which is undesired. This is not a serious problem
because we do not want to package the built plugin anyway. (It should not be
built with -DPXR_BUILD_EXAMPLES=OFF, but it is.)
---
 cmake/defaults/Version.cmake | 6 ++++++
 cmake/macros/Private.cmake   | 1 +
 cmake/macros/Public.cmake    | 1 +
 3 files changed, 8 insertions(+)

diff --git a/cmake/defaults/Version.cmake b/cmake/defaults/Version.cmake
index b9516997a..97c9df203 100644
--- a/cmake/defaults/Version.cmake
+++ b/cmake/defaults/Version.cmake
@@ -27,3 +27,9 @@ set(PXR_MINOR_VERSION "24")
 set(PXR_PATCH_VERSION "3") # NOTE: Must not have leading 0 for single digits
 
 math(EXPR PXR_VERSION "${PXR_MAJOR_VERSION} * 10000 + ${PXR_MINOR_VERSION} * 100 + ${PXR_PATCH_VERSION}")
+
+set(PXR_DOWNSTREAM_SOVERSION "${PXR_MAJOR_VERSION}.${PXR_MINOR_VERSION}.${PXR_PATCH_VERSION}"
+    CACHE
+    STRING
+    "Downstream shared object version"
+)
diff --git a/cmake/macros/Private.cmake b/cmake/macros/Private.cmake
index 21606d4d6..4cf8aeeb6 100644
--- a/cmake/macros/Private.cmake
+++ b/cmake/macros/Private.cmake
@@ -1299,6 +1299,7 @@ function(_pxr_library NAME)
             IMPORT_PREFIX "${args_PREFIX}"            
             PREFIX "${args_PREFIX}"
             SUFFIX "${args_SUFFIX}"
+	    SOVERSION ${PXR_DOWNSTREAM_SOVERSION}
     )
 
     target_compile_definitions(${NAME}
diff --git a/cmake/macros/Public.cmake b/cmake/macros/Public.cmake
index 97263d4cd..80abe790c 100644
--- a/cmake/macros/Public.cmake
+++ b/cmake/macros/Public.cmake
@@ -1017,6 +1017,7 @@ function(pxr_toplevel_prologue)
                     FOLDER "${folder}"
                     PREFIX "${libPrefix}"
                     IMPORT_PREFIX "${libPrefix}"
+		    SOVERSION ${PXR_DOWNSTREAM_SOVERSION}
             )
             _get_install_dir("lib" libInstallPrefix)
             install(
-- 
2.43.2