Check for rt library in configuration -- support for glibc<2.17 (#2854)
authormakaimann <makaim@stanford.edu>
Tue, 16 Apr 2019 00:17:29 +0000 (17:17 -0700)
committerAndres Noetzli <andres.noetzli@gmail.com>
Tue, 16 Apr 2019 00:17:29 +0000 (17:17 -0700)
This is a minor fix for systems with glibc version < 2.17. In that case, we need to link with `-lrt` according to the clock_gettime man page.

cmake/ConfigureCVC4.cmake
src/CMakeLists.txt

index 84575d6109688496f2f64a6e2b92919c2055bbe7..67c1f414d0a1478f651de247d1970fdb277c8ac0 100644 (file)
@@ -2,6 +2,7 @@ include(CheckCXXSourceCompiles)
 include(CheckIncludeFile)
 include(CheckIncludeFileCXX)
 include(CheckSymbolExists)
+include(CheckLibraryExists)
 
 # Check whether "long" and "int64_t" are distinct types w.r.t. overloading.
 # Even if they have the same size, they can be distinct, and some platforms
@@ -54,6 +55,11 @@ if(CVC4_WINDOWS_BUILD)
   endif()
 else()
   check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
+  if(NOT HAVE_CLOCK_GETTIME)
+    unset(HAVE_CLOCK_GETTIME CACHE)
+    check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
+    find_library(RT_LIBRARIES NAMES rt)
+  endif()
 endif()
 check_symbol_exists(ffs "strings.h" HAVE_FFS)
 check_symbol_exists(optreset "getopt.h" HAVE_DECL_OPTRESET)
index 460c6c14d14258f2fac372c2dc5d6a72998ecd0a..372888d3665c006e4354329688ae8e77b145eb9d 100644 (file)
@@ -773,6 +773,11 @@ endif()
 target_link_libraries(cvc4 ${GMP_LIBRARIES})
 target_include_directories(cvc4 PUBLIC ${GMP_INCLUDE_DIR})
 
+# Add rt library
+# Note: For glibc < 2.17 we have to additionally link against rt (man clock_gettime).
+#       RT_LIBRARIES should be empty for glibc >= 2.17
+target_link_libraries(cvc4 ${RT_LIBRARIES})
+
 #-----------------------------------------------------------------------------#
 # Visit main subdirectory after creating target cvc4. For target main, we have
 # to manually add library dependencies since we can't use