Skip to content

Commit f30c748

Browse files
Merge #1270: cmake: Fix library ABI versioning
bef448f cmake: Fix library ABI versioning (Hennadii Stepanov) Pull request description: This change emulates Libtool to make sure Libtool and CMake agree on the ABI version. To test, one needs to simulate a release with backward-compatible API changes, which means the following changes in `configure.ac` and `CMakeLists.txt`: - incrementing of `*_LIB_VERSION_CURRENT` - setting `*_LIB_VERSION_REVISION` to zero - incrementing of `*_LIB_VERSION_AGE` ACKs for top commit: real-or-random: ACK bef448f diff looks good and I tested on Linux Tree-SHA512: f7551fc7377ea50c8bc32d14108a034a1f91ebbb63d5fec562e5cc28416637834b9a4dcba3692df1780adcd1212ad4f238dc0219ab5add68bd88a5a458572ee5
2 parents 3c81838 + bef448f commit f30c748

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/CMakeLists.txt

+36-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,44 @@ target_include_directories(secp256k1 INTERFACE
3636
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${PROJECT_IS_TOP_LEVEL}>>:${PROJECT_SOURCE_DIR}/include>>
3737
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
3838
)
39+
40+
# This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
41+
# see below "Calculate the version variables" in build-aux/ltmain.sh.
42+
math(EXPR ${PROJECT_NAME}_soversion "${${PROJECT_NAME}_LIB_VERSION_CURRENT} - ${${PROJECT_NAME}_LIB_VERSION_AGE}")
3943
set_target_properties(secp256k1 PROPERTIES
40-
VERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION}"
41-
SOVERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}"
44+
SOVERSION ${${PROJECT_NAME}_soversion}
4245
)
46+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
47+
set_target_properties(secp256k1 PROPERTIES
48+
VERSION ${${PROJECT_NAME}_soversion}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
49+
)
50+
elseif(APPLE)
51+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
52+
math(EXPR ${PROJECT_NAME}_compatibility_version "${${PROJECT_NAME}_LIB_VERSION_CURRENT} + 1")
53+
set_target_properties(secp256k1 PROPERTIES
54+
MACHO_COMPATIBILITY_VERSION ${${PROJECT_NAME}_compatibility_version}
55+
MACHO_CURRENT_VERSION ${${PROJECT_NAME}_compatibility_version}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
56+
)
57+
unset(${PROJECT_NAME}_compatibility_version)
58+
elseif(BUILD_SHARED_LIBS)
59+
message(WARNING
60+
"The 'compatibility version' and 'current version' values of the DYLIB "
61+
"will diverge from the values set by the GNU Libtool. To ensure "
62+
"compatibility, it is recommended to upgrade CMake to at least version 3.17."
63+
)
64+
endif()
65+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
66+
set(${PROJECT_NAME}_windows "secp256k1")
67+
if(MSVC)
68+
set(${PROJECT_NAME}_windows "${PROJECT_NAME}")
69+
endif()
70+
set_target_properties(secp256k1 PROPERTIES
71+
ARCHIVE_OUTPUT_NAME "${${PROJECT_NAME}_windows}"
72+
RUNTIME_OUTPUT_NAME "${${PROJECT_NAME}_windows}-${${PROJECT_NAME}_soversion}"
73+
)
74+
unset(${PROJECT_NAME}_windows)
75+
endif()
76+
unset(${PROJECT_NAME}_soversion)
4377

4478
if(SECP256K1_BUILD_BENCHMARK)
4579
add_executable(bench bench.c)

0 commit comments

Comments
 (0)