cmake, refactor: Introduce `SetLibtoolAbiVersion` module
What changed, and why it matters
This commit is a straightforward cleanup of the build system. It moves existing logic for setting shared-library version numbers into a reusable CMake helper module, without changing the actual version-numbering behavior. There is no security-relevant change.
No security action needed. Treat as normal build-system refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors CMake build configuration by extracting the Libtool-compatible ABI version calculation into a new function set_libtool_abi_version() in cmake/SetLibtoolAbiVersion.cmake. The same formulas and platform-specific branches (Linux/FreeBSD VERSION, Apple MACHO compatibility/current, Windows output names) are preserved; only the variable scoping and code organization changed. No source code, cryptographic logic, or runtime behavior is modified.
Changed components
cmake/SetLibtoolAbiVersion.cmakesrc/CMakeLists.txtInspect captured patch +33 / −28
diff --git a/cmake/SetLibtoolAbiVersion.cmake b/cmake/SetLibtoolAbiVersion.cmake
new file mode 100644
index 0000000..6ae19d3
--- /dev/null
+++ b/cmake/SetLibtoolAbiVersion.cmake
@@ -0,0 +1,28 @@
+# This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
+# see below "Calculate the version variables" in autotools-aux/ltmain.sh.
+function(set_libtool_abi_version target current revision age)
+ math(EXPR _soversion "${current} - ${age}")
+ set_target_properties(${target} PROPERTIES
+ SOVERSION ${_soversion}
+ )
+ if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|FreeBSD)$")
+ set_target_properties(${target} PROPERTIES
+ VERSION ${_soversion}.${age}.${revision}
+ )
+ elseif(APPLE)
+ math(EXPR _compatibility "${current} + 1")
+ set_target_properties(${target} PROPERTIES
+ MACHO_COMPATIBILITY_VERSION ${_compatibility}
+ MACHO_CURRENT_VERSION ${_compatibility}.${revision}
+ )
+ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ set(_windows_name "secp256k1")
+ if(MSVC)
+ set(_windows_name "${PROJECT_NAME}")
+ endif()
+ set_target_properties(${target} PROPERTIES
+ ARCHIVE_OUTPUT_NAME "${_windows_name}"
+ RUNTIME_OUTPUT_NAME "${_windows_name}-${_soversion}"
+ )
+ endif()
+endfunction()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 322f198..a45eeb9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -94,35 +94,12 @@ set_target_properties(secp256k1_objs PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:secp256k1,INTERFACE_INCLUDE_DIRECTORIES>"
)
-# This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
-# see below "Calculate the version variables" in autotools-aux/ltmain.sh.
-math(EXPR ${PROJECT_NAME}_soversion "${${PROJECT_NAME}_LIB_VERSION_CURRENT} - ${${PROJECT_NAME}_LIB_VERSION_AGE}")
-set_target_properties(secp256k1 PROPERTIES
- SOVERSION ${${PROJECT_NAME}_soversion}
+include(SetLibtoolAbiVersion)
+set_libtool_abi_version(secp256k1
+ ${${PROJECT_NAME}_LIB_VERSION_CURRENT}
+ ${${PROJECT_NAME}_LIB_VERSION_REVISION}
+ ${${PROJECT_NAME}_LIB_VERSION_AGE}
)
-if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|FreeBSD)$")
- set_target_properties(secp256k1 PROPERTIES
- VERSION ${${PROJECT_NAME}_soversion}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
- )
-elseif(APPLE)
- math(EXPR ${PROJECT_NAME}_compatibility_version "${${PROJECT_NAME}_LIB_VERSION_CURRENT} + 1")
- set_target_properties(secp256k1 PROPERTIES
- MACHO_COMPATIBILITY_VERSION ${${PROJECT_NAME}_compatibility_version}
- MACHO_CURRENT_VERSION ${${PROJECT_NAME}_compatibility_version}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
- )
- unset(${PROJECT_NAME}_compatibility_version)
-elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set(${PROJECT_NAME}_windows "secp256k1")
- if(MSVC)
- set(${PROJECT_NAME}_windows "${PROJECT_NAME}")
- endif()
- set_target_properties(secp256k1 PROPERTIES
- ARCHIVE_OUTPUT_NAME "${${PROJECT_NAME}_windows}"
- RUNTIME_OUTPUT_NAME "${${PROJECT_NAME}_windows}-${${PROJECT_NAME}_soversion}"
- )
- unset(${PROJECT_NAME}_windows)
-endif()
-unset(${PROJECT_NAME}_soversion)
if(SECP256K1_BUILD_BENCHMARK)
add_executable(bench bench.c)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.