cmake: detect linker support

check the linker support of `--version-script` and `--exclude-libs`
flags. and use them only if they are supported.

llvm-ld does not support `--version-script` at this moment. and it's
reported that old versions of llvm-ld do not support `--exclude-libs`
as well.

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2019-10-08 16:04:45 +08:00
parent d4872ce97a
commit a826efc52f
4 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,2 @@
int main()
{}

View File

@ -0,0 +1 @@
{};

View File

@ -124,3 +124,14 @@ int main(int argc, char **argv)
else(CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)
message(STATUS "Assuming unaligned access is supported")
endif(CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)
# should use LINK_OPTIONS instead of LINK_LIBRARIES, if we can use cmake v3.14+
try_compile(HAVE_LINK_VERSION_SCRIPT
${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_LIST_DIR}/CephCheck_link.c
LINK_LIBRARIES "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/CephCheck_link.map")
try_compile(HAVE_LINK_EXCLUDE_LIBS
${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_LIST_DIR}/CephCheck_link.c
LINK_LIBRARIES "-Wl,--exclude-libs,ALL")

View File

@ -16,9 +16,11 @@ if(ENABLE_SHARED)
VERSION 2.0.0
SOVERSION 2
VISIBILITY_INLINES_HIDDEN ON)
if(NOT APPLE)
if(HAVE_LINK_EXCLUDE_LIBS)
set_property(TARGET librados APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--exclude-libs,ALL")
endif()
if(HAVE_LINK_VERSION_SCRIPT)
set_property(TARGET librados APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/librados.map")
endif()