diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d6c0846eeafe4beddfea195c2fb9c6493095fe3..ca968eb8d8079f5fb32bc59d4de17e653c9b5753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,12 @@ else () set(HAVE_CLOCK_GETTIME ${HAVE_CLOCK_GETTIME_DECL}) endif () set(CMAKE_REQUIRED_LIBRARIES "") +# According to `man 2 clockgettime` the glibc wrapper requires +# -lrt on glibc versions before 2.17. We need to check whether +# the function is available without -lrt to set this linker option +# conditionally. +check_function_exists(clock_gettime HAVE_CLOCK_GETTIME_WITHOUT_RT) + check_symbol_exists(__get_cpuid cpuid.h HAVE_CPUID) # Checks for libev diff --git a/src/lib/core/CMakeLists.txt b/src/lib/core/CMakeLists.txt index e60b5199e15b8f45ad0abddd1b4ff7bf6884c9c2..8623aa0de9f65c3a5b5b86d0e0b0dc5b487cd0d1 100644 --- a/src/lib/core/CMakeLists.txt +++ b/src/lib/core/CMakeLists.txt @@ -46,3 +46,11 @@ target_link_libraries(core salad small uri decNumber ${LIBEV_LIBRARIES} if (ENABLE_BACKTRACE AND NOT TARGET_OS_DARWIN) target_link_libraries(core gcc_s ${UNWIND_LIBRARIES}) endif() + +# Since fiber.top() introduction, fiber.cc, which is part of core +# library, depends on clock_gettime() syscall, so we should set +# -lrt when it is appropriate. See a comment for +# HAVE_CLOCK_GETTIME_WITHOUT_RT in ${REPO}/CMakeLists.txt. +if ("${HAVE_CLOCK_GETTIME}" AND NOT "${HAVE_CLOCK_GETTIME_WITHOUT_RT}") + target_link_libraries(core rt) +endif()