Skip to content

Commit ee29bcd

Browse files
fanquakebluca
authored andcommitted
problem: trying to link against librt on macOS
Solution: don't use rt if not `RT_LIBRARY` This currently causes the check to fail on macOS: ```bash /Library/Developer/CommandLineTools/usr/bin/c++ -std=c++11 -Wno-tautological-constant-compare -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_8466b.dir/CheckSymbolExists.cxx.o -o cmTC_8466b -lrt ld: library 'rt' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` even though `clock_gettime` is available. Move the `clock_gettime` check up with the other librt related checks, and don't set `CMAKE_REQUIRED_LIBRARIES` if not `RT_LIBRARY`.
1 parent d203ad2 commit ee29bcd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

CMakeLists.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,12 @@ if(NOT MINGW)
589589
find_library(RT_LIBRARY rt)
590590
if(RT_LIBRARY)
591591
set(pkg_config_libs_private "${pkg_config_libs_private} -lrt")
592+
593+
set(CMAKE_REQUIRED_LIBRARIES rt)
594+
check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
595+
set(CMAKE_REQUIRED_LIBRARIES)
596+
else()
597+
check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
592598
endif()
593599
endif()
594600

@@ -609,10 +615,6 @@ if(WIN32 AND NOT CYGWIN)
609615
endif()
610616

611617
if(NOT MSVC)
612-
set(CMAKE_REQUIRED_LIBRARIES rt)
613-
check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
614-
set(CMAKE_REQUIRED_LIBRARIES)
615-
616618
check_cxx_symbol_exists(fork unistd.h HAVE_FORK)
617619
check_cxx_symbol_exists(gethrtime sys/time.h HAVE_GETHRTIME)
618620
check_cxx_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)

0 commit comments

Comments
 (0)