]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: detect linker support 30781/head
authorKefu Chai <kchai@redhat.com>
Tue, 8 Oct 2019 08:04:45 +0000 (16:04 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 8 Oct 2019 13:53:03 +0000 (21:53 +0800)
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>
cmake/modules/CephCheck_link.c [new file with mode: 0644]
cmake/modules/CephCheck_link.map [new file with mode: 0644]
cmake/modules/CephChecks.cmake
src/librados/CMakeLists.txt

diff --git a/cmake/modules/CephCheck_link.c b/cmake/modules/CephCheck_link.c
new file mode 100644 (file)
index 0000000..0c87b37
--- /dev/null
@@ -0,0 +1,2 @@
+int main()
+{}
diff --git a/cmake/modules/CephCheck_link.map b/cmake/modules/CephCheck_link.map
new file mode 100644 (file)
index 0000000..333a9b3
--- /dev/null
@@ -0,0 +1 @@
+{};
\ No newline at end of file
index 576971ed2a8770dffbbb497f186341550a7650be..f5a77abc6e6ad10356280238ee82d6708eecdb33 100644 (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")
index 6efed26bd8f765a655cc89547df2c778c5651615..6335d0c597525f0d2ba4948e0be59e1f51470708 100644 (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()