blob: 19217343d1cc7bb4bd637921ef46dce9cc4a8b4c [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Jo-Philipp Wich <jo@mein.io>
2Date: Wed, 11 Jan 2017 03:36:04 +0100
3Subject: [PATCH] cmcurl: link librt
4
5When cmake is linked against LibreSSL, there might be an indirect
6dependency on librt on certain systems if LibreSSL's libcrypto uses
7clock_gettime() from librt:
8
9 [ 28%] Linking C executable LIBCURL
10 .../lib/libcrypto.a(getentropy_linux.o): In function `getentropy_fallback':
11 getentropy_linux.c:(.text+0x16d): undefined reference to `clock_gettime'
12 getentropy_linux.c:(.text+0x412): undefined reference to `clock_gettime'
13 collect2: error: ld returned 1 exit status
14 make[5]: *** [Utilities/cmcurl/LIBCURL] Error 1
15
16Modify the cmcurl CMakeLists.txt to check for clock_gettime() in librt
17and unconditionally link the rt library when the symbol is found.
18
19Signed-off-by: Jo-Philipp Wich <jo@mein.io>
20---
21--- a/Utilities/cmcurl/CMakeLists.txt
22+++ b/Utilities/cmcurl/CMakeLists.txt
23@@ -648,6 +648,14 @@ if(CURL_USE_OPENSSL)
24 endif()
25 set(SSL_ENABLED ON)
26 set(USE_OPENSSL ON)
27+ check_library_exists("rt" clock_gettime "" HAVE_LIBRT)
28+ if(HAVE_LIBRT)
29+ list(APPEND OPENSSL_LIBRARIES rt)
30+ endif()
31+ check_library_exists("pthread" pthread_once "" HAVE_PTHREAD)
32+ if(HAVE_PTHREAD)
33+ list(APPEND OPENSSL_LIBRARIES pthread)
34+ endif()
35 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
36 include_directories(${OPENSSL_INCLUDE_DIR})
37