History

Fix CMake generated shared library ABI compliance, closes #116

Use version script to export correct ABI set with CMake. This change is related to Unix shared library builds only (GNUC, Clang and Intel Compilers).

evpobr committed 6 years ago

Commit 144174d1 parent 260c3f62 files · +28 −1Browse files

Unified · Split

2 files
  1. CMakeLists.txt +26 −1
  2. NEWS +2 −0
CMakeLists.txt+26−1
@@ -165,11 +165,36 @@ endif() · 164 unmodified lines
165165 # Set public header
166166 set_property(TARGET samplerate PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/src/samplerate.h)
167167
168−# Set ABI version. This is critical for Unix-like OSes
169168 if(BUILD_SHARED_LIBS)
169+ # Set ABI version. This is critical for Unix-like OSes
170170 set_target_properties(samplerate PROPERTIES
171171 VERSION ${libsamplerate_VERSION}
172172 SOVERSION ${libsamplerate_VERSION_MAJOR})
173+
174+ # Use Version_script to export ABI set
175+ if(UNIX AND (NOT APPLE))
176+ if((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR
177+ (CMAKE_C_COMPILER_ID STREQUAL "Clang") OR
178+ (CMAKE_C_COMPILER_ID STREQUAL "Intel"))
179+
180+ set(PACKAGE ${PROJECT_NAME})
181+ configure_file(src/Version_script.in src/Version_script)
182+ unset(PACKAGE)
183+
184+ if(CMAKE_VERSION VERSION_LESS 3.13)
185+ # This works
186+ set_property(TARGET samplerate APPEND_STRING PROPERTY
187+ LINK_FLAGS "-Wl,--version-script,${PROJECT_BINARY_DIR}/src/Version_script")
188+ else()
189+ # This works even better, e.g. for Clang it uses `-Xlinker` option,
190+ # but requires CMake >= 3.13.
191+ target_link_options(samplerate
192+ PRIVATE
193+ "LINKER:--version-script,${PROJECT_BINARY_DIR}/src/Version_script")
194+ endif()
195+
196+ endif()
197+ endif()
173198 endif()
174199
175200 # Tests
NEWS+2−0
@@ -1,5 +1,7 @@
11 Unreleased
22
3+ * CMake:
4+ * Fix CMake generated shared library ABI compliance with Autotools build
35 * Documentation:
46 * Move site to new URL: http://libsndfile.github.io/libsamplerate/
57 * Convert documentation pages from HTML to Markdown

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t