From 41739c89271177b1aa1755b1ea8a78f7bb3b7ff4 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Thu, 29 Sep 2022 12:35:25 +0200 Subject: [PATCH] Link with -lrt with ancient glibc --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e51cdd2..8efad82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,20 @@ set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_DEBUG} \ set(CMAKE_C_FLAGS_UBSAN "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING "Flags used by the C compiler during UndefinedBehaviorSanitizer builds." FORCE) +# Required for clock_gettime() in glibc <= 2.17 +include(CheckLibraryExists) +check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME) + +if (NOT HAVE_CLOCK_GETTIME) + check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME_RT) + if (HAVE_CLOCK_GETTIME_RT) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrt") + set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lrt") + else() + message(FATAL_ERROR "cannot find clock_gettime()") + endif() +endif() + add_library(ovni SHARED ovni.c parson.c