diff options
author | Anderson Toshiyuki Sasaki <ansasaki@redhat.com> | 2018-05-14 15:55:06 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-08-08 20:58:23 +0200 |
commit | efc427fdce8a2c54e60bc2ca0c9e13f8ac008ead (patch) | |
tree | 5f65f5e6a9578c246d4636ed9aa98783951a9b8d /src/CMakeLists.txt | |
parent | 0f64bc78a8f11d32da3e4d7e9ddd466cdbccd0b5 (diff) | |
download | libssh-efc427fdce8a2c54e60bc2ca0c9e13f8ac008ead.tar.gz libssh-efc427fdce8a2c54e60bc2ca0c9e13f8ac008ead.tar.xz libssh-efc427fdce8a2c54e60bc2ca0c9e13f8ac008ead.zip |
cmake: Introduce symbol versioning
This adds a cmake module, FindABIMap, which looks for abimap and
provides functions to generate a symbol version linker script.
The module can be included using find_package(ABIMap).
This also adds the option to compile with symbol versioning. The symbol
list is obtained from the header files by filtering those marked with
the LIBSSH_API modifier.
Such symbols are used as input to generate the version script used by
the linker. The version script is automatically updated as new symbols
marked with LIBSSH_API are added to the header files.
If any symbol is removed, the build will fail due to break in the ABI.
Symbol versioning is enabled by default if abimap has been found. It is
disabled in non-UNIX platforms. It can be disabled by passing
"-DWITH_SYMBOL_VERSIONING=OFF" option to cmake.
Pair-Programmed-With: Andreas Schneider <asn@cryptomilk.org>
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/CMakeLists.txt')
-rw-r--r-- | src/CMakeLists.txt | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6cf44158..e5746b15 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,3 @@ -project(libssh-library C) - set(LIBSSH_PUBLIC_INCLUDE_DIRS ${libssh_SOURCE_DIR}/include CACHE INTERNAL "libssh public include directories" @@ -265,10 +263,52 @@ include_directories( ${LIBSSH_PRIVATE_INCLUDE_DIRS} ) +# Set the path to the default map file +set(MAP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.map") + +if (WITH_SYMBOL_VERSIONING AND ABIMAP_FOUND) + # Get the list of header files + get_file_list("dev_header_list" + DIRECTORIES "${LIBSSH_PUBLIC_INCLUDE_DIRS}/libssh" + FILES_PATTERNS "*.h") + + # Extract the symbols marked as "LIBSSH_API" from the header files + extract_symbols("${PROJECT_NAME}_dev.symbols" + HEADERS_LIST_FILE "dev_header_list" + FILTER_PATTERN "LIBSSH_API") + + if (WITH_ABI_BREAK) + set(ALLOW_ABI_BREAK "BREAK_ABI") + endif() + + # Generate the symbol version map file + generate_map_file("${PROJECT_NAME}_dev.map" + SYMBOLS "${PROJECT_NAME}_dev.symbols" + RELEASE_NAME_VERSION ${PROJECT_NAME}_AFTER_${LIBRARY_VERSION} + CURRENT_MAP ${MAP_PATH} + ${ALLOW_ABI_BREAK}) + + set(libssh_SRCS + ${libssh_SRCS} + ${PROJECT_NAME}_dev.map + ) +endif (WITH_SYMBOL_VERSIONING AND ABIMAP_FOUND) + add_library(${LIBSSH_SHARED_LIBRARY} SHARED ${libssh_SRCS}) target_link_libraries(${LIBSSH_SHARED_LIBRARY} ${LIBSSH_LINK_LIBRARIES}) +if (WITH_SYMBOL_VERSIONING) + if (ABIMAP_FOUND) + # Change path to devel map file + set(MAP_PATH "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_dev.map") + endif (ABIMAP_FOUND) + + set_target_properties(${LIBSSH_SHARED_LIBRARY} + PROPERTIES LINK_FLAGS + "-Wl,--version-script,\"${MAP_PATH}\"") +endif (WITH_SYMBOL_VERSIONING) + set_target_properties( ${LIBSSH_SHARED_LIBRARY} PROPERTIES |