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).
Unified · Split
| @@ -165,11 +165,36 @@ endif() · 164 unmodified lines | |||
| 165 | # Set public header | 165 | # Set public header |
| 166 | set_property(TARGET samplerate PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/src/samplerate.h) | 166 | set_property(TARGET samplerate PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/src/samplerate.h) |
| 167 | 167 | ||
| 168 | # Set ABI version. This is critical for Unix-like OSes | ||
| 169 | if(BUILD_SHARED_LIBS) | 168 | if(BUILD_SHARED_LIBS) |
| 169 | # Set ABI version. This is critical for Unix-like OSes | ||
| 170 | set_target_properties(samplerate PROPERTIES | 170 | set_target_properties(samplerate PROPERTIES |
| 171 | VERSION ${libsamplerate_VERSION} | 171 | VERSION ${libsamplerate_VERSION} |
| 172 | SOVERSION ${libsamplerate_VERSION_MAJOR}) | 172 | 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() | ||
| 173 | endif() | 198 | endif() |
| 174 | 199 | ||
| 175 | # Tests | 200 | # Tests |
| @@ -1,5 +1,7 @@ | |||
| 1 | Unreleased | 1 | Unreleased |
| 2 | 2 | ||
| 3 | * CMake: | ||
| 4 | * Fix CMake generated shared library ABI compliance with Autotools build | ||
| 3 | * Documentation: | 5 | * Documentation: |
| 4 | * Move site to new URL: http://libsndfile.github.io/libsamplerate/ | 6 | * Move site to new URL: http://libsndfile.github.io/libsamplerate/ |
| 5 | * Convert documentation pages from HTML to Markdown | 7 | * Convert documentation pages from HTML to Markdown |