]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: detect librt for POSIX time functions 31543/head
authorKefu Chai <kchai@redhat.com>
Mon, 11 Nov 2019 22:55:40 +0000 (06:55 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 14 Nov 2019 13:26:57 +0000 (21:26 +0800)
per clock_gettime(3),

> On POSIX systems on which these functions are available, the symbol
> _POSIX_TIMERS is defined in <unistd.h> to a value greater than 0.

and

> Most systems require the program be linked with the librt library to
> use these functions.

so, we should detect this symbol and link against librt for using these
functions.

in this change, librt is linked for checking the existence of
clock_gettime(), if it exists. RT_LIBRARY is defined.

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/CephChecks.cmake
src/CMakeLists.txt

index 0f3f9a1d48a8fc78955af119b13547ddf3a4ae00..1a46e88876df52bed25ae2a291b7fbd6d2766d6e 100644 (file)
@@ -67,6 +67,13 @@ CHECK_TYPE_SIZE(__s64 __S64)
 unset(CMAKE_EXTRA_INCLUDE_FILES)
 
 include(CheckSymbolExists)
+cmake_push_check_state(RESET)
+set(CMAKE_REQUIRED_LIBRARIES rt)
+check_symbol_exists(_POSIX_TIMERS "unistd.h;time.h" HAVE_POSIX_TIMERS)
+cmake_pop_check_state()
+if(HAVE_POSIX_TIMERS)
+  find_library(RT_LIBRARY NAMES rt)
+endif()
 check_symbol_exists(res_nquery "resolv.h" HAVE_RES_NQUERY)
 check_symbol_exists(F_SETPIPE_SZ "linux/fcntl.h" CEPH_HAVE_SETPIPE_SZ)
 check_symbol_exists(__func__ "" HAVE_FUNC)
index 91680cbe5282bb23014ee48bcc47a8ff350ada00..7573b1e5da6242194125beb9c60a86437ed50f65 100644 (file)
@@ -151,8 +151,8 @@ if(COMPILER_SUPPORTS_DIAGNOSTICS_COLOR)
 endif()
 
 set(EXTRALIBS ${CMAKE_DL_LIBS})
-if(NOT APPLE)
-  list(APPEND EXTRALIBS rt)
+if(HAVE_POSIX_TIMERS)
+  list(APPEND EXTRALIBS ${RT_LIBRARY})
 endif()
 if(LINUX OR APPLE)
   set(LIB_RESOLV resolv)