]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Fix time.h checks not running on second CMake run.
authorJia Tan <jiat0218@gmail.com>
Tue, 12 Sep 2023 14:36:12 +0000 (22:36 +0800)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 7 May 2024 12:44:02 +0000 (15:44 +0300)
If CMake was configured more than once, HAVE_CLOCK_GETTIME and
HAVE_CLOCK_MONOTONIC would not be set as compile definitions. The check
for librt being needed to provide HAVE_CLOCK_GETTIME was also
simplified.

(cherry picked from commit a70e96d2da761b8b3a77bf14e08002d871e5950b)

CMakeLists.txt

index 3e410039f496d189a3682888c12d037c5a2e7670..1afe1d138a67f544dcec438cc9ed0c57cffb4d49 100644 (file)
@@ -167,24 +167,26 @@ tuklib_integer(ALL)
 
 # Check for clock_gettime(). Do this before checking for threading so
 # that we know there if CLOCK_MONOTONIC is available.
-if(NOT WIN32 AND NOT DEFINED HAVE_CLOCK_GETTIME)
+if(NOT WIN32)
     check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
+
     if(NOT HAVE_CLOCK_GETTIME)
         # With glibc <= 2.17 or Solaris 10 this needs librt.
-        unset(HAVE_CLOCK_GETTIME CACHE)
-
+        # Add librt for the next check for HAVE_CLOCK_GETTIME. If it is
+        # found after including the library, we know that librt is required.
         list(INSERT CMAKE_REQUIRED_LIBRARIES 0 rt)
-        check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
+        check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME_LIBRT)
 
-        # If it was found now, add it to all targets and keep it
-        # in CMAKE_REQUIRED_LIBRARIES for further tests too.
-        if(HAVE_CLOCK_GETTIME)
+        # If it was found now, add librt to all targets and keep it in
+        # CMAKE_REQUIRED_LIBRARIES for further tests too.
+        if(HAVE_CLOCK_GETTIME_LIBRT)
             link_libraries(rt)
         else()
             list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0)
         endif()
     endif()
-    if(HAVE_CLOCK_GETTIME)
+
+    if(HAVE_CLOCK_GETTIME OR HAVE_CLOCK_GETTIME_LIBRT)
         # Check if CLOCK_MONOTONIC is available for clock_gettime().
         check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_DECL_CLOCK_MONOTONIC)