Skip to content

Commit

Permalink
CMake: Fix time.h checks not running on second CMake run.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JiaT75 committed Sep 12, 2023
1 parent 5d691fe commit 7379bb3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,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)
add_compile_definitions(HAVE_CLOCK_GETTIME)

# Check if CLOCK_MONOTONIC is available for clock_gettime().
Expand Down

0 comments on commit 7379bb3

Please sign in to comment.