CMake: fix dylib versioning

match the behavior of autoconf in generating the -compatibility_version
and -current_version options. these use current + 1 and revision:
  # Darwin ld doesn't like 0 for these options...
  func_arith $current + 1
  minor_current=$func_arith_result
  ...
  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"

this requires CMake >= 3.17 to set the MACHO_COMPATIBILITY_VERSION and
MACHO_CURRENT_VERSION properties:
https://cmake.org/cmake/help/latest/prop_tgt/MACHO_COMPATIBILITY_VERSION.html

based on the fix in libexpat:
https://github.com/libexpat/libexpat/issues/55

Bug: webp:576
Fixed: webp:576
Change-Id: Ibc3ab99449aa213fc8c2ca3ae06def648c61acbd
This commit is contained in:
James Zern 2022-07-22 10:50:31 -07:00
parent 7366f7f394
commit 231bdfb762

View File

@ -6,7 +6,11 @@
# in the file PATENTS. All contributing project authors may # in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree. # be found in the AUTHORS file in the root of the source tree.
cmake_minimum_required(VERSION 3.7) if(APPLE)
cmake_minimum_required(VERSION 3.17)
else()
cmake_minimum_required(VERSION 3.7)
endif()
if(POLICY CMP0072) if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW) cmake_policy(SET CMP0072 NEW)
@ -396,6 +400,19 @@ macro(set_version FILE TARGET_NAME NAME_IN_MAKEFILE)
${LT_CURRENT_MINUS_AGE}.${LT_AGE}.${LT_REVISION} ${LT_CURRENT_MINUS_AGE}.${LT_AGE}.${LT_REVISION}
SOVERSION SOVERSION
${LT_CURRENT_MINUS_AGE}) ${LT_CURRENT_MINUS_AGE})
if(APPLE)
# For compatibility, set MACHO_COMPATIBILITY_VERSION and
# MACHO_CURRENT_VERSION to match libtool. These properties were introduced
# in 3.17:
# https://cmake.org/cmake/help/latest/prop_tgt/MACHO_COMPATIBILITY_VERSION.html
math(EXPR LIBWEBP_MACHO_COMPATIBILITY_VERSION "${LT_CURRENT} + 1")
set_target_properties(
${TARGET_NAME}
PROPERTIES MACHO_COMPATIBILITY_VERSION
${LIBWEBP_MACHO_COMPATIBILITY_VERSION}
MACHO_CURRENT_VERSION
${LIBWEBP_MACHO_COMPATIBILITY_VERSION}.${LT_REVISION})
endif()
endmacro() endmacro()
set_version(Makefile.am webp webp) set_version(Makefile.am webp webp)
set_version(Makefile.am webpdecoder webpdecoder) set_version(Makefile.am webpdecoder webpdecoder)