diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-08-18 00:31:05 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-08-18 00:40:14 +0300 |
commit | ab1bfc33c87726dc1fd85c351191380c6c463143 (patch) | |
tree | 731d03872f73628a9444c6007bf6dab0f742f7a7 /CMakeLists.txt | |
parent | 454e8410e03b8a141296ec4c3c2bf876d78b4ea8 (diff) | |
download | bdwgc-ab1bfc33c87726dc1fd85c351191380c6c463143.tar.gz |
Link with rt library to get clock_gettime where necessary
Issue #450 (bdwgc).
This patch adds the logic to CMake and configure scripts to pass -lrt
option during linking to avoid unresolved clock_gettime on some hosts.
* CMakeLists.txt [!NEED_LIB_RT] (HAVE_CLOCK_GETTIME_DIRECTLY): Set
variable by check_function_exists(clock_gettime).
* CMakeLists.txt [!NEED_LIB_RT && !HAVE_CLOCK_GETTIME_DIRECTLY]
(NEED_LIB_RT): Set to ON.
* CMakeLists.txt (LIBRT): Refine comment.
* CMakeLists.txt (gc): Specify target_link_libraries regardless of
enable_threads.
* Makefile.am (libgc_la_LIBADD): Update comment.
* configure.ac (need_lib_rt): Define variable (and set to false).
* configure.ac [$THREADS==pthreads && ($host==*-*-hpux11*
|| $host==*-*-netbsd* || $host== *-*-solaris* || $host==*-*-osf*)]
(THREADDLLIBS): Do not add "-lrt" directly.
* configure.ac [$THREADS==pthreads && ($host==*-*-hpux11*
|| $host==*-*-netbsd* || $host== *-*-solaris* || $host==*-*-osf*)]
(need_lib_rt): Set to true.
* configure.ac [!need_lib_rt && !AC_LINK_IFELSE(clock_gettime)
&& AC_CHECK_LIB(rt,clock_gettime)] (need_lib_rt): Set to true.
* configure.ac [need_lib_rt] (THREADDLLIBS): Append "-lrt".
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cefb561..18dda3d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,7 +260,16 @@ elseif (CMAKE_HP_PTHREADS_INIT OR CMAKE_USE_SPROC_INIT) message(FATAL_ERROR "Unsupported thread package") endif() -# Some targets need -lrt linker option. +# Check whether -lrt linker option is needed to use clock_gettime. +if (NOT NEED_LIB_RT) + check_function_exists(clock_gettime HAVE_CLOCK_GETTIME_DIRECTLY) + if (NOT HAVE_CLOCK_GETTIME_DIRECTLY) + # Use of clock_gettime() probably requires linking with "rt" library. + set(NEED_LIB_RT ON) + endif() +endif() + +# Locate and use "rt" library if needed (and the library is available). if (NEED_LIB_RT) find_library(LIBRT rt) if (LIBRT) @@ -508,10 +517,8 @@ if (HAVE_DLADDR) endif() add_library(gc ${SRC}) -if (enable_threads) - target_link_libraries(gc +target_link_libraries(gc PRIVATE ${ATOMIC_OPS_LIBS_CMAKE} ${THREADDLLIBS_LIST}) -endif() target_include_directories(gc INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<INSTALL_INTERFACE:include>") |