From 231bdfb762016ed4448b764d6a677afa15f0c02c Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 22 Jul 2022 10:50:31 -0700 Subject: [PATCH] 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 --- CMakeLists.txt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1b120bd..702e5c9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,11 @@ # in the file PATENTS. All contributing project authors may # 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) 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} SOVERSION ${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() set_version(Makefile.am webp webp) set_version(Makefile.am webpdecoder webpdecoder)