Use matching soname when building with CMake as Makefile (#9178)

This updates the CMake support to additionally symlink the soversion value
to the generated shared library when so generated. This aligns the
generated soversion with that traditionally used by the Makefile build
workflow and provides cross-compatibility irrespective of build approach
used.

The primary version of the non-symlink library retains the actual
(non-SO) project version for clarity and compatibility with
installations built using prior versions of CMake support. An example of
the net resulting symlink structures is shown below, where the most
important aspect is that the symlink matching the embedded SONAME is
present (libprotobuf.so.30 in the example case).

Makefile:

    libprotobuf.so -> libprotobuf.so.30.0.0
    libprotobuf.so.30 -> libprotobuf.so.30.0.0
    libprotobuf.so.30.0.0

CMake:

    libprotobuf.so -> libprotobuf.so.30
    libprotobuf.so.30 -> libprotobuf.so.3.19.0.0
    libprotobuf.so.3.19.0.0

Fixes: #8635
pull/9462/head
Joel Johnson 3 years ago committed by GitHub
parent 7e5bfe8883
commit a9cf69a0ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmake/libprotobuf.cmake
  2. 36
      update_version.py

@ -125,6 +125,8 @@ if(MSVC AND protobuf_BUILD_SHARED_LIBS)
endif()
set_target_properties(libprotobuf PROPERTIES
VERSION ${protobuf_VERSION}
# Use only the first SO version component for compatibility with Makefile emitted SONAME.
SOVERSION 30
OUTPUT_NAME ${LIB_PREFIX}protobuf
DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
add_library(protobuf::libprotobuf ALIAS libprotobuf)

@ -61,6 +61,19 @@ def GetFullVersion(rc_suffix = '-rc-'):
return '%s%s%s' % (NEW_VERSION, rc_suffix, RC_VERSION)
def GetSharedObjectVersion():
protobuf_version_offset = 11
expected_major_version = 3
if NEW_VERSION_INFO[0] != expected_major_version:
print("""[ERROR] Major protobuf version has changed. Please update
update_version.py to readjust the protobuf_version_offset and
expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is
always increasing.
""")
exit(1)
return [NEW_VERSION_INFO[1] + protobuf_version_offset, NEW_VERSION_INFO[2], 0]
def RewriteXml(filename, rewriter, add_xml_prefix=True):
document = minidom.parse(filename)
rewriter(document)
@ -89,6 +102,14 @@ def RewriteTextFile(filename, line_rewriter):
f.close()
def UpdateCMake():
RewriteTextFile('cmake/libprotobuf.cmake',
lambda line : re.sub(
r'SOVERSION [0-9]+\.[0-9]+(\.[0-9]+)?',
'SOVERSION %s' % GetSharedObjectVersion()[0],
line))
def UpdateConfigure():
RewriteTextFile('configure.ac',
lambda line : re.sub(
@ -270,22 +291,10 @@ def UpdateJavaScript():
def UpdateMakefile():
protobuf_version_offset = 11
expected_major_version = 3
if NEW_VERSION_INFO[0] != expected_major_version:
print("""[ERROR] Major protobuf version has changed. Please update
update_version.py to readjust the protobuf_version_offset and
expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is
always increasing.
""")
exit(1)
protobuf_version_info = '%d:%d:0' % (
NEW_VERSION_INFO[1] + protobuf_version_offset, NEW_VERSION_INFO[2])
RewriteTextFile('src/Makefile.am',
lambda line : re.sub(
r'^PROTOBUF_VERSION = .*$',
'PROTOBUF_VERSION = %s' % protobuf_version_info,
'PROTOBUF_VERSION = %s' % ":".join(map(str,GetSharedObjectVersion())),
line))
@ -397,6 +406,7 @@ def UpdateBazel():
line))
UpdateCMake()
UpdateConfigure()
UpdateCsharp()
UpdateCpp()

Loading…
Cancel
Save