Blame 0001-cmake-Allow-shared-libraries-to-customize-the-soname.patch

68ca04b
From 3dc5722d5c7673a879f2b4680369d3ac8b6b64b6 Mon Sep 17 00:00:00 2001
68ca04b
From: Tom Stellard <tstellar@redhat.com>
68ca04b
Date: Wed, 4 Aug 2021 14:05:38 -0700
68ca04b
Subject: [PATCH] cmake: Allow shared libraries to customize the soname using
68ca04b
 LLVM_ABI_REVISION
68ca04b
68ca04b
The LLVM_ABI_REVISION variable is intended to be used for release
68ca04b
candidates which introduce an ABI change to a shared library.  This
68ca04b
variable can be specified per library, so there is not one global value
68ca04b
for all of LLVM.
68ca04b
68ca04b
For example, if we LLVM X.0.0-rc2 introduces an ABI change for a library
68ca04b
compared with LLVM X.0.0-rc1, then the LLVM_ABI_REVISION number for
68ca04b
library will be incremented by 1.
68ca04b
68ca04b
In the main branch, LLVM_ABI_REVISION should always be 0, it is only
68ca04b
meant to be used in the release branch.
68ca04b
68ca04b
Differential Revision: https://reviews.llvm.org/D105594
68ca04b
---
68ca04b
 llvm/cmake/modules/AddLLVM.cmake       | 7 +++++--
68ca04b
 llvm/tools/llvm-shlib/CMakeLists.txt   | 9 +++++++++
68ca04b
 3 files changed, 19 insertions(+), 2 deletions(-)
68ca04b
68ca04b
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
68ca04b
index 3e009f5061d3..a09405a1be3e 100644
68ca04b
--- a/llvm/cmake/modules/AddLLVM.cmake
68ca04b
+++ b/llvm/cmake/modules/AddLLVM.cmake
68ca04b
@@ -586,11 +586,14 @@ function(llvm_add_library name)
68ca04b
     # Set SOVERSION on shared libraries that lack explicit SONAME
68ca04b
     # specifier, on *nix systems that are not Darwin.
68ca04b
     if(UNIX AND NOT APPLE AND NOT ARG_SONAME)
68ca04b
+      if (NOT LLVM_ABI_REVISION)
68ca04b
+        set(LLVM_ABI_REVISION 0)
68ca04b
+      endif()
68ca04b
       set_target_properties(${name}
68ca04b
         PROPERTIES
68ca04b
         # Since 4.0.0, the ABI version is indicated by the major version
68ca04b
-        SOVERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}
68ca04b
-        VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX})
68ca04b
+	SOVERSION ${LLVM_VERSION_MAJOR}.${LLVM_ABI_REVISION}
68ca04b
+	VERSION ${LLVM_VERSION_MAJOR}.${LLVM_ABI_REVISION})
68ca04b
     endif()
68ca04b
   endif()
68ca04b
 
68ca04b
diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt
68ca04b
index 76b9a25cbbcd..b876e7fed6b5 100644
68ca04b
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
68ca04b
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
68ca04b
@@ -2,6 +2,11 @@
68ca04b
 # library is enabled by setting LLVM_BUILD_LLVM_DYLIB=yes on the CMake
68ca04b
 # commandline. By default the shared library only exports the LLVM C API.
68ca04b
 
68ca04b
+# In the main branch, LLVM_ABI_REVISION should always be 0.  In the release
68ca04b
+# branches, this should be incremented before each release candidate every
68ca04b
+# time the ABI of libLLVM.so changes.
68ca04b
+set(LLVM_ABI_REVISION 0 CACHE STRING "ABI Revision number for SONAMEs (default: 0)")
68ca04b
+
68ca04b
 set(SOURCES
68ca04b
   libllvm.cpp
68ca04b
   )
68ca04b
@@ -67,6 +72,10 @@ if(LLVM_BUILD_LLVM_DYLIB)
68ca04b
     set_property(TARGET LLVM APPEND_STRING PROPERTY
68ca04b
                 LINK_FLAGS
68ca04b
                 " -compatibility_version 1 -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
68ca04b
+  else()
68ca04b
+    set_target_properties(LLVM
68ca04b
+      PROPERTIES
68ca04b
+      SOVERSION ${LLVM_ABI_REVISION})
68ca04b
   endif()
68ca04b
 
68ca04b
   if(TARGET libLLVMExports)
68ca04b
-- 
68ca04b
2.27.0
68ca04b