summaryrefslogtreecommitdiffstats
path: root/project/cmake/modules/FindCurl.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/modules/FindCurl.cmake')
-rw-r--r--project/cmake/modules/FindCurl.cmake94
1 files changed, 70 insertions, 24 deletions
diff --git a/project/cmake/modules/FindCurl.cmake b/project/cmake/modules/FindCurl.cmake
index a2e8862..ed4d81f 100644
--- a/project/cmake/modules/FindCurl.cmake
+++ b/project/cmake/modules/FindCurl.cmake
@@ -1,37 +1,83 @@
1# - Try to find CURL 1#.rst:
2# Once done this will define 2# FindCurl
3# --------
4# Finds the Curl library
3# 5#
4# CURL_FOUND - system has libcurl 6# This will will define the following variables::
5# CURL_INCLUDE_DIRS - the libcurl include directory 7#
6# CURL_LIBRARIES - The libcurl libraries 8# CURL_FOUND - system has Curl
9# CURL_INCLUDE_DIRS - the Curl include directory
10# CURL_LIBRARIES - the Curl libraries
11# CURL_DEFINITIONS - the Curl definitions
12#
13# and the following imported targets::
14#
15# Curl::Curl - The Curl library
7 16
8if(PKG_CONFIG_FOUND) 17if(PKG_CONFIG_FOUND)
9 pkg_check_modules (CURL libcurl) 18 pkg_check_modules(PC_CURL libcurl QUIET)
10 list(APPEND CURL_INCLUDE_DIRS ${CURL_INCLUDEDIR})
11else()
12 find_path(CURL_INCLUDE_DIRS curl/curl.h)
13 find_library(CURL_LIBRARIES NAMES curl libcurl)
14endif() 19endif()
15include(FindPackageHandleStandardArgs)
16find_package_handle_standard_args(Curl DEFAULT_MSG CURL_INCLUDE_DIRS CURL_LIBRARIES)
17 20
18mark_as_advanced(CURL_INCLUDE_DIRS CURL_LIBRARIES) 21find_path(CURL_INCLUDE_DIR NAMES curl/curl.h
22 PATHS ${PC_CURL_INCLUDEDIR})
23find_library(CURL_LIBRARY NAMES curl libcurl
24 PATHS ${PC_CURL_LIBDIR})
25
26set(CURL_VERSION ${PC_CURL_VERSION})
27
28include(FindPackageHandleStandardArgs)
29find_package_handle_standard_args(Curl
30 REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
31 VERSION_VAR CURL_VERSION)
19 32
20if(CURL_FOUND) 33if(CURL_FOUND)
21 if(NOT CURL_LIBRARY_DIRS AND CURL_LIBDIR) 34 set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
22 set(CURL_LIBRARY_DIRS ${CURL_LIBDIR}) 35 set(CURL_LIBRARIES ${CURL_LIBRARY})
36
37 # Check whether OpenSSL inside libcurl is static.
38 if(UNIX)
39 if(NOT DEFINED HAS_CURL_STATIC)
40 get_filename_component(CURL_LIBRARY_DIR ${CURL_LIBRARY} DIRECTORY)
41 find_soname(CURL REQUIRED)
42
43 if(APPLE)
44 set(libchecker nm)
45 set(searchpattern "T [_]?CRYPTO_set_locking_call")
46 else()
47 set(libchecker readelf -s)
48 set(searchpattern "CRYPTO_set_locking_call")
49 endif()
50 execute_process(
51 COMMAND ${libchecker} ${CURL_LIBRARY_DIR}/${CURL_SONAME}
52 COMMAND grep -Eq ${searchpattern}
53 RESULT_VARIABLE HAS_CURL_STATIC)
54 unset(libchecker)
55 unset(searchpattern)
56 if(HAS_CURL_STATIC EQUAL 0)
57 set(HAS_CURL_STATIC TRUE)
58 else()
59 set(HAS_CURL_STATIC FALSE)
60 endif()
61 set(HAS_CURL_STATIC ${HAS_CURL_STATIC} CACHE INTERNAL
62 "OpenSSL is statically linked into Curl")
63 message(STATUS "OpenSSL is statically linked into Curl: ${HAS_CURL_STATIC}")
64 endif()
23 endif() 65 endif()
24 66
25 find_soname(CURL) 67 if(HAS_CURL_STATIC)
68 set(CURL_DEFINITIONS -DHAS_CURL_STATIC=1)
69 endif()
26 70
27 if(EXISTS "${CURL_LIBRARY_DIRS}/${CURL_SONAME}") 71 if(NOT TARGET Curl::Curl)
28 execute_process(COMMAND readelf -s ${CURL_LIBRARY_DIRS}/${CURL_SONAME} COMMAND grep CRYPTO_set_locking_call OUTPUT_VARIABLE HAS_CURL_STATIC) 72 add_library(Curl::Curl UNKNOWN IMPORTED)
29 else() 73 set_target_properties(Curl::Curl PROPERTIES
30 message(FATAL_ERROR "curl library not found") 74 IMPORTED_LOCATION "${CURL_LIBRARY}"
75 INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIR}")
76 if(HAS_CURL_STATIC)
77 set_target_properties(Curl::Curl PROPERTIES
78 INTERFACE_COMPILE_DEFINITIONS HAS_CURL_STATIC=1)
79 endif()
31 endif() 80 endif()
32endif() 81endif()
33 82
34if(HAS_CURL_STATIC) 83mark_as_advanced(CURL_INCLUDE_DIR CURL_LIBRARY)
35 mark_as_advanced(HAS_CURL_STATIC)
36 list(APPEND CURL_DEFINITIONS -DHAS_CURL_STATIC=1)
37endif()