[CMake] Link with librt only when platform toolchain has it (#34255)

Not all POSIX platforms have rt as a separate library. QNX has rt as
part of libc (same as pthreads).
Add condition to check if the library can be found and link with it only
in positive scenario.

A solution for: https://github.com/grpc/grpc/issues/34254
pull/34837/head
Roman-Byshliaha-Bose 1 year ago committed by GitHub
parent 19ed52554f
commit e256508e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      CMakeLists.txt
  2. 5
      templates/CMakeLists.txt.template

5
CMakeLists.txt generated

@ -301,7 +301,10 @@ if(UNIX AND NOT HAIKU)
find_package(Threads)
set(_gRPC_ALLTARGETS_LIBRARIES ${CMAKE_DL_LIBS} m Threads::Threads)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
set(_gRPC_ALLTARGETS_LIBRARIES ${_gRPC_ALLTARGETS_LIBRARIES} rt)
find_library(LIBRT rt)
if(LIBRT)
set(_gRPC_ALLTARGETS_LIBRARIES ${_gRPC_ALLTARGETS_LIBRARIES} rt)
endif()
endif()
endif()

@ -444,7 +444,10 @@
find_package(Threads)
set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m Threads::Threads)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX)
set(_gRPC_ALLTARGETS_LIBRARIES <%text>${_gRPC_ALLTARGETS_LIBRARIES}</%text> rt)
find_library(LIBRT rt)
if(LIBRT)
set(_gRPC_ALLTARGETS_LIBRARIES <%text>${_gRPC_ALLTARGETS_LIBRARIES}</%text> rt)
endif()
endif()
endif()

Loading…
Cancel
Save