From: Kefu Chai Date: Mon, 11 Nov 2019 22:55:40 +0000 (+0800) Subject: cmake: detect librt for POSIX time functions X-Git-Tag: v15.1.0~871^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d6998a3b95c45d4a5f8ff433d9ee4cf96316f274;p=ceph.git cmake: detect librt for POSIX time functions per clock_gettime(3), > On POSIX systems on which these functions are available, the symbol > _POSIX_TIMERS is defined in 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 --- diff --git a/cmake/modules/CephChecks.cmake b/cmake/modules/CephChecks.cmake index 0f3f9a1d48a..1a46e88876d 100644 --- a/cmake/modules/CephChecks.cmake +++ b/cmake/modules/CephChecks.cmake @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 91680cbe528..7573b1e5da6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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)