diff options
Diffstat (limited to 'cmake/modules/FindCurl.cmake')
| -rw-r--r-- | cmake/modules/FindCurl.cmake | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/cmake/modules/FindCurl.cmake b/cmake/modules/FindCurl.cmake new file mode 100644 index 0000000..ed4d81f --- /dev/null +++ b/cmake/modules/FindCurl.cmake | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | #.rst: | ||
| 2 | # FindCurl | ||
| 3 | # -------- | ||
| 4 | # Finds the Curl library | ||
| 5 | # | ||
| 6 | # This will will define the following variables:: | ||
| 7 | # | ||
| 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 | ||
| 16 | |||
| 17 | if(PKG_CONFIG_FOUND) | ||
| 18 | pkg_check_modules(PC_CURL libcurl QUIET) | ||
| 19 | endif() | ||
| 20 | |||
| 21 | find_path(CURL_INCLUDE_DIR NAMES curl/curl.h | ||
| 22 | PATHS ${PC_CURL_INCLUDEDIR}) | ||
| 23 | find_library(CURL_LIBRARY NAMES curl libcurl | ||
| 24 | PATHS ${PC_CURL_LIBDIR}) | ||
| 25 | |||
| 26 | set(CURL_VERSION ${PC_CURL_VERSION}) | ||
| 27 | |||
| 28 | include(FindPackageHandleStandardArgs) | ||
| 29 | find_package_handle_standard_args(Curl | ||
| 30 | REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR | ||
| 31 | VERSION_VAR CURL_VERSION) | ||
| 32 | |||
| 33 | if(CURL_FOUND) | ||
| 34 | set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) | ||
| 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() | ||
| 65 | endif() | ||
| 66 | |||
| 67 | if(HAS_CURL_STATIC) | ||
| 68 | set(CURL_DEFINITIONS -DHAS_CURL_STATIC=1) | ||
| 69 | endif() | ||
| 70 | |||
| 71 | if(NOT TARGET Curl::Curl) | ||
| 72 | add_library(Curl::Curl UNKNOWN IMPORTED) | ||
| 73 | set_target_properties(Curl::Curl PROPERTIES | ||
| 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() | ||
| 80 | endif() | ||
| 81 | endif() | ||
| 82 | |||
| 83 | mark_as_advanced(CURL_INCLUDE_DIR CURL_LIBRARY) | ||
