1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 9# 10# This software is licensed as described in the file COPYING, which 11# you should have received as part of this distribution. The terms 12# are also available at https://curl.se/docs/copyright.html. 13# 14# You may opt to use, copy, modify, merge, publish, distribute and/or sell 15# copies of the Software, and permit persons to whom the Software is 16# furnished to do so, under the terms of the COPYING file. 17# 18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19# KIND, either express or implied. 20# 21# SPDX-License-Identifier: curl 22# 23########################################################################### 24# by Tetetest and Sukender (Benoit Neil) 25 26# Note: By default this CMake build script detects the version of some 27# dependencies using `check_symbol_exists`. Those checks do not work in 28# the case that both CURL and its dependency are included as sub-projects 29# in a larger build using `FetchContent`. To support that case, additional 30# variables may be defined by the parent project, ideally in the "extra" 31# find package redirect file: 32# https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package 33# 34# The following variables are available: 35# HAVE_SSL_SET0_WBIO: `SSL_set0_wbio` present in OpenSSL/wolfSSL 36# HAVE_OPENSSL_SRP: `SSL_CTX_set_srp_username` present in OpenSSL/wolfSSL 37# HAVE_GNUTLS_SRP: `gnutls_srp_verifier` present in GnuTLS 38# HAVE_SSL_SET_QUIC_USE_LEGACY_CODEPOINT: `SSL_set_quic_use_legacy_codepoint` present in OpenSSL/wolfSSL 39# HAVE_QUICHE_CONN_SET_QLOG_FD: `quiche_conn_set_qlog_fd` present in quiche 40# HAVE_ECH: ECH API checks for OpenSSL, BoringSSL or wolfSSL 41# 42# For each of the above variables, if the variable is DEFINED (either 43# to ON or OFF), the symbol detection is skipped. If the variable is 44# NOT DEFINED, the symbol detection is performed. 45 46cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR) 47message(STATUS "Using CMake version ${CMAKE_VERSION}") 48 49# Collect command-line arguments for buildinfo.txt. 50# Must reside at the top of the script to work as expected. 51set(_cmake_args "") 52if(NOT "$ENV{CURL_BUILDINFO}$ENV{CURL_CI}$ENV{CI}" STREQUAL "") 53 get_cmake_property(_cache_vars CACHE_VARIABLES) 54 foreach(_cache_var IN ITEMS ${_cache_vars}) 55 get_property(_cache_var_helpstring CACHE ${_cache_var} PROPERTY HELPSTRING) 56 if(_cache_var_helpstring STREQUAL "No help, variable specified on the command line.") 57 get_property(_cache_var_type CACHE ${_cache_var} PROPERTY TYPE) 58 get_property(_cache_var_value CACHE ${_cache_var} PROPERTY VALUE) 59 if(_cache_var_type STREQUAL "UNINITIALIZED") 60 set(_cache_var_type) 61 else() 62 set(_cache_var_type ":${_cache_var_type}") 63 endif() 64 set(_cmake_args "${_cmake_args} -D${_cache_var}${_cache_var_type}=\"${_cache_var_value}\"") 65 endif() 66 endforeach() 67endif() 68 69set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}") 70include(Utilities) 71include(Macros) 72include(CMakeDependentOption) 73include(CheckCCompilerFlag) 74 75file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/curl/curlver.h" _curl_version_h_contents REGEX "#define LIBCURL_VERSION( |_NUM )") 76string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*" _curl_version ${_curl_version_h_contents}) 77string(REGEX REPLACE "[^\"]+\"" "" _curl_version ${_curl_version}) 78string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+" _curl_version_num ${_curl_version_h_contents}) 79string(REGEX REPLACE "[^0]+0x" "" _curl_version_num ${_curl_version_num}) 80unset(_curl_version_h_contents) 81 82message(STATUS "curl version=[${_curl_version}]") 83 84string(REGEX REPLACE "([0-9]+\.[0-9]+\.[0-9]+).+" "\\1" _curl_version_sem "${_curl_version}") 85project(CURL 86 VERSION "${_curl_version_sem}" 87 LANGUAGES C) 88 89# CMake does not recognize some targets accurately. Touch up configuration manually as a workaround. 90if(WINDOWS_STORE AND MINGW) # mingw UWP build 91 # CMake (as of v3.31.2) gets confused and applies the MSVC rc.exe command-line 92 # template to windres. Reset it to the windres template via 'Modules/Platform/Windows-windres.cmake': 93 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>") 94elseif(DOS AND CMAKE_COMPILER_IS_GNUCC) # DJGPP 95 set(CMAKE_STATIC_LIBRARY_PREFIX "lib") 96 set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") 97 set(CMAKE_FIND_LIBRARY_PREFIXES "lib") 98 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") 99endif() 100 101# Fill platform level variable when using CMake's built-in Android configuration 102if(ANDROID AND NOT DEFINED ANDROID_PLATFORM_LEVEL AND NOT CMAKE_SYSTEM_VERSION EQUAL 1) 103 set(ANDROID_PLATFORM_LEVEL "${CMAKE_SYSTEM_VERSION}") 104endif() 105 106set(_target_flags "") 107if(APPLE) 108 set(_target_flags "${_target_flags} APPLE") 109endif() 110if(UNIX) 111 set(_target_flags "${_target_flags} UNIX") 112endif() 113if(BSD) 114 set(_target_flags "${_target_flags} BSD") 115endif() 116if(ANDROID) 117 set(_target_flags "${_target_flags} ANDROID-${ANDROID_PLATFORM_LEVEL}") 118endif() 119if(WIN32) 120 set(_target_flags "${_target_flags} WIN32") 121endif() 122if(WINDOWS_STORE) 123 set(_target_flags "${_target_flags} UWP") 124endif() 125if(CYGWIN) 126 set(_target_flags "${_target_flags} CYGWIN") 127endif() 128if(MSYS) 129 set(_target_flags "${_target_flags} MSYS") 130endif() 131if(DOS) 132 set(_target_flags "${_target_flags} DOS") 133endif() 134if(AMIGA) 135 set(_target_flags "${_target_flags} AMIGA") 136endif() 137if(CMAKE_COMPILER_IS_GNUCC) 138 set(_target_flags "${_target_flags} GCC") 139endif() 140if(MINGW) 141 set(_target_flags "${_target_flags} MINGW") 142endif() 143if(MSVC) 144 set(_target_flags "${_target_flags} MSVC-${MSVC_VERSION}") 145endif() 146if(VCPKG_TOOLCHAIN) 147 set(_target_flags "${_target_flags} VCPKG") 148endif() 149if(CMAKE_CROSSCOMPILING) 150 set(_target_flags "${_target_flags} CROSS") 151endif() 152message(STATUS "CMake platform flags:${_target_flags}") 153 154if(CMAKE_CROSSCOMPILING) 155 message(STATUS "Cross-compiling: " 156 "${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR} -> " 157 "${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}") 158endif() 159 160if(CMAKE_C_COMPILER_TARGET) 161 set(CURL_OS "\"${CMAKE_C_COMPILER_TARGET}\"") 162else() 163 set(CURL_OS "\"${CMAKE_SYSTEM_NAME}\"") 164endif() 165 166include_directories("${PROJECT_SOURCE_DIR}/include") 167 168if(NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE) 169 set(CMAKE_UNITY_BUILD_BATCH_SIZE 0) 170endif() 171 172# Having CMAKE_TRY_COMPILE_TARGET_TYPE set to STATIC_LIBRARY breaks certain 173# 'check_function_exists()' detections (possibly more), by detecting 174# non-existing features. This happens by default when using 'ios.toolchain.cmake'. 175# Work it around by setting this value to `EXECUTABLE`. 176if(CMAKE_TRY_COMPILE_TARGET_TYPE STREQUAL "STATIC_LIBRARY") 177 message(STATUS "CMAKE_TRY_COMPILE_TARGET_TYPE was found set to STATIC_LIBRARY. " 178 "Overriding with EXECUTABLE for feature detections to work.") 179 set(_cmake_try_compile_target_type_save ${CMAKE_TRY_COMPILE_TARGET_TYPE}) 180 set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE") 181endif() 182 183option(CURL_WERROR "Turn compiler warnings into errors" OFF) 184option(PICKY_COMPILER "Enable picky compiler options" ON) 185option(BUILD_CURL_EXE "Build curl executable" ON) 186option(BUILD_SHARED_LIBS "Build shared libraries" ON) 187option(BUILD_STATIC_LIBS "Build static libraries" OFF) 188option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF) 189option(ENABLE_ARES "Enable c-ares support" OFF) 190option(CURL_DISABLE_INSTALL "Disable installation targets" OFF) 191 192if(WIN32) 193 option(CURL_STATIC_CRT "Build libcurl with static CRT with MSVC (/MT)" OFF) 194 if(CURL_STATIC_CRT AND MSVC) 195 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") 196 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -MT") 197 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -MTd") 198 endif() 199 200 option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF) 201 if(WINDOWS_STORE) 202 set(ENABLE_UNICODE ON) 203 endif() 204 if(ENABLE_UNICODE) 205 add_definitions("-DUNICODE" "-D_UNICODE") 206 if(MINGW) 207 add_compile_options("-municode") 208 endif() 209 endif() 210 211 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN") # Apply to all feature checks 212 213 set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string") 214 if(CURL_TARGET_WINDOWS_VERSION) 215 add_definitions("-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") 216 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") # Apply to all feature checks 217 endif() 218 219 # Detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT 220 curl_internal_test(HAVE_WIN32_WINNT) 221 if(HAVE_WIN32_WINNT) 222 string(REGEX MATCH "_WIN32_WINNT=0x[0-9a-fA-F]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}") 223 string(REGEX REPLACE "_WIN32_WINNT=" "" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}") 224 string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}") # pad to 4 digits 225 string(TOLOWER "${CURL_TEST_OUTPUT}" HAVE_WIN32_WINNT) 226 message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}") 227 endif() 228 unset(HAVE_WIN32_WINNT CACHE) # Avoid storing in CMake cache 229 230 if(MINGW) 231 # Detect __MINGW64_VERSION_MAJOR, __MINGW64_VERSION_MINOR and store as MINGW64_VERSION 232 curl_internal_test(MINGW64_VERSION) 233 if(MINGW64_VERSION) 234 string(REGEX MATCH "MINGW64_VERSION=[0-9]+\.[0-9]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}") 235 string(REGEX REPLACE "MINGW64_VERSION=" "" MINGW64_VERSION "${CURL_TEST_OUTPUT}") 236 message(STATUS "Found MINGW64_VERSION=${MINGW64_VERSION}") 237 endif() 238 unset(MINGW64_VERSION CACHE) # Avoid storing in CMake cache 239 endif() 240elseif(DOS OR AMIGA) 241 set(BUILD_SHARED_LIBS OFF) 242 set(BUILD_STATIC_LIBS ON) 243endif() 244option(CURL_LTO "Enable compiler Link Time Optimizations" OFF) 245 246if(NOT DOS AND NOT AMIGA) 247 # if c-ares is used, default the threaded resolver to OFF 248 if(ENABLE_ARES) 249 set(_enable_threaded_resolver_default OFF) 250 else() 251 set(_enable_threaded_resolver_default ON) 252 endif() 253 option(ENABLE_THREADED_RESOLVER "Enable threaded DNS lookup" ${_enable_threaded_resolver_default}) 254endif() 255 256include(PickyWarnings) 257 258if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 259 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") # Required for sendmmsg() 260endif() 261 262option(ENABLE_DEBUG "Enable curl debug features (for developing curl itself)" OFF) 263if(ENABLE_DEBUG) 264 message(WARNING "This curl build is Debug-enabled, do not use in production.") 265endif() 266option(ENABLE_CURLDEBUG "Enable TrackMemory debug feature" ${ENABLE_DEBUG}) 267 268if(MSVC) 269 set(ENABLE_CURLDEBUG OFF) # FIXME: TrackMemory + MSVC fails test 558 and 1330. Tested with static build, Debug mode. 270endif() 271 272if(ENABLE_DEBUG) 273 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "DEBUGBUILD") 274endif() 275 276if(ENABLE_CURLDEBUG) 277 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "CURLDEBUG") 278endif() 279 280option(CURL_CLANG_TIDY "Run the build through clang-tidy" OFF) 281if(CURL_CLANG_TIDY) 282 set(CMAKE_UNITY_BUILD OFF) 283 set(_tidy_checks "") 284 list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.strcpy") 285 list(APPEND _tidy_checks "-clang-analyzer-optin.performance.Padding") 286 list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling") 287 string(REPLACE ";" "," _tidy_checks "${_tidy_checks}") 288 find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED) 289 set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY}" "-checks=${_tidy_checks}" "-quiet") 290 unset(_tidy_checks) 291 if(CURL_WERROR) 292 list(APPEND CMAKE_C_CLANG_TIDY "--warnings-as-errors=*") 293 endif() 294 if(CURL_CLANG_TIDYFLAGS) 295 list(APPEND CMAKE_C_CLANG_TIDY ${CURL_CLANG_TIDYFLAGS}) 296 endif() 297endif() 298 299# For debug libs and exes, add "-d" postfix 300if(NOT DEFINED CMAKE_DEBUG_POSTFIX) 301 set(CMAKE_DEBUG_POSTFIX "-d") 302endif() 303 304set(LIB_STATIC "libcurl_static") 305set(LIB_SHARED "libcurl_shared") 306 307if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS) 308 set(BUILD_STATIC_LIBS ON) 309endif() 310if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS) 311 set(BUILD_STATIC_CURL ON) 312elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS) 313 set(BUILD_STATIC_CURL OFF) 314endif() 315 316# Lib flavour selected for curl tool 317if(BUILD_STATIC_CURL) 318 set(LIB_SELECTED_FOR_EXE ${LIB_STATIC}) 319else() 320 set(LIB_SELECTED_FOR_EXE ${LIB_SHARED}) 321endif() 322 323# Lib flavour selected for example and test programs. 324if(BUILD_SHARED_LIBS) 325 set(LIB_SELECTED ${LIB_SHARED}) 326else() 327 set(LIB_SELECTED ${LIB_STATIC}) 328endif() 329 330# Override to force-disable or force-enable the use of pkg-config. 331if((UNIX AND NOT ANDROID AND (NOT APPLE OR CMAKE_SYSTEM_NAME MATCHES "Darwin")) OR 332 VCPKG_TOOLCHAIN OR 333 (MINGW AND NOT CMAKE_CROSSCOMPILING)) 334 set(_curl_use_pkgconfig_default ON) 335else() 336 set(_curl_use_pkgconfig_default OFF) 337endif() 338option(CURL_USE_PKGCONFIG "Enable pkg-config to detect dependencies" ${_curl_use_pkgconfig_default}) 339 340# Initialize variables collecting dependency libs, paths, pkg-config names. 341set(CURL_LIBS "") 342set(CURL_LIBDIRS "") 343set(LIBCURL_PC_REQUIRES_PRIVATE "") 344 345if(ENABLE_ARES) 346 set(USE_ARES 1) 347 find_package(Cares REQUIRED) 348 list(APPEND CURL_LIBS ${CARES_LIBRARIES}) 349 list(APPEND CURL_LIBDIRS ${CARES_LIBRARY_DIRS}) 350 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${CARES_PC_REQUIRES}) 351 link_directories(${CARES_LIBRARY_DIRS}) 352 if(CARES_CFLAGS) 353 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CARES_CFLAGS}") 354 endif() 355endif() 356 357include(CurlSymbolHiding) 358 359option(CURL_ENABLE_EXPORT_TARGET "Enable CMake export target" ON) 360mark_as_advanced(CURL_ENABLE_EXPORT_TARGET) 361 362option(CURL_DISABLE_ALTSVC "Disable alt-svc support" OFF) 363mark_as_advanced(CURL_DISABLE_ALTSVC) 364option(CURL_DISABLE_SRP "Disable TLS-SRP support" OFF) 365mark_as_advanced(CURL_DISABLE_SRP) 366option(CURL_DISABLE_COOKIES "Disable cookies support" OFF) 367mark_as_advanced(CURL_DISABLE_COOKIES) 368option(CURL_DISABLE_BASIC_AUTH "Disable Basic authentication" OFF) 369mark_as_advanced(CURL_DISABLE_BASIC_AUTH) 370option(CURL_DISABLE_BEARER_AUTH "Disable Bearer authentication" OFF) 371mark_as_advanced(CURL_DISABLE_BEARER_AUTH) 372option(CURL_DISABLE_DIGEST_AUTH "Disable Digest authentication" OFF) 373mark_as_advanced(CURL_DISABLE_DIGEST_AUTH) 374option(CURL_DISABLE_KERBEROS_AUTH "Disable Kerberos authentication" OFF) 375mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH) 376option(CURL_DISABLE_NEGOTIATE_AUTH "Disable negotiate authentication" OFF) 377mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH) 378option(CURL_DISABLE_AWS "Disable aws-sigv4" OFF) 379mark_as_advanced(CURL_DISABLE_AWS) 380option(CURL_DISABLE_DICT "Disable DICT" OFF) 381mark_as_advanced(CURL_DISABLE_DICT) 382option(CURL_DISABLE_DOH "Disable DNS-over-HTTPS" OFF) 383mark_as_advanced(CURL_DISABLE_DOH) 384option(CURL_DISABLE_FILE "Disable FILE" OFF) 385mark_as_advanced(CURL_DISABLE_FILE) 386option(CURL_DISABLE_FTP "Disable FTP" OFF) 387mark_as_advanced(CURL_DISABLE_FTP) 388option(CURL_DISABLE_GETOPTIONS "Disable curl_easy_options API for existing options to curl_easy_setopt" OFF) 389mark_as_advanced(CURL_DISABLE_GETOPTIONS) 390option(CURL_DISABLE_GOPHER "Disable Gopher" OFF) 391mark_as_advanced(CURL_DISABLE_GOPHER) 392option(CURL_DISABLE_HEADERS_API "Disable headers-api support" OFF) 393mark_as_advanced(CURL_DISABLE_HEADERS_API) 394option(CURL_DISABLE_HSTS "Disable HSTS support" OFF) 395mark_as_advanced(CURL_DISABLE_HSTS) 396option(CURL_DISABLE_HTTP "Disable HTTP" OFF) 397mark_as_advanced(CURL_DISABLE_HTTP) 398option(CURL_DISABLE_HTTP_AUTH "Disable all HTTP authentication methods" OFF) 399mark_as_advanced(CURL_DISABLE_HTTP_AUTH) 400option(CURL_DISABLE_IMAP "Disable IMAP" OFF) 401mark_as_advanced(CURL_DISABLE_IMAP) 402option(CURL_DISABLE_LDAP "Disable LDAP" OFF) 403mark_as_advanced(CURL_DISABLE_LDAP) 404option(CURL_DISABLE_LDAPS "Disable LDAPS" ${CURL_DISABLE_LDAP}) 405mark_as_advanced(CURL_DISABLE_LDAPS) 406option(CURL_DISABLE_LIBCURL_OPTION "Disable --libcurl option from the curl tool" OFF) 407mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION) 408option(CURL_DISABLE_MIME "Disable MIME support" OFF) 409mark_as_advanced(CURL_DISABLE_MIME) 410cmake_dependent_option(CURL_DISABLE_FORM_API "Disable form-api" 411 OFF "NOT CURL_DISABLE_MIME" 412 ON) 413mark_as_advanced(CURL_DISABLE_FORM_API) 414option(CURL_DISABLE_MQTT "Disable MQTT" OFF) 415mark_as_advanced(CURL_DISABLE_MQTT) 416option(CURL_DISABLE_BINDLOCAL "Disable local binding support" OFF) 417mark_as_advanced(CURL_DISABLE_BINDLOCAL) 418option(CURL_DISABLE_NETRC "Disable netrc parser" OFF) 419mark_as_advanced(CURL_DISABLE_NETRC) 420option(CURL_DISABLE_NTLM "Disable NTLM support" OFF) 421mark_as_advanced(CURL_DISABLE_NTLM) 422option(CURL_DISABLE_PARSEDATE "Disable date parsing" OFF) 423mark_as_advanced(CURL_DISABLE_PARSEDATE) 424option(CURL_DISABLE_POP3 "Disable POP3" OFF) 425mark_as_advanced(CURL_DISABLE_POP3) 426option(CURL_DISABLE_PROGRESS_METER "Disable built-in progress meter" OFF) 427mark_as_advanced(CURL_DISABLE_PROGRESS_METER) 428option(CURL_DISABLE_PROXY "Disable proxy support" OFF) 429mark_as_advanced(CURL_DISABLE_PROXY) 430option(CURL_DISABLE_IPFS "Disable IPFS" OFF) 431mark_as_advanced(CURL_DISABLE_IPFS) 432option(CURL_DISABLE_RTSP "Disable RTSP" OFF) 433mark_as_advanced(CURL_DISABLE_SHA512_256) 434option(CURL_DISABLE_SHA512_256 "Disable SHA-512/256 hash algorithm" OFF) 435mark_as_advanced(CURL_DISABLE_RTSP) 436option(CURL_DISABLE_SHUFFLE_DNS "Disable shuffle DNS feature" OFF) 437mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS) 438option(CURL_DISABLE_SMB "Disable SMB" OFF) 439mark_as_advanced(CURL_DISABLE_SMB) 440option(CURL_DISABLE_SMTP "Disable SMTP" OFF) 441mark_as_advanced(CURL_DISABLE_SMTP) 442option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll" OFF) 443mark_as_advanced(CURL_DISABLE_SOCKETPAIR) 444option(CURL_DISABLE_WEBSOCKETS "Disable WebSocket" OFF) 445mark_as_advanced(CURL_DISABLE_WEBSOCKETS) 446option(CURL_DISABLE_TELNET "Disable Telnet" OFF) 447mark_as_advanced(CURL_DISABLE_TELNET) 448option(CURL_DISABLE_TFTP "Disable TFTP" OFF) 449mark_as_advanced(CURL_DISABLE_TFTP) 450option(CURL_DISABLE_VERBOSE_STRINGS "Disable verbose strings" OFF) 451mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS) 452 453if(CURL_DISABLE_HTTP) 454 set(CURL_DISABLE_IPFS ON) 455 set(CURL_DISABLE_RTSP ON) 456 set(CURL_DISABLE_ALTSVC ON) 457 set(CURL_DISABLE_HSTS ON) 458endif() 459 460# Corresponds to HTTP_ONLY in lib/curl_setup.h 461option(HTTP_ONLY "Disable all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF) 462mark_as_advanced(HTTP_ONLY) 463 464if(HTTP_ONLY) 465 set(CURL_DISABLE_DICT ON) 466 set(CURL_DISABLE_FILE ON) 467 set(CURL_DISABLE_FTP ON) 468 set(CURL_DISABLE_GOPHER ON) 469 set(CURL_DISABLE_IMAP ON) 470 set(CURL_DISABLE_LDAP ON) 471 set(CURL_DISABLE_LDAPS ON) 472 set(CURL_DISABLE_MQTT ON) 473 set(CURL_DISABLE_POP3 ON) 474 set(CURL_DISABLE_IPFS ON) 475 set(CURL_DISABLE_RTSP ON) 476 set(CURL_DISABLE_SMB ON) 477 set(CURL_DISABLE_SMTP ON) 478 set(CURL_DISABLE_TELNET ON) 479 set(CURL_DISABLE_TFTP ON) 480endif() 481 482if(WINDOWS_STORE) 483 set(CURL_DISABLE_TELNET ON) # telnet code needs fixing to compile for UWP. 484endif() 485 486option(ENABLE_IPV6 "Enable IPv6 support" ON) 487mark_as_advanced(ENABLE_IPV6) 488if(ENABLE_IPV6 AND NOT WIN32) 489 include(CheckStructHasMember) 490 check_struct_has_member("struct sockaddr_in6" "sin6_addr" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_ADDR) 491 check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) 492 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR) 493 if(NOT DOS AND NOT AMIGA) 494 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support") 495 endif() 496 # Force the feature off as this name is used as guard macro... 497 set(ENABLE_IPV6 OFF CACHE BOOL "Enable IPv6 support" FORCE) 498 endif() 499 500 if(APPLE AND NOT ENABLE_ARES) 501 set(_use_core_foundation_and_core_services ON) 502 503 find_library(SYSTEMCONFIGURATION_FRAMEWORK NAMES "SystemConfiguration") 504 mark_as_advanced(SYSTEMCONFIGURATION_FRAMEWORK) 505 if(NOT SYSTEMCONFIGURATION_FRAMEWORK) 506 message(FATAL_ERROR "SystemConfiguration framework not found") 507 endif() 508 list(APPEND CURL_LIBS "-framework SystemConfiguration") 509 endif() 510endif() 511if(ENABLE_IPV6) 512 set(USE_IPV6 ON) 513endif() 514 515find_package(Perl) 516 517if(PERL_EXECUTABLE) 518 add_custom_target(curl-ca-bundle 519 COMMENT "Generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL 520 COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl" -b -l -u "lib/ca-bundle.crt" 521 DEPENDS "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl" 522 ) 523 add_custom_target(curl-ca-firefox 524 COMMENT "generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL 525 COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh" "lib/ca-bundle.crt" 526 DEPENDS "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh" 527 ) 528endif() 529 530option(BUILD_LIBCURL_DOCS "Build libcurl man pages" ON) 531option(BUILD_MISC_DOCS "Build misc man pages (e.g. curl-config and mk-ca-bundle)" ON) 532option(ENABLE_CURL_MANUAL "Build the man page for curl and enable its -M/--manual option" ON) 533 534if(ENABLE_CURL_MANUAL OR BUILD_LIBCURL_DOCS) 535 if(PERL_FOUND) 536 set(HAVE_MANUAL_TOOLS ON) 537 endif() 538 if(NOT HAVE_MANUAL_TOOLS) 539 message(WARNING "Perl not found. Will not build manuals.") 540 endif() 541endif() 542 543# Disable warnings on Borland to avoid changing 3rd party code. 544if(BORLAND) 545 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-") 546endif() 547 548# If we are on AIX, do the _ALL_SOURCE magic 549if(CMAKE_SYSTEM_NAME STREQUAL "AIX") 550 add_definitions("-D_ALL_SOURCE") 551endif() 552 553# If we are on Haiku, make sure that the network library is brought in. 554if(CMAKE_SYSTEM_NAME STREQUAL "Haiku") 555 list(APPEND CURL_LIBS "network") 556elseif(AMIGA) 557 list(APPEND CURL_LIBS "net" "m" "atomic") 558 list(APPEND CMAKE_REQUIRED_LIBRARIES "net" "m" "atomic") 559endif() 560 561# Include all the necessary files for macros 562include(CMakePushCheckState) 563include(CheckFunctionExists) 564include(CheckIncludeFile) 565include(CheckIncludeFiles) 566include(CheckLibraryExists) 567include(CheckSymbolExists) 568include(CheckTypeSize) 569include(CheckCSourceCompiles) 570 571if(WIN32) 572 # Preload settings on Windows 573 include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/win32-cache.cmake") 574elseif(APPLE) 575 # Fast-track predictable feature detections 576 set(HAVE_EVENTFD 0) 577 set(HAVE_GETPASS_R 0) 578 set(HAVE_SENDMMSG 0) 579elseif(AMIGA) 580 set(HAVE_GETADDRINFO 0) # Breaks the build when detected and used. 581endif() 582if(DOS OR AMIGA) 583 set(HAVE_TIME_T_UNSIGNED 1) 584endif() 585 586if(ENABLE_THREADED_RESOLVER) 587 if(WIN32) 588 set(USE_THREADS_WIN32 ON) 589 else() 590 find_package(Threads REQUIRED) 591 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT}) 592 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT}) 593 list(APPEND CURL_LIBS ${CMAKE_THREAD_LIBS_INIT}) 594 endif() 595endif() 596 597# Check for all needed libraries 598if(DOS) 599 if(WATT_ROOT) 600 set(USE_WATT32 ON) 601 # FIXME upstream: must specify the full path to avoid CMake converting "watt" to "watt.lib" 602 list(APPEND CURL_LIBS "${WATT_ROOT}/lib/libwatt.a") 603 include_directories(SYSTEM "${WATT_ROOT}/inc") 604 list(APPEND CMAKE_REQUIRED_INCLUDES "${WATT_ROOT}/inc") 605 else() 606 message(FATAL_ERROR "Set WATT_ROOT variable to the root installation of Watt-32.") 607 endif() 608elseif(AMIGA) 609 if(AMISSL_INCLUDE_DIR AND AMISSL_STUBS_LIBRARY AND AMISSL_AUTO_LIBRARY) 610 set(USE_AMISSL ON) 611 list(APPEND CMAKE_REQUIRED_INCLUDES "${AMISSL_INCLUDE_DIR}") 612 list(APPEND CMAKE_REQUIRED_LIBRARIES "${AMISSL_STUBS_LIBRARY}" "${AMISSL_AUTO_LIBRARY}") 613 set(OPENSSL_INCLUDE_DIR "${AMISSL_INCLUDE_DIR}") 614 set(OPENSSL_SSL_LIBRARY "${AMISSL_STUBS_LIBRARY}") 615 set(OPENSSL_CRYPTO_LIBRARY "${AMISSL_AUTO_LIBRARY}") 616 set(CURL_USE_OPENSSL ON) 617 set(CURL_CA_FALLBACK ON CACHE BOOL "") 618 endif() 619elseif(NOT WIN32 AND NOT APPLE) 620 check_library_exists("socket" "connect" "" HAVE_LIBSOCKET) 621 if(HAVE_LIBSOCKET) 622 set(CURL_LIBS "socket;${CURL_LIBS}") 623 endif() 624endif() 625 626if(WIN32) 627 list(APPEND CURL_LIBS "ws2_32" "bcrypt") 628endif() 629 630# Check SSL libraries 631option(CURL_ENABLE_SSL "Enable SSL support" ON) 632 633if(CURL_DEFAULT_SSL_BACKEND) 634 set(_valid_default_ssl_backend FALSE) 635endif() 636 637if(APPLE) 638 cmake_dependent_option(CURL_USE_SECTRANSP "Enable Apple OS native SSL/TLS (Secure Transport)" OFF CURL_ENABLE_SSL OFF) 639endif() 640if(WIN32) 641 cmake_dependent_option(CURL_USE_SCHANNEL "Enable Windows native SSL/TLS (Schannel)" OFF CURL_ENABLE_SSL OFF) 642 option(CURL_WINDOWS_SSPI "Enable SSPI on Windows" ${CURL_USE_SCHANNEL}) 643endif() 644cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 645cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 646cmake_dependent_option(CURL_USE_WOLFSSL "Enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 647cmake_dependent_option(CURL_USE_GNUTLS "Enable GnuTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 648cmake_dependent_option(CURL_USE_RUSTLS "Enable Rustls for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 649 650if(WIN32 OR 651 CURL_USE_SECTRANSP OR 652 CURL_USE_SCHANNEL OR 653 CURL_USE_MBEDTLS OR 654 CURL_USE_BEARSSL OR 655 CURL_USE_WOLFSSL OR 656 CURL_USE_GNUTLS OR 657 CURL_USE_RUSTLS) 658 set(_openssl_default OFF) 659else() 660 set(_openssl_default ON) 661endif() 662cmake_dependent_option(CURL_USE_OPENSSL "Enable OpenSSL for SSL/TLS" ${_openssl_default} CURL_ENABLE_SSL OFF) 663option(USE_OPENSSL_QUIC "Use OpenSSL and nghttp3 libraries for HTTP/3 support" OFF) 664if(USE_OPENSSL_QUIC AND NOT CURL_USE_OPENSSL) 665 message(WARNING "OpenSSL QUIC has been requested, but without enabling OpenSSL. Will not enable QUIC.") 666 set(USE_OPENSSL_QUIC OFF) 667endif() 668option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF) 669 670curl_count_true(_enabled_ssl_options_count 671 CURL_USE_SCHANNEL 672 CURL_USE_SECTRANSP 673 CURL_USE_OPENSSL 674 CURL_USE_MBEDTLS 675 CURL_USE_BEARSSL 676 CURL_USE_WOLFSSL 677 CURL_USE_GNUTLS 678 CURL_USE_RUSTLS 679) 680if(_enabled_ssl_options_count GREATER 1) 681 set(CURL_WITH_MULTI_SSL ON) 682elseif(_enabled_ssl_options_count EQUAL 0) 683 set(CURL_DISABLE_HSTS ON) 684endif() 685 686if(CURL_USE_SCHANNEL) 687 set(_ssl_enabled ON) 688 set(USE_SCHANNEL ON) # Windows native SSL/TLS support 689 set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI 690 691 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "schannel") 692 set(_valid_default_ssl_backend TRUE) 693 endif() 694endif() 695if(CURL_WINDOWS_SSPI) 696 set(USE_WINDOWS_SSPI ON) 697endif() 698 699if(CURL_USE_SECTRANSP) 700 set(_use_core_foundation_and_core_services ON) 701 702 find_library(SECURITY_FRAMEWORK NAMES "Security") 703 mark_as_advanced(SECURITY_FRAMEWORK) 704 if(NOT SECURITY_FRAMEWORK) 705 message(FATAL_ERROR "Security framework not found") 706 endif() 707 list(APPEND CURL_LIBS "-framework Security") 708 709 set(_ssl_enabled ON) 710 set(USE_SECTRANSP ON) 711 712 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport") 713 set(_valid_default_ssl_backend TRUE) 714 endif() 715 716 message(WARNING "Secure Transport does not support TLS 1.3.") 717endif() 718 719if(_use_core_foundation_and_core_services) 720 find_library(COREFOUNDATION_FRAMEWORK NAMES "CoreFoundation") 721 mark_as_advanced(COREFOUNDATION_FRAMEWORK) 722 if(NOT COREFOUNDATION_FRAMEWORK) 723 message(FATAL_ERROR "CoreFoundation framework not found") 724 endif() 725 list(APPEND CURL_LIBS "-framework CoreFoundation") 726 727 find_library(CORESERVICES_FRAMEWORK NAMES "CoreServices") 728 mark_as_advanced(CORESERVICES_FRAMEWORK) 729 if(NOT CORESERVICES_FRAMEWORK) 730 message(FATAL_ERROR "CoreServices framework not found") 731 endif() 732 list(APPEND CURL_LIBS "-framework CoreServices") 733endif() 734 735if(CURL_USE_OPENSSL) 736 find_package(OpenSSL REQUIRED) 737 set(_ssl_enabled ON) 738 set(USE_OPENSSL ON) 739 740 # Depend on OpenSSL via imported targets. This allows our dependents to 741 # get our dependencies transitively. 742 list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto) 743 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "openssl") 744 745 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl") 746 set(_valid_default_ssl_backend TRUE) 747 endif() 748 set(_curl_ca_bundle_supported TRUE) 749 750 cmake_push_check_state() 751 list(APPEND CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) 752 if(NOT DEFINED HAVE_BORINGSSL) 753 check_symbol_exists("OPENSSL_IS_BORINGSSL" "openssl/base.h" HAVE_BORINGSSL) 754 endif() 755 if(NOT DEFINED HAVE_AWSLC) 756 check_symbol_exists("OPENSSL_IS_AWSLC" "openssl/base.h" HAVE_AWSLC) 757 endif() 758 if(NOT DEFINED HAVE_LIBRESSL) 759 check_symbol_exists("LIBRESSL_VERSION_NUMBER" "openssl/opensslv.h" HAVE_LIBRESSL) 760 endif() 761 cmake_pop_check_state() 762 763 if(HAVE_BORINGSSL OR HAVE_AWSLC) 764 if(OPENSSL_USE_STATIC_LIBS AND CMAKE_C_COMPILER_ID MATCHES "Clang") 765 list(APPEND CURL_LIBS "stdc++") 766 list(APPEND CMAKE_REQUIRED_LIBRARIES "stdc++") 767 endif() 768 endif() 769 770 if(HAVE_BORINGSSL) 771 set(_openssl "BoringSSL") 772 elseif(HAVE_AWSLC) 773 set(_openssl "AWS-LC") 774 elseif(HAVE_LIBRESSL) 775 set(_openssl "LibreSSL") 776 elseif(USE_AMISSL) 777 set(_openssl "AmiSSL") 778 else() 779 set(_openssl "OpenSSL") 780 if(OPENSSL_VERSION VERSION_LESS 1.1.1) 781 message(WARNING "OpenSSL ${OPENSSL_VERSION} does not support TLS 1.3.") 782 endif() 783 endif() 784endif() 785 786if(CURL_USE_MBEDTLS) 787 find_package(MbedTLS REQUIRED) 788 set(_ssl_enabled ON) 789 set(USE_MBEDTLS ON) 790 list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES}) 791 list(APPEND CURL_LIBDIRS ${MBEDTLS_LIBRARY_DIRS}) 792 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${MBEDTLS_PC_REQUIRES}) 793 include_directories(SYSTEM ${MBEDTLS_INCLUDE_DIRS}) 794 link_directories(${MBEDTLS_LIBRARY_DIRS}) 795 if(MBEDTLS_CFLAGS) 796 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MBEDTLS_CFLAGS}") 797 endif() 798 799 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "mbedtls") 800 set(_valid_default_ssl_backend TRUE) 801 endif() 802 set(_curl_ca_bundle_supported TRUE) 803endif() 804 805if(CURL_USE_BEARSSL) 806 find_package(BearSSL REQUIRED) 807 set(_ssl_enabled ON) 808 set(USE_BEARSSL ON) 809 list(APPEND CURL_LIBS ${BEARSSL_LIBRARIES}) 810 include_directories(SYSTEM ${BEARSSL_INCLUDE_DIRS}) 811 812 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "bearssl") 813 set(_valid_default_ssl_backend TRUE) 814 endif() 815 set(_curl_ca_bundle_supported TRUE) 816 817 message(WARNING "BearSSL does not support TLS 1.3.") 818endif() 819 820if(CURL_USE_WOLFSSL) 821 find_package(WolfSSL REQUIRED) 822 set(_ssl_enabled ON) 823 set(USE_WOLFSSL ON) 824 list(APPEND CURL_LIBS ${WOLFSSL_LIBRARIES}) 825 list(APPEND CURL_LIBDIRS ${WOLFSSL_LIBRARY_DIRS}) 826 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${WOLFSSL_PC_REQUIRES}) 827 include_directories(SYSTEM ${WOLFSSL_INCLUDE_DIRS}) 828 link_directories(${WOLFSSL_LIBRARY_DIRS}) 829 if(WOLFSSL_CFLAGS) 830 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WOLFSSL_CFLAGS}") 831 endif() 832 833 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "wolfssl") 834 set(_valid_default_ssl_backend TRUE) 835 endif() 836 set(_curl_ca_bundle_supported TRUE) 837endif() 838 839if(CURL_USE_GNUTLS) 840 if(CURL_USE_PKGCONFIG) 841 find_package(PkgConfig QUIET) 842 pkg_check_modules(GNUTLS "gnutls") 843 if(GNUTLS_FOUND) 844 set(GNUTLS_LIBRARIES ${GNUTLS_LINK_LIBRARIES}) 845 endif() 846 endif() 847 if(NOT GNUTLS_FOUND) 848 find_package(GnuTLS REQUIRED) 849 endif() 850 find_package(Nettle REQUIRED) 851 set(_ssl_enabled ON) 852 set(USE_GNUTLS ON) 853 list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES} ${NETTLE_LIBRARIES}) 854 list(APPEND CURL_LIBDIRS ${NETTLE_LIBRARY_DIRS}) 855 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "gnutls" ${NETTLE_PC_REQUIRES}) 856 include_directories(SYSTEM ${GNUTLS_INCLUDE_DIRS} ${NETTLE_INCLUDE_DIRS}) 857 link_directories(${NETTLE_LIBRARY_DIRS}) 858 if(NETTLE_CFLAGS) 859 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NETTLE_CFLAGS}") 860 endif() 861 862 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls") 863 set(_valid_default_ssl_backend TRUE) 864 endif() 865 set(_curl_ca_bundle_supported TRUE) 866 867 if(NOT DEFINED HAVE_GNUTLS_SRP AND NOT CURL_DISABLE_SRP) 868 cmake_push_check_state() 869 list(APPEND CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS}) 870 list(APPEND CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES}) 871 check_symbol_exists("gnutls_srp_verifier" "gnutls/gnutls.h" HAVE_GNUTLS_SRP) 872 cmake_pop_check_state() 873 endif() 874endif() 875 876if(CURL_USE_RUSTLS) 877 find_package(Rustls REQUIRED) 878 set(_ssl_enabled ON) 879 set(USE_RUSTLS ON) 880 list(APPEND CURL_LIBS ${RUSTLS_LIBRARIES}) 881 list(APPEND CURL_LIBDIRS ${RUSTLS_LIBRARY_DIRS}) 882 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${RUSTLS_PC_REQUIRES}) 883 include_directories(SYSTEM ${RUSTLS_INCLUDE_DIRS}) 884 link_directories(${RUSTLS_LIBRARY_DIRS}) 885 if(RUSTLS_CFLAGS) 886 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${RUSTLS_CFLAGS}") 887 endif() 888 889 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "rustls") 890 set(_valid_default_ssl_backend TRUE) 891 endif() 892 set(_curl_ca_bundle_supported TRUE) 893endif() 894 895if(CURL_DEFAULT_SSL_BACKEND AND NOT _valid_default_ssl_backend) 896 message(FATAL_ERROR "CURL_DEFAULT_SSL_BACKEND '${CURL_DEFAULT_SSL_BACKEND}' not enabled.") 897endif() 898 899# Keep ZLIB detection after TLS detection, 900# and before calling curl_openssl_check_symbol_exists(). 901 902set(HAVE_LIBZ OFF) 903curl_dependency_option(CURL_ZLIB ZLIB "ZLIB") 904if(ZLIB_FOUND) 905 set(HAVE_LIBZ ON) 906 # Depend on ZLIB via imported targets. This allows our dependents to 907 # get our dependencies transitively. 908 list(APPEND CURL_LIBS ZLIB::ZLIB) 909 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "zlib") 910endif() 911 912set(HAVE_BROTLI OFF) 913curl_dependency_option(CURL_BROTLI Brotli "brotli") 914if(BROTLI_FOUND) 915 set(HAVE_BROTLI ON) 916 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES}) 917 list(APPEND CURL_LIBDIRS ${BROTLI_LIBRARY_DIRS}) 918 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${BROTLI_PC_REQUIRES}) 919 include_directories(SYSTEM ${BROTLI_INCLUDE_DIRS}) 920 link_directories(${BROTLI_LIBRARY_DIRS}) 921 if(BROTLI_CFLAGS) 922 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${BROTLI_CFLAGS}") 923 endif() 924endif() 925 926set(HAVE_ZSTD OFF) 927curl_dependency_option(CURL_ZSTD Zstd "zstd") 928if(ZSTD_FOUND) 929 if(NOT ZSTD_VERSION VERSION_LESS 1.0.0) 930 set(HAVE_ZSTD ON) 931 list(APPEND CURL_LIBS ${ZSTD_LIBRARIES}) 932 list(APPEND CURL_LIBDIRS ${ZSTD_LIBRARY_DIRS}) 933 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${ZSTD_PC_REQUIRES}) 934 include_directories(SYSTEM ${ZSTD_INCLUDE_DIRS}) 935 link_directories(${ZSTD_LIBRARY_DIRS}) 936 if(ZSTD_CFLAGS) 937 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ZSTD_CFLAGS}") 938 endif() 939 else() 940 message(WARNING "zstd v1.0.0 or newer is required, disabling zstd support.") 941 endif() 942endif() 943 944# Check symbol in an OpenSSL-like TLS backend. 945macro(curl_openssl_check_symbol_exists _symbol _files _variable) 946 cmake_push_check_state() 947 if(USE_OPENSSL) 948 list(APPEND CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}") 949 list(APPEND CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}") 950 if(HAVE_LIBZ) 951 list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}") 952 endif() 953 if(WIN32) 954 list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32") 955 list(APPEND CMAKE_REQUIRED_LIBRARIES "bcrypt") # for OpenSSL/LibreSSL 956 endif() 957 endif() 958 if(USE_WOLFSSL) 959 list(APPEND CMAKE_REQUIRED_INCLUDES "${WOLFSSL_INCLUDE_DIRS}") 960 list(APPEND CMAKE_REQUIRED_LIBRARIES "${WOLFSSL_LIBRARIES}") 961 curl_required_libpaths("${WOLFSSL_LIBRARY_DIRS}") 962 if(HAVE_LIBZ) 963 list(APPEND CMAKE_REQUIRED_INCLUDES "${ZLIB_INCLUDE_DIRS}") # Public wolfSSL headers require zlib headers 964 list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}") 965 endif() 966 if(WIN32) 967 list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32" "crypt32") 968 endif() 969 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_UINTPTR_T") # to pull in stdint.h (as of wolfSSL v5.5.4) 970 endif() 971 check_symbol_exists("${_symbol}" "${_files}" "${_variable}") 972 cmake_pop_check_state() 973endmacro() 974 975# Ensure that the OpenSSL fork actually supports QUIC. 976macro(curl_openssl_check_quic) 977 if(NOT DEFINED HAVE_SSL_SET_QUIC_USE_LEGACY_CODEPOINT) 978 if(USE_OPENSSL) 979 curl_openssl_check_symbol_exists("SSL_set_quic_use_legacy_codepoint" "openssl/ssl.h" HAVE_SSL_SET_QUIC_USE_LEGACY_CODEPOINT) 980 endif() 981 if(USE_WOLFSSL) 982 curl_openssl_check_symbol_exists("wolfSSL_set_quic_use_legacy_codepoint" "wolfssl/options.h;wolfssl/openssl/ssl.h" 983 HAVE_SSL_SET_QUIC_USE_LEGACY_CODEPOINT) 984 endif() 985 endif() 986 if(NOT HAVE_SSL_SET_QUIC_USE_LEGACY_CODEPOINT) 987 message(FATAL_ERROR "QUIC support is missing in OpenSSL fork. Try setting -DOPENSSL_ROOT_DIR") 988 endif() 989endmacro() 990 991if(USE_WOLFSSL) 992 curl_openssl_check_symbol_exists("wolfSSL_DES_ecb_encrypt" "wolfssl/options.h;wolfssl/openssl/des.h" HAVE_WOLFSSL_DES_ECB_ENCRYPT) 993 curl_openssl_check_symbol_exists("wolfSSL_BIO_new" "wolfssl/options.h;wolfssl/ssl.h" HAVE_WOLFSSL_BIO) 994 curl_openssl_check_symbol_exists("wolfSSL_BIO_set_shutdown" "wolfssl/options.h;wolfssl/ssl.h" HAVE_WOLFSSL_FULL_BIO) 995endif() 996 997if(USE_OPENSSL OR USE_WOLFSSL) 998 if(NOT DEFINED HAVE_SSL_SET0_WBIO) 999 curl_openssl_check_symbol_exists("SSL_set0_wbio" "openssl/ssl.h" HAVE_SSL_SET0_WBIO) 1000 endif() 1001 if(NOT DEFINED HAVE_OPENSSL_SRP AND NOT CURL_DISABLE_SRP) 1002 curl_openssl_check_symbol_exists("SSL_CTX_set_srp_username" "openssl/ssl.h" HAVE_OPENSSL_SRP) 1003 endif() 1004endif() 1005 1006option(USE_HTTPSRR "Enable HTTPS RR support" OFF) 1007option(USE_ECH "Enable ECH support" OFF) 1008if(USE_ECH) 1009 if(USE_OPENSSL OR USE_WOLFSSL) 1010 # Be sure that the TLS library actually supports ECH. 1011 if(USE_WOLFSSL) 1012 curl_openssl_check_symbol_exists("wolfSSL_CTX_GenerateEchConfig" "wolfssl/options.h;wolfssl/ssl.h" 1013 HAVE_WOLFSSL_CTX_GENERATEECHCONFIG) 1014 endif() 1015 if(HAVE_BORINGSSL OR HAVE_AWSLC) 1016 curl_openssl_check_symbol_exists("SSL_set1_ech_config_list" "openssl/ssl.h" HAVE_SSL_SET1_ECH_CONFIG_LIST) 1017 elseif(HAVE_OPENSSL) 1018 curl_openssl_check_symbol_exists("SSL_set1_ech_config_list" "openssl/ech.h" HAVE_SSL_SET1_ECH_CONFIG_LIST) 1019 endif() 1020 if(HAVE_WOLFSSL_CTX_GENERATEECHCONFIG OR 1021 HAVE_SSL_SET1_ECH_CONFIG_LIST) 1022 set(HAVE_ECH 1) 1023 endif() 1024 if(NOT HAVE_ECH) 1025 message(FATAL_ERROR "ECH support missing in OpenSSL/BoringSSL/AWS-LC/wolfSSL") 1026 else() 1027 message(STATUS "ECH enabled") 1028 # ECH wants HTTPSRR 1029 set(USE_HTTPSRR ON) 1030 message(STATUS "HTTPSRR enabled") 1031 endif() 1032 else() 1033 message(FATAL_ERROR "ECH requires ECH-enablded OpenSSL, BoringSSL, AWS-LC or wolfSSL") 1034 endif() 1035endif() 1036 1037option(USE_SSLS_EXPORT "Enable SSL session export support" OFF) 1038if(USE_SSLS_EXPORT) 1039 if(_ssl_enabled) 1040 message(STATUS "SSL export enabled.") 1041 else() 1042 message(FATAL_ERROR "SSL session export requires SSL enabled") 1043 endif() 1044endif() 1045 1046option(USE_NGHTTP2 "Use nghttp2 library" ON) 1047if(USE_NGHTTP2) 1048 find_package(NGHTTP2) 1049 if(NGHTTP2_FOUND) 1050 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES}) 1051 list(APPEND CURL_LIBDIRS ${NGHTTP2_LIBRARY_DIRS}) 1052 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGHTTP2_PC_REQUIRES}) 1053 include_directories(SYSTEM ${NGHTTP2_INCLUDE_DIRS}) 1054 link_directories(${NGHTTP2_LIBRARY_DIRS}) 1055 if(NGHTTP2_CFLAGS) 1056 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NGHTTP2_CFLAGS}") 1057 endif() 1058 else() 1059 set(USE_NGHTTP2 OFF) 1060 endif() 1061endif() 1062 1063option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF) 1064if(USE_NGTCP2) 1065 if(USE_OPENSSL OR USE_WOLFSSL) 1066 if(USE_WOLFSSL) 1067 find_package(NGTCP2 REQUIRED "wolfSSL") 1068 elseif(HAVE_BORINGSSL OR HAVE_AWSLC) 1069 find_package(NGTCP2 REQUIRED "BoringSSL") 1070 else() 1071 find_package(NGTCP2 REQUIRED "quictls") 1072 if(NOT HAVE_LIBRESSL) 1073 set(_openssl "quictls") 1074 endif() 1075 endif() 1076 curl_openssl_check_quic() 1077 elseif(USE_GNUTLS) 1078 find_package(NGTCP2 REQUIRED "GnuTLS") 1079 else() 1080 message(FATAL_ERROR "ngtcp2 requires OpenSSL, wolfSSL or GnuTLS") 1081 endif() 1082 list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES}) 1083 list(APPEND CURL_LIBDIRS ${NGTCP2_LIBRARY_DIRS}) 1084 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGTCP2_PC_REQUIRES}) 1085 include_directories(SYSTEM ${NGTCP2_INCLUDE_DIRS}) 1086 link_directories(${NGTCP2_LIBRARY_DIRS}) 1087 if(NGTCP2_CFLAGS) 1088 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NGTCP2_CFLAGS}") 1089 endif() 1090 1091 find_package(NGHTTP3 REQUIRED) 1092 set(USE_NGHTTP3 ON) 1093 list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES}) 1094 list(APPEND CURL_LIBDIRS ${NGHTTP3_LIBRARY_DIRS}) 1095 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGHTTP3_PC_REQUIRES}) 1096 include_directories(SYSTEM ${NGHTTP3_INCLUDE_DIRS}) 1097 link_directories(${NGHTTP3_LIBRARY_DIRS}) 1098 if(NGHTTP3_CFLAGS) 1099 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NGHTTP3_CFLAGS}") 1100 endif() 1101endif() 1102 1103option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF) 1104if(USE_QUICHE) 1105 if(USE_NGTCP2) 1106 message(FATAL_ERROR "Only one HTTP/3 backend can be selected") 1107 endif() 1108 find_package(Quiche REQUIRED) 1109 if(NOT HAVE_BORINGSSL) 1110 message(FATAL_ERROR "quiche requires BoringSSL") 1111 endif() 1112 curl_openssl_check_quic() 1113 list(APPEND CURL_LIBS ${QUICHE_LIBRARIES}) 1114 list(APPEND CURL_LIBDIRS ${QUICHE_LIBRARY_DIRS}) 1115 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${QUICHE_PC_REQUIRES}) 1116 include_directories(SYSTEM ${QUICHE_INCLUDE_DIRS}) 1117 link_directories(${QUICHE_LIBRARY_DIRS}) 1118 if(QUICHE_CFLAGS) 1119 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${QUICHE_CFLAGS}") 1120 endif() 1121 if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD) 1122 cmake_push_check_state() 1123 list(APPEND CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}") 1124 list(APPEND CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}") 1125 check_symbol_exists("quiche_conn_set_qlog_fd" "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD) 1126 cmake_pop_check_state() 1127 endif() 1128endif() 1129 1130option(USE_MSH3 "Use msh3/msquic library for HTTP/3 support" OFF) 1131if(USE_MSH3) 1132 if(USE_NGTCP2 OR USE_QUICHE) 1133 message(FATAL_ERROR "Only one HTTP/3 backend can be selected") 1134 endif() 1135 if(NOT WIN32) 1136 if(NOT USE_OPENSSL) 1137 message(FATAL_ERROR "msh3/msquic requires OpenSSL fork with QUIC API") 1138 endif() 1139 curl_openssl_check_quic() 1140 endif() 1141 find_package(MSH3 REQUIRED) 1142 list(APPEND CURL_LIBS ${MSH3_LIBRARIES}) 1143 list(APPEND CURL_LIBDIRS ${MSH3_LIBRARY_DIRS}) 1144 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${MSH3_PC_REQUIRES}) 1145 include_directories(SYSTEM ${MSH3_INCLUDE_DIRS}) 1146 link_directories(${MSH3_LIBRARY_DIRS}) 1147 if(MSH3_CFLAGS) 1148 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSH3_CFLAGS}") 1149 endif() 1150endif() 1151 1152if(USE_OPENSSL_QUIC) 1153 if(USE_NGTCP2 OR USE_QUICHE OR USE_MSH3) 1154 message(FATAL_ERROR "Only one HTTP/3 backend can be selected") 1155 endif() 1156 find_package(OpenSSL 3.3.0 REQUIRED) 1157 1158 find_package(NGHTTP3 REQUIRED) 1159 set(USE_NGHTTP3 ON) 1160 include_directories(SYSTEM ${NGHTTP3_INCLUDE_DIRS}) 1161 list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES}) 1162 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${NGHTTP3_PC_REQUIRES}) 1163endif() 1164 1165if(CURL_WITH_MULTI_SSL AND (USE_NGTCP2 OR USE_QUICHE OR USE_MSH3 OR USE_OPENSSL_QUIC)) 1166 message(FATAL_ERROR "MultiSSL cannot be enabled with HTTP/3 and vice versa.") 1167endif() 1168 1169if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP)) 1170 set(USE_TLS_SRP 1) 1171endif() 1172 1173if(NOT CURL_DISABLE_LDAP) 1174 if(WIN32 AND NOT WINDOWS_STORE) 1175 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON) 1176 if(USE_WIN32_LDAP) 1177 list(APPEND CURL_LIBS "wldap32") 1178 if(NOT CURL_DISABLE_LDAPS) 1179 set(HAVE_LDAP_SSL ON) 1180 endif() 1181 endif() 1182 endif() 1183 1184 # Now that we know, we are not using Windows LDAP... 1185 if(NOT USE_WIN32_LDAP) 1186 # Check for LDAP 1187 cmake_push_check_state() 1188 if(USE_OPENSSL) 1189 list(APPEND CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}) 1190 endif() 1191 find_package(LDAP) 1192 if(LDAP_FOUND) 1193 set(HAVE_LBER_H 1) 1194 set(CURL_LIBS "${LDAP_LIBRARIES};${CURL_LIBS}") 1195 list(APPEND CURL_LIBDIRS ${LDAP_LIBRARY_DIRS}) 1196 if(LDAP_PC_REQUIRES) 1197 set(LIBCURL_PC_REQUIRES_PRIVATE "${LDAP_PC_REQUIRES};${LIBCURL_PC_REQUIRES_PRIVATE}") 1198 endif() 1199 include_directories(SYSTEM ${LDAP_INCLUDE_DIRS}) 1200 link_directories(${LDAP_LIBRARY_DIRS}) 1201 if(LDAP_CFLAGS) 1202 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LDAP_CFLAGS}") 1203 endif() 1204 1205 # LDAP feature checks 1206 1207 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1") 1208 list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LIBRARIES}) 1209 curl_required_libpaths("${LDAP_LIBRARY_DIRS}") 1210 1211 check_function_exists("ldap_url_parse" HAVE_LDAP_URL_PARSE) 1212 check_function_exists("ldap_init_fd" HAVE_LDAP_INIT_FD) 1213 1214 check_include_file("ldap_ssl.h" HAVE_LDAP_SSL_H) 1215 1216 if(HAVE_LDAP_INIT_FD) 1217 set(USE_OPENLDAP ON) 1218 add_definitions("-DLDAP_DEPRECATED=1") 1219 endif() 1220 if(NOT CURL_DISABLE_LDAPS) 1221 set(HAVE_LDAP_SSL ON) 1222 endif() 1223 else() 1224 message(STATUS "LDAP not found. CURL_DISABLE_LDAP set ON") 1225 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE) 1226 endif() 1227 cmake_pop_check_state() 1228 endif() 1229endif() 1230 1231# No ldap, no ldaps. 1232if(CURL_DISABLE_LDAP) 1233 if(NOT CURL_DISABLE_LDAPS) 1234 message(STATUS "LDAP needs to be enabled to support LDAPS") 1235 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE) 1236 endif() 1237endif() 1238 1239if(WIN32) 1240 option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF) 1241 if(USE_WIN32_IDN) 1242 list(APPEND CURL_LIBS "normaliz") 1243 endif() 1244else() 1245 set(USE_WIN32_IDN OFF) 1246endif() 1247 1248if(APPLE) 1249 option(USE_APPLE_IDN "Use Apple built-in IDN support" OFF) 1250 if(USE_APPLE_IDN) 1251 cmake_push_check_state() 1252 list(APPEND CMAKE_REQUIRED_LIBRARIES "icucore") 1253 check_symbol_exists("uidna_openUTS46" "unicode/uidna.h" HAVE_APPLE_IDN) 1254 cmake_pop_check_state() 1255 if(HAVE_APPLE_IDN) 1256 list(APPEND CURL_LIBS "icucore" "iconv") 1257 else() 1258 set(USE_APPLE_IDN OFF) 1259 endif() 1260 endif() 1261else() 1262 set(USE_APPLE_IDN OFF) 1263endif() 1264 1265# Check for libidn2 1266option(USE_LIBIDN2 "Use libidn2 for IDN support" ON) 1267set(HAVE_IDN2_H OFF) 1268set(HAVE_LIBIDN2 OFF) 1269if(USE_LIBIDN2 AND NOT USE_APPLE_IDN AND NOT USE_WIN32_IDN) 1270 find_package(Libidn2) 1271 if(LIBIDN2_FOUND) 1272 set(CURL_LIBS "${LIBIDN2_LIBRARIES};${CURL_LIBS}") 1273 list(APPEND CURL_LIBDIRS ${LIBIDN2_LIBRARY_DIRS}) 1274 set(LIBCURL_PC_REQUIRES_PRIVATE "${LIBIDN2_PC_REQUIRES};${LIBCURL_PC_REQUIRES_PRIVATE}") 1275 include_directories(SYSTEM ${LIBIDN2_INCLUDE_DIRS}) 1276 link_directories(${LIBIDN2_LIBRARY_DIRS}) 1277 if(LIBIDN2_CFLAGS) 1278 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBIDN2_CFLAGS}") 1279 endif() 1280 set(HAVE_IDN2_H 1) 1281 set(HAVE_LIBIDN2 1) 1282 endif() 1283endif() 1284 1285# libpsl 1286option(CURL_USE_LIBPSL "Use libpsl" ON) 1287mark_as_advanced(CURL_USE_LIBPSL) 1288set(USE_LIBPSL OFF) 1289 1290if(CURL_USE_LIBPSL) 1291 find_package(Libpsl REQUIRED) 1292 list(APPEND CURL_LIBS ${LIBPSL_LIBRARIES}) 1293 list(APPEND CURL_LIBDIRS ${LIBPSL_LIBRARY_DIRS}) 1294 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBPSL_PC_REQUIRES}) 1295 include_directories(SYSTEM ${LIBPSL_INCLUDE_DIRS}) 1296 link_directories(${LIBPSL_LIBRARY_DIRS}) 1297 if(LIBPSL_CFLAGS) 1298 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBPSL_CFLAGS}") 1299 endif() 1300 set(USE_LIBPSL ON) 1301endif() 1302 1303# libssh2 1304option(CURL_USE_LIBSSH2 "Use libssh2" ON) 1305mark_as_advanced(CURL_USE_LIBSSH2) 1306set(USE_LIBSSH2 OFF) 1307 1308if(CURL_USE_LIBSSH2) 1309 find_package(Libssh2) 1310 if(LIBSSH2_FOUND) 1311 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARIES}) 1312 list(APPEND CURL_LIBDIRS ${LIBSSH2_LIBRARY_DIRS}) 1313 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBSSH2_PC_REQUIRES}) 1314 include_directories(SYSTEM ${LIBSSH2_INCLUDE_DIRS}) 1315 link_directories(${LIBSSH2_LIBRARY_DIRS}) 1316 if(LIBSSH2_CFLAGS) 1317 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBSSH2_CFLAGS}") 1318 endif() 1319 set(USE_LIBSSH2 ON) 1320 endif() 1321endif() 1322 1323# libssh 1324option(CURL_USE_LIBSSH "Use libssh" OFF) 1325mark_as_advanced(CURL_USE_LIBSSH) 1326if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH) 1327 find_package(Libssh REQUIRED) 1328 list(APPEND CURL_LIBS ${LIBSSH_LIBRARIES}) 1329 list(APPEND CURL_LIBDIRS ${LIBSSH_LIBRARY_DIRS}) 1330 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBSSH_PC_REQUIRES}) 1331 include_directories(SYSTEM ${LIBSSH_INCLUDE_DIRS}) 1332 link_directories(${LIBSSH_LIBRARY_DIRS}) 1333 if(LIBSSH_CFLAGS) 1334 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBSSH_CFLAGS}") 1335 endif() 1336 set(USE_LIBSSH ON) 1337endif() 1338 1339# wolfSSH 1340option(CURL_USE_WOLFSSH "Use wolfSSH" OFF) 1341mark_as_advanced(CURL_USE_WOLFSSH) 1342set(USE_WOLFSSH OFF) 1343if(NOT USE_LIBSSH2 AND NOT USE_LIBSSH AND CURL_USE_WOLFSSH) 1344 if(USE_WOLFSSL) 1345 find_package(WolfSSH) 1346 if(WOLFSSH_FOUND) 1347 list(APPEND CURL_LIBS ${WOLFSSH_LIBRARIES}) 1348 include_directories(SYSTEM ${WOLFSSH_INCLUDE_DIRS}) 1349 set(USE_WOLFSSH ON) 1350 endif() 1351 else() 1352 message(WARNING "wolfSSH requires wolfSSL. Skipping.") 1353 endif() 1354endif() 1355 1356option(CURL_USE_GSASL "Use libgsasl" OFF) 1357mark_as_advanced(CURL_USE_GSASL) 1358if(CURL_USE_GSASL) 1359 find_package(Libgsasl REQUIRED) 1360 list(APPEND CURL_LIBS ${LIBGSASL_LIBRARIES}) 1361 list(APPEND CURL_LIBDIRS ${LIBGSASL_LIBRARY_DIRS}) 1362 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBGSASL_PC_REQUIRES}) 1363 include_directories(SYSTEM ${LIBGSASL_INCLUDE_DIRS}) 1364 link_directories(${LIBGSASL_LIBRARY_DIRS}) 1365 if(LIBGSASL_CFLAGS) 1366 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBGSASL_CFLAGS}") 1367 endif() 1368 set(USE_GSASL ON) 1369endif() 1370 1371option(CURL_USE_GSSAPI "Use GSSAPI implementation" OFF) 1372mark_as_advanced(CURL_USE_GSSAPI) 1373 1374if(CURL_USE_GSSAPI) 1375 find_package(GSS) 1376 1377 set(HAVE_GSSAPI ${GSS_FOUND}) 1378 if(GSS_FOUND) 1379 list(APPEND CURL_LIBS ${GSS_LIBRARIES}) 1380 list(APPEND CURL_LIBDIRS ${GSS_LIBRARY_DIRS}) 1381 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${GSS_PC_REQUIRES}) 1382 include_directories(SYSTEM ${GSS_INCLUDE_DIRS}) 1383 link_directories(${GSS_LIBRARY_DIRS}) 1384 if(GSS_CFLAGS) 1385 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_CFLAGS}") 1386 endif() 1387 1388 if(GSS_FLAVOUR STREQUAL "GNU") 1389 set(HAVE_GSSGNU 1) 1390 else() 1391 cmake_push_check_state() 1392 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRS}) 1393 1394 set(_include_list "") 1395 check_include_file("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H) 1396 if(HAVE_GSSAPI_GSSAPI_H) 1397 list(APPEND _include_list "gssapi/gssapi.h") 1398 endif() 1399 check_include_files("${_include_list};gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H) 1400 1401 if(GSS_FLAVOUR STREQUAL "MIT") 1402 check_include_files("${_include_list};gssapi/gssapi_krb5.h" _have_gssapi_gssapi_krb5_h) 1403 if(HAVE_GSSAPI_GSSAPI_GENERIC_H) 1404 list(APPEND _include_list "gssapi/gssapi_generic.h") 1405 endif() 1406 if(_have_gssapi_gssapi_krb5_h) 1407 list(APPEND _include_list "gssapi/gssapi_krb5.h") 1408 endif() 1409 1410 if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE) 1411 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${GSS_CFLAGS}") 1412 list(APPEND CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES}) 1413 curl_required_libpaths("${GSS_LIBRARY_DIRS}") 1414 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" "${_include_list}" HAVE_GSS_C_NT_HOSTBASED_SERVICE) 1415 endif() 1416 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE) 1417 set(HAVE_OLD_GSSMIT ON) 1418 endif() 1419 endif() 1420 unset(_include_list) 1421 cmake_pop_check_state() 1422 endif() 1423 else() 1424 message(WARNING "GSSAPI has been requested, but no supporting libraries found. Skipping.") 1425 endif() 1426endif() 1427 1428# libuv 1429option(CURL_USE_LIBUV "Use libuv for event-based tests" OFF) 1430if(CURL_USE_LIBUV) 1431 if(NOT ENABLE_DEBUG) 1432 message(FATAL_ERROR "Using libuv without debug support enabled is useless") 1433 endif() 1434 find_package(Libuv REQUIRED) 1435 list(APPEND CURL_LIBS ${LIBUV_LIBRARIES}) 1436 list(APPEND CURL_LIBDIRS ${LIBUV_LIBRARY_DIRS}) 1437 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBUV_PC_REQUIRES}) 1438 include_directories(SYSTEM ${LIBUV_INCLUDE_DIRS}) 1439 link_directories(${LIBUV_LIBRARY_DIRS}) 1440 if(LIBUV_CFLAGS) 1441 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUV_CFLAGS}") 1442 endif() 1443 set(USE_LIBUV ON) 1444 set(HAVE_UV_H ON) 1445endif() 1446 1447option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF) 1448if(USE_LIBRTMP) 1449 find_package(Librtmp REQUIRED) 1450 list(APPEND CURL_LIBS ${LIBRTMP_LIBRARIES}) 1451 list(APPEND CURL_LIBDIRS ${LIBRTMP_LIBRARY_DIRS}) 1452 list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBRTMP_PC_REQUIRES}) 1453 include_directories(SYSTEM ${LIBRTMP_INCLUDE_DIRS}) 1454 link_directories(${LIBRTMP_LIBRARY_DIRS}) 1455 if(LIBRTMP_CFLAGS) 1456 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBRTMP_CFLAGS}") 1457 endif() 1458endif() 1459 1460option(ENABLE_UNIX_SOCKETS "Enable Unix domain sockets support" ON) 1461if(ENABLE_UNIX_SOCKETS) 1462 if(WIN32 OR DOS) 1463 set(USE_UNIX_SOCKETS ON) 1464 else() 1465 include(CheckStructHasMember) 1466 check_struct_has_member("struct sockaddr_un" "sun_path" "sys/un.h" USE_UNIX_SOCKETS) 1467 endif() 1468else() 1469 unset(USE_UNIX_SOCKETS CACHE) 1470endif() 1471 1472# 1473# CA handling 1474# 1475if(_curl_ca_bundle_supported) 1476 set(CURL_CA_BUNDLE "auto" CACHE 1477 STRING "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 1478 set(CURL_CA_FALLBACK OFF CACHE 1479 BOOL "Use built-in CA store of TLS backend. Defaults to OFF") 1480 set(CURL_CA_PATH "auto" CACHE 1481 STRING "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 1482 set(CURL_CA_EMBED "" CACHE 1483 STRING "Path to the CA bundle to embed in the curl tool.") 1484 1485 if(CURL_CA_BUNDLE STREQUAL "") 1486 message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.") 1487 elseif(CURL_CA_BUNDLE STREQUAL "none") 1488 unset(CURL_CA_BUNDLE CACHE) 1489 elseif(CURL_CA_BUNDLE STREQUAL "auto") 1490 unset(CURL_CA_BUNDLE CACHE) 1491 if(NOT CMAKE_CROSSCOMPILING AND NOT WIN32) 1492 set(_curl_ca_bundle_autodetect TRUE) 1493 endif() 1494 else() 1495 set(CURL_CA_BUNDLE_SET TRUE) 1496 endif() 1497 mark_as_advanced(CURL_CA_BUNDLE_SET) 1498 1499 if(CURL_CA_PATH STREQUAL "") 1500 message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.") 1501 elseif(CURL_CA_PATH STREQUAL "none") 1502 unset(CURL_CA_PATH CACHE) 1503 elseif(CURL_CA_PATH STREQUAL "auto") 1504 unset(CURL_CA_PATH CACHE) 1505 if(NOT CMAKE_CROSSCOMPILING AND NOT WIN32) 1506 set(_curl_ca_path_autodetect TRUE) 1507 endif() 1508 else() 1509 set(CURL_CA_PATH_SET TRUE) 1510 endif() 1511 mark_as_advanced(CURL_CA_PATH_SET) 1512 1513 if(CURL_CA_BUNDLE_SET AND _curl_ca_path_autodetect) 1514 # Skip auto-detection of unset CA path because CA bundle is set explicitly 1515 elseif(CURL_CA_PATH_SET AND _curl_ca_bundle_autodetect) 1516 # Skip auto-detection of unset CA bundle because CA path is set explicitly 1517 elseif(_curl_ca_bundle_autodetect OR _curl_ca_path_autodetect) 1518 # First try auto-detecting a CA bundle, then a CA path 1519 1520 if(_curl_ca_bundle_autodetect) 1521 foreach(_search_ca_bundle_path IN ITEMS 1522 "/etc/ssl/certs/ca-certificates.crt" 1523 "/etc/pki/tls/certs/ca-bundle.crt" 1524 "/usr/share/ssl/certs/ca-bundle.crt" 1525 "/usr/local/share/certs/ca-root-nss.crt" 1526 "/etc/ssl/cert.pem") 1527 if(EXISTS "${_search_ca_bundle_path}") 1528 message(STATUS "Found CA bundle: ${_search_ca_bundle_path}") 1529 set(CURL_CA_BUNDLE "${_search_ca_bundle_path}" CACHE 1530 STRING "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 1531 set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set") 1532 break() 1533 endif() 1534 endforeach() 1535 endif() 1536 1537 if(_curl_ca_path_autodetect AND NOT CURL_CA_PATH_SET) 1538 set(_search_ca_path "/etc/ssl/certs") 1539 file(GLOB _curl_ca_files_found "${_search_ca_path}/[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].0") 1540 if(_curl_ca_files_found) 1541 unset(_curl_ca_files_found) 1542 message(STATUS "Found CA path: ${_search_ca_path}") 1543 set(CURL_CA_PATH "${_search_ca_path}" CACHE 1544 STRING "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 1545 set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set") 1546 endif() 1547 endif() 1548 endif() 1549 1550 set(CURL_CA_EMBED_SET FALSE) 1551 if(BUILD_CURL_EXE AND NOT CURL_CA_EMBED STREQUAL "") 1552 if(EXISTS "${CURL_CA_EMBED}") 1553 set(CURL_CA_EMBED_SET TRUE) 1554 message(STATUS "Found CA bundle to embed: ${CURL_CA_EMBED}") 1555 else() 1556 message(FATAL_ERROR "CA bundle to embed is missing: '${CURL_CA_EMBED}'") 1557 endif() 1558 endif() 1559endif() 1560 1561if(WIN32) 1562 option(CURL_DISABLE_CA_SEARCH "Disable unsafe CA bundle search in PATH on Windows" OFF) 1563 option(CURL_CA_SEARCH_SAFE "Enable safe CA bundle search (within the curl tool directory) on Windows" OFF) 1564endif() 1565 1566# Check for header files 1567if(WIN32) 1568 list(APPEND CURL_INCLUDES "winsock2.h") 1569 list(APPEND CURL_INCLUDES "ws2tcpip.h") 1570 1571 if(HAVE_WIN32_WINNT) 1572 if(HAVE_WIN32_WINNT LESS 0x0501) 1573 # Windows XP is required for freeaddrinfo, getaddrinfo 1574 message(FATAL_ERROR "Building for Windows XP or newer is required.") 1575 endif() 1576 1577 # Pre-fill detection results based on target OS version 1578 if(MINGW OR MSVC) 1579 if(HAVE_WIN32_WINNT LESS 0x0600) 1580 set(HAVE_INET_NTOP 0) 1581 set(HAVE_INET_PTON 0) 1582 else() # Windows Vista or newer 1583 set(HAVE_INET_NTOP 1) 1584 set(HAVE_INET_PTON 1) 1585 endif() 1586 unset(HAVE_INET_NTOP CACHE) 1587 unset(HAVE_INET_PTON CACHE) 1588 endif() 1589 endif() 1590endif() 1591 1592# Detect headers 1593 1594# Use check_include_file_concat_curl() for headers required by subsequent 1595# check_include_file_concat_curl() or check_symbol_exists() detections. 1596# Order for these is significant. 1597check_include_file("sys/eventfd.h" HAVE_SYS_EVENTFD_H) 1598check_include_file("sys/filio.h" HAVE_SYS_FILIO_H) 1599check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) 1600check_include_file("sys/param.h" HAVE_SYS_PARAM_H) 1601check_include_file("sys/poll.h" HAVE_SYS_POLL_H) 1602check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H) 1603check_include_file_concat_curl("sys/select.h" HAVE_SYS_SELECT_H) 1604check_include_file_concat_curl("sys/socket.h" HAVE_SYS_SOCKET_H) 1605check_include_file("sys/sockio.h" HAVE_SYS_SOCKIO_H) 1606check_include_file("sys/stat.h" HAVE_SYS_STAT_H) 1607check_include_file_concat_curl("sys/time.h" HAVE_SYS_TIME_H) 1608check_include_file_concat_curl("sys/types.h" HAVE_SYS_TYPES_H) 1609check_include_file("sys/un.h" HAVE_SYS_UN_H) 1610check_include_file_concat_curl("sys/utime.h" HAVE_SYS_UTIME_H) # sys/types.h (AmigaOS) 1611 1612check_include_file_concat_curl("arpa/inet.h" HAVE_ARPA_INET_H) 1613check_include_file("dirent.h" HAVE_DIRENT_H) 1614check_include_file("fcntl.h" HAVE_FCNTL_H) 1615check_include_file_concat_curl("ifaddrs.h" HAVE_IFADDRS_H) 1616check_include_file("io.h" HAVE_IO_H) 1617check_include_file_concat_curl("libgen.h" HAVE_LIBGEN_H) 1618check_include_file("linux/tcp.h" HAVE_LINUX_TCP_H) 1619check_include_file("locale.h" HAVE_LOCALE_H) 1620check_include_file_concat_curl("net/if.h" HAVE_NET_IF_H) # sys/select.h (e.g. MS-DOS/Watt-32) 1621check_include_file_concat_curl("netdb.h" HAVE_NETDB_H) 1622check_include_file_concat_curl("netinet/in.h" HAVE_NETINET_IN_H) 1623check_include_file("netinet/in6.h" HAVE_NETINET_IN6_H) 1624check_include_file_concat_curl("netinet/tcp.h" HAVE_NETINET_TCP_H) # sys/types.h (e.g. Cygwin) netinet/in.h 1625check_include_file_concat_curl("netinet/udp.h" HAVE_NETINET_UDP_H) # sys/types.h (e.g. Cygwin) 1626check_include_file("poll.h" HAVE_POLL_H) 1627check_include_file("pwd.h" HAVE_PWD_H) 1628check_include_file("stdatomic.h" HAVE_STDATOMIC_H) 1629check_include_file("stdbool.h" HAVE_STDBOOL_H) 1630check_include_file("strings.h" HAVE_STRINGS_H) 1631check_include_file("stropts.h" HAVE_STROPTS_H) 1632check_include_file("termio.h" HAVE_TERMIO_H) 1633check_include_file("termios.h" HAVE_TERMIOS_H) 1634check_include_file_concat_curl("unistd.h" HAVE_UNISTD_H) 1635check_include_file("utime.h" HAVE_UTIME_H) 1636 1637if(AMIGA) 1638 check_include_file_concat_curl("proto/bsdsocket.h" HAVE_PROTO_BSDSOCKET_H) 1639endif() 1640 1641# Pass these detection results to curl_internal_test() for use in CurlTests.c 1642# Add here all feature flags referenced from CurlTests.c 1643foreach(_variable IN ITEMS 1644 HAVE_STDATOMIC_H 1645 HAVE_STDBOOL_H 1646 HAVE_STROPTS_H 1647 HAVE_SYS_IOCTL_H 1648 HAVE_SYS_SOCKET_H 1649 HAVE_SYS_TYPES_H 1650 HAVE_UNISTD_H 1651 ) 1652 if(${_variable}) 1653 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${_variable}") 1654 endif() 1655endforeach() 1656 1657check_type_size("size_t" SIZEOF_SIZE_T) 1658check_type_size("ssize_t" SIZEOF_SSIZE_T) 1659check_type_size("long long" SIZEOF_LONG_LONG) 1660check_type_size("long" SIZEOF_LONG) 1661check_type_size("int" SIZEOF_INT) 1662check_type_size("__int64" SIZEOF___INT64) 1663check_type_size("time_t" SIZEOF_TIME_T) 1664check_type_size("suseconds_t" SIZEOF_SUSECONDS_T) 1665if(NOT HAVE_SIZEOF_SSIZE_T) 1666 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T) 1667 set(ssize_t "long") 1668 endif() 1669 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T) 1670 set(ssize_t "__int64") 1671 endif() 1672endif() 1673# off_t is sized later, after the HAVE_FILE_OFFSET_BITS test 1674 1675if(SIZEOF_LONG_LONG) 1676 set(HAVE_LONGLONG 1) 1677endif() 1678if(SIZEOF_SUSECONDS_T) 1679 set(HAVE_SUSECONDS_T 1) 1680endif() 1681 1682# Check for some functions that are used 1683 1684# Apply to all feature checks 1685if(WIN32) 1686 list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32") 1687elseif(HAVE_LIBSOCKET) 1688 list(APPEND CMAKE_REQUIRED_LIBRARIES "socket") 1689elseif(DOS) 1690 list(APPEND CMAKE_REQUIRED_LIBRARIES "${WATT_ROOT}/lib/libwatt.a") 1691endif() 1692 1693check_function_exists("fnmatch" HAVE_FNMATCH) 1694check_symbol_exists("basename" "${CURL_INCLUDES};string.h" HAVE_BASENAME) # libgen.h unistd.h 1695check_symbol_exists("opendir" "dirent.h" HAVE_OPENDIR) 1696check_function_exists("poll" HAVE_POLL) # poll.h 1697check_symbol_exists("socket" "${CURL_INCLUDES}" HAVE_SOCKET) # winsock2.h sys/socket.h 1698check_symbol_exists("socketpair" "${CURL_INCLUDES}" HAVE_SOCKETPAIR) # sys/socket.h 1699check_symbol_exists("recv" "${CURL_INCLUDES}" HAVE_RECV) # proto/bsdsocket.h sys/types.h sys/socket.h 1700check_symbol_exists("send" "${CURL_INCLUDES}" HAVE_SEND) # proto/bsdsocket.h sys/types.h sys/socket.h 1701check_function_exists("sendmsg" HAVE_SENDMSG) 1702check_function_exists("sendmmsg" HAVE_SENDMMSG) 1703check_symbol_exists("select" "${CURL_INCLUDES}" HAVE_SELECT) # proto/bsdsocket.h sys/select.h sys/socket.h 1704check_symbol_exists("strdup" "string.h" HAVE_STRDUP) 1705check_symbol_exists("strtok_r" "string.h" HAVE_STRTOK_R) 1706check_symbol_exists("memrchr" "string.h" HAVE_MEMRCHR) 1707check_symbol_exists("alarm" "unistd.h" HAVE_ALARM) 1708check_symbol_exists("fcntl" "fcntl.h" HAVE_FCNTL) 1709check_function_exists("getppid" HAVE_GETPPID) 1710check_function_exists("utimes" HAVE_UTIMES) 1711 1712check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY) # sys/time.h 1713check_symbol_exists("closesocket" "${CURL_INCLUDES}" HAVE_CLOSESOCKET) # winsock2.h 1714check_symbol_exists("sigsetjmp" "setjmp.h" HAVE_SIGSETJMP) 1715check_function_exists("getpass_r" HAVE_GETPASS_R) 1716check_function_exists("getpwuid" HAVE_GETPWUID) 1717check_function_exists("getpwuid_r" HAVE_GETPWUID_R) 1718check_function_exists("geteuid" HAVE_GETEUID) 1719check_function_exists("utime" HAVE_UTIME) 1720check_symbol_exists("gmtime_r" "stdlib.h;time.h" HAVE_GMTIME_R) 1721 1722check_symbol_exists("gethostbyname_r" "netdb.h" HAVE_GETHOSTBYNAME_R) 1723check_symbol_exists("gethostname" "${CURL_INCLUDES}" HAVE_GETHOSTNAME) # winsock2.h unistd.h proto/bsdsocket.h 1724 1725check_symbol_exists("signal" "signal.h" HAVE_SIGNAL) 1726check_symbol_exists("strtoll" "stdlib.h" HAVE_STRTOLL) 1727check_symbol_exists("strerror_r" "stdlib.h;string.h" HAVE_STRERROR_R) 1728check_symbol_exists("sigaction" "signal.h" HAVE_SIGACTION) 1729check_symbol_exists("siginterrupt" "signal.h" HAVE_SIGINTERRUPT) 1730check_symbol_exists("getaddrinfo" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_GETADDRINFO) # ws2tcpip.h sys/socket.h netdb.h 1731check_symbol_exists("getifaddrs" "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS) # ifaddrs.h 1732check_symbol_exists("freeaddrinfo" "${CURL_INCLUDES}" HAVE_FREEADDRINFO) # ws2tcpip.h sys/socket.h netdb.h 1733check_function_exists("pipe" HAVE_PIPE) 1734check_function_exists("eventfd" HAVE_EVENTFD) 1735check_symbol_exists("ftruncate" "unistd.h" HAVE_FTRUNCATE) 1736check_symbol_exists("getpeername" "${CURL_INCLUDES}" HAVE_GETPEERNAME) # winsock2.h unistd.h proto/bsdsocket.h 1737check_symbol_exists("getsockname" "${CURL_INCLUDES}" HAVE_GETSOCKNAME) # winsock2.h unistd.h proto/bsdsocket.h 1738check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # winsock2.h net/if.h 1739check_function_exists("getrlimit" HAVE_GETRLIMIT) 1740check_function_exists("setlocale" HAVE_SETLOCALE) 1741check_function_exists("setmode" HAVE_SETMODE) 1742check_function_exists("setrlimit" HAVE_SETRLIMIT) 1743 1744if(NOT WIN32) 1745 check_function_exists("sched_yield" HAVE_SCHED_YIELD) 1746 check_symbol_exists("strcasecmp" "string.h" HAVE_STRCASECMP) 1747 check_symbol_exists("stricmp" "string.h" HAVE_STRICMP) 1748 check_symbol_exists("strcmpi" "string.h" HAVE_STRCMPI) 1749endif() 1750 1751if(WIN32 OR CYGWIN) 1752 check_function_exists("_setmode" HAVE__SETMODE) 1753endif() 1754 1755if(AMIGA) 1756 check_symbol_exists("CloseSocket" "${CURL_INCLUDES}" HAVE_CLOSESOCKET_CAMEL) # sys/socket.h proto/bsdsocket.h 1757endif() 1758 1759if(NOT _ssl_enabled) 1760 check_symbol_exists("arc4random" "${CURL_INCLUDES};stdlib.h" HAVE_ARC4RANDOM) 1761endif() 1762 1763if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900)) 1764 # Earlier MSVC compilers had faulty snprintf implementations 1765 check_function_exists("snprintf" HAVE_SNPRINTF) 1766endif() 1767if(APPLE) 1768 check_function_exists("mach_absolute_time" HAVE_MACH_ABSOLUTE_TIME) 1769endif() 1770check_symbol_exists("inet_ntop" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP) # arpa/inet.h 1771check_symbol_exists("inet_pton" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON) # arpa/inet.h 1772 1773check_symbol_exists("fsetxattr" "sys/xattr.h" HAVE_FSETXATTR) 1774if(HAVE_FSETXATTR) 1775 curl_internal_test(HAVE_FSETXATTR_5) 1776 curl_internal_test(HAVE_FSETXATTR_6) 1777endif() 1778 1779cmake_push_check_state() 1780if(WIN32) 1781 list(APPEND CMAKE_EXTRA_INCLUDE_FILES "winsock2.h") 1782 check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY) 1783 set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY}) 1784elseif(HAVE_SYS_SOCKET_H) 1785 list(APPEND CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h") 1786 check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T) 1787 set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T}) 1788endif() 1789cmake_pop_check_state() 1790 1791# Do curl specific tests 1792foreach(_curl_test IN ITEMS 1793 HAVE_FCNTL_O_NONBLOCK 1794 HAVE_IOCTLSOCKET 1795 HAVE_IOCTLSOCKET_CAMEL 1796 HAVE_IOCTLSOCKET_CAMEL_FIONBIO 1797 HAVE_IOCTLSOCKET_FIONBIO 1798 HAVE_IOCTL_FIONBIO 1799 HAVE_IOCTL_SIOCGIFADDR 1800 HAVE_SETSOCKOPT_SO_NONBLOCK 1801 HAVE_GETHOSTBYNAME_R_3 1802 HAVE_GETHOSTBYNAME_R_5 1803 HAVE_GETHOSTBYNAME_R_6 1804 HAVE_GETHOSTBYNAME_R_3_REENTRANT 1805 HAVE_GETHOSTBYNAME_R_5_REENTRANT 1806 HAVE_GETHOSTBYNAME_R_6_REENTRANT 1807 HAVE_IN_ADDR_T 1808 HAVE_BOOL_T 1809 STDC_HEADERS 1810 HAVE_FILE_OFFSET_BITS 1811 HAVE_ATOMIC 1812 ) 1813 curl_internal_test(${_curl_test}) 1814endforeach() 1815 1816cmake_push_check_state() 1817if(HAVE_FILE_OFFSET_BITS) 1818 set(_FILE_OFFSET_BITS 64) 1819 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64") 1820endif() 1821check_type_size("off_t" SIZEOF_OFF_T) 1822 1823if(NOT WIN32) 1824 # fseeko may not exist with _FILE_OFFSET_BITS=64 but can exist with 1825 # _FILE_OFFSET_BITS unset or 32 (e.g. Android ARMv7 with NDK 26b and API level < 24) 1826 # so we need to test fseeko after testing for _FILE_OFFSET_BITS 1827 check_symbol_exists("fseeko" "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO) 1828 1829 if(HAVE_FSEEKO) 1830 set(HAVE_DECL_FSEEKO 1) 1831 endif() 1832endif() 1833 1834# Include this header to get the type 1835cmake_push_check_state() 1836list(APPEND CMAKE_REQUIRED_INCLUDES "${PROJECT_SOURCE_DIR}/include") 1837list(APPEND CMAKE_EXTRA_INCLUDE_FILES "curl/system.h") 1838check_type_size("curl_off_t" SIZEOF_CURL_OFF_T) 1839list(APPEND CMAKE_EXTRA_INCLUDE_FILES "curl/curl.h") 1840check_type_size("curl_socket_t" SIZEOF_CURL_SOCKET_T) 1841cmake_pop_check_state() # pop curl system headers 1842cmake_pop_check_state() # pop -D_FILE_OFFSET_BITS=64 1843 1844if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING) 1845 # On non-Windows and not cross-compiling, check for writable argv[] 1846 include(CheckCSourceRuns) 1847 check_c_source_runs(" 1848 int main(int argc, char **argv) 1849 { 1850 (void)argc; 1851 argv[0][0] = ' '; 1852 return (argv[0][0] == ' ')?0:1; 1853 }" HAVE_WRITABLE_ARGV) 1854endif() 1855 1856if(NOT CMAKE_CROSSCOMPILING) 1857 include(CheckCSourceRuns) 1858 check_c_source_runs(" 1859 #include <time.h> 1860 int main(void) { 1861 time_t t = -1; 1862 return t < 0; 1863 }" HAVE_TIME_T_UNSIGNED) 1864endif() 1865 1866curl_internal_test(HAVE_GLIBC_STRERROR_R) 1867curl_internal_test(HAVE_POSIX_STRERROR_R) 1868 1869# Check for reentrant 1870foreach(_curl_test IN ITEMS 1871 HAVE_GETHOSTBYNAME_R_3 1872 HAVE_GETHOSTBYNAME_R_5 1873 HAVE_GETHOSTBYNAME_R_6) 1874 if(NOT ${_curl_test}) 1875 if(${_curl_test}_REENTRANT) 1876 set(NEED_REENTRANT 1) 1877 endif() 1878 endif() 1879endforeach() 1880 1881if(NEED_REENTRANT) 1882 foreach(_curl_test IN ITEMS 1883 HAVE_GETHOSTBYNAME_R_3 1884 HAVE_GETHOSTBYNAME_R_5 1885 HAVE_GETHOSTBYNAME_R_6) 1886 set(${_curl_test} 0) 1887 if(${_curl_test}_REENTRANT) 1888 set(${_curl_test} 1) 1889 endif() 1890 endforeach() 1891endif() 1892 1893if(NOT WIN32) 1894 curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC) # Check clock_gettime(CLOCK_MONOTONIC, x) support 1895endif() 1896 1897if(APPLE) 1898 curl_internal_test(HAVE_BUILTIN_AVAILABLE) # Check compiler support of __builtin_available() 1899endif() 1900 1901# Some other minor tests 1902 1903if(NOT HAVE_IN_ADDR_T) 1904 set(in_addr_t "unsigned long") 1905endif() 1906 1907if(CMAKE_COMPILER_IS_GNUCC AND APPLE) 1908 include(CheckCCompilerFlag) 1909 check_c_compiler_flag("-Wno-long-double" HAVE_C_FLAG_Wno_long_double) 1910 if(HAVE_C_FLAG_Wno_long_double) 1911 # The Mac version of GCC warns about use of long double. Disable it. 1912 get_source_file_property(_mprintf_compile_flags "mprintf.c" COMPILE_FLAGS) 1913 if(_mprintf_compile_flags) 1914 set(_mprintf_compile_flags "${_mprintf_compile_flags} -Wno-long-double") 1915 else() 1916 set(_mprintf_compile_flags "-Wno-long-double") 1917 endif() 1918 set_source_files_properties("mprintf.c" PROPERTIES 1919 COMPILE_FLAGS ${_mprintf_compile_flags}) 1920 endif() 1921endif() 1922 1923if(_cmake_try_compile_target_type_save) 1924 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_cmake_try_compile_target_type_save}) 1925 unset(_cmake_try_compile_target_type_save) 1926endif() 1927 1928include(CMake/OtherTests.cmake) 1929 1930add_definitions("-DHAVE_CONFIG_H") 1931 1932if(WIN32) 1933 # _fseeki64() requires VS2005 1934 if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1400)) 1935 set(USE_WIN32_LARGE_FILES ON) 1936 endif() 1937 1938 # Use the manifest embedded in the Windows Resource 1939 set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST") 1940 1941 # We use crypto functions that are not available for UWP apps 1942 if(NOT WINDOWS_STORE) 1943 set(USE_WIN32_CRYPTO ON) 1944 endif() 1945 1946 # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL 1947 if(USE_WIN32_CRYPTO OR USE_SCHANNEL) 1948 list(APPEND CURL_LIBS "advapi32" "crypt32") 1949 endif() 1950endif() 1951 1952if(MSVC) 1953 # Disable default manifest added by CMake 1954 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -MANIFEST:NO") 1955 1956 if(CMAKE_C_FLAGS MATCHES "[/-]W[0-4]") 1957 string(REGEX REPLACE "[/-]W[0-4]" "-W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 1958 else() 1959 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4") 1960 endif() 1961 1962 # Use multithreaded compilation on VS2008+ 1963 if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1500) 1964 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MP") 1965 endif() 1966endif() 1967 1968if(CURL_WERROR) 1969 if(MSVC) 1970 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -WX") 1971 else() 1972 # This assumes clang or gcc style options 1973 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") 1974 endif() 1975endif() 1976 1977if(CURL_LTO) 1978 if(CMAKE_VERSION VERSION_LESS 3.9) 1979 message(FATAL_ERROR "LTO has been requested, but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9") 1980 endif() 1981 1982 cmake_policy(SET CMP0069 NEW) 1983 1984 include(CheckIPOSupported) 1985 check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT _lto_error LANGUAGES C) 1986 if(CURL_HAS_LTO) 1987 message(STATUS "LTO supported and enabled") 1988 else() 1989 message(FATAL_ERROR "LTO has been requested, but the compiler does not support it\n${_lto_error}") 1990 endif() 1991endif() 1992 1993 1994# Ugly (but functional) way to include "Makefile.inc" by transforming it 1995# (= regenerate it). 1996function(curl_transform_makefile_inc _input_file _output_file) 1997 file(READ ${_input_file} _makefile_inc_text) 1998 string(REPLACE "$(top_srcdir)" "\${PROJECT_SOURCE_DIR}" _makefile_inc_text ${_makefile_inc_text}) 1999 string(REPLACE "$(top_builddir)" "\${PROJECT_BINARY_DIR}" _makefile_inc_text ${_makefile_inc_text}) 2000 2001 string(REGEX REPLACE "\\\\\n" "!π!α!" _makefile_inc_text ${_makefile_inc_text}) 2002 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "set(\\1 \\2)" _makefile_inc_text ${_makefile_inc_text}) 2003 string(REPLACE "!π!α!" "\n" _makefile_inc_text ${_makefile_inc_text}) 2004 2005 # Replace $() with ${} 2006 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" _makefile_inc_text ${_makefile_inc_text}) 2007 # Replace @@ with ${}, even if that may not be read by CMake scripts. 2008 string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" _makefile_inc_text ${_makefile_inc_text}) 2009 2010 file(WRITE ${_output_file} ${_makefile_inc_text}) 2011 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_input_file}") 2012endfunction() 2013 2014include(GNUInstallDirs) 2015 2016set(_install_cmake_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") 2017set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") 2018set(_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") 2019set(_project_config "${_generated_dir}/${PROJECT_NAME}Config.cmake") 2020set(_version_config "${_generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") 2021 2022option(BUILD_TESTING "Build tests" ON) 2023if(BUILD_TESTING AND PERL_FOUND AND NOT CURL_DISABLE_TESTS) 2024 set(CURL_BUILD_TESTING ON) 2025else() 2026 set(CURL_BUILD_TESTING OFF) 2027endif() 2028 2029if(HAVE_MANUAL_TOOLS) 2030 set(CURL_MANPAGE "${PROJECT_BINARY_DIR}/docs/cmdline-opts/curl.1") 2031 set(CURL_ASCIIPAGE "${PROJECT_BINARY_DIR}/docs/cmdline-opts/curl.txt") 2032 add_subdirectory(docs) 2033endif() 2034 2035add_subdirectory(lib) 2036 2037if(BUILD_CURL_EXE) 2038 add_subdirectory(src) 2039endif() 2040 2041option(BUILD_EXAMPLES "Build libcurl examples" ON) 2042if(BUILD_EXAMPLES) 2043 add_subdirectory(docs/examples) 2044endif() 2045 2046if(CURL_BUILD_TESTING) 2047 add_subdirectory(tests) 2048endif() 2049 2050# Helper to populate a list (_items) with a label when conditions 2051# (the remaining args) are satisfied 2052macro(curl_add_if _label) 2053 # Needs to be a macro to allow this indirection 2054 if(${ARGN}) 2055 set(_items ${_items} "${_label}") 2056 endif() 2057endmacro() 2058 2059# NTLM support requires crypto functions from various SSL libs. 2060# These conditions must match those in lib/curl_setup.h. 2061if(NOT CURL_DISABLE_NTLM AND 2062 (USE_OPENSSL OR 2063 USE_MBEDTLS OR 2064 USE_GNUTLS OR 2065 USE_SECTRANSP OR 2066 USE_WIN32_CRYPTO OR 2067 (USE_WOLFSSL AND HAVE_WOLFSSL_DES_ECB_ENCRYPT))) 2068 set(_use_curl_ntlm_core ON) 2069endif() 2070 2071# Clear list and try to detect available protocols 2072set(_items "") 2073curl_add_if("HTTP" NOT CURL_DISABLE_HTTP) 2074curl_add_if("HTTPS" NOT CURL_DISABLE_HTTP AND _ssl_enabled) 2075curl_add_if("FTP" NOT CURL_DISABLE_FTP) 2076curl_add_if("FTPS" NOT CURL_DISABLE_FTP AND _ssl_enabled) 2077curl_add_if("FILE" NOT CURL_DISABLE_FILE) 2078curl_add_if("TELNET" NOT CURL_DISABLE_TELNET) 2079curl_add_if("LDAP" NOT CURL_DISABLE_LDAP) 2080# CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS 2081curl_add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND 2082 ((USE_OPENLDAP AND _ssl_enabled) OR 2083 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL))) 2084curl_add_if("DICT" NOT CURL_DISABLE_DICT) 2085curl_add_if("TFTP" NOT CURL_DISABLE_TFTP) 2086curl_add_if("GOPHER" NOT CURL_DISABLE_GOPHER) 2087curl_add_if("GOPHERS" NOT CURL_DISABLE_GOPHER AND _ssl_enabled) 2088curl_add_if("POP3" NOT CURL_DISABLE_POP3) 2089curl_add_if("POP3S" NOT CURL_DISABLE_POP3 AND _ssl_enabled) 2090curl_add_if("IMAP" NOT CURL_DISABLE_IMAP) 2091curl_add_if("IMAPS" NOT CURL_DISABLE_IMAP AND _ssl_enabled) 2092curl_add_if("SMB" NOT CURL_DISABLE_SMB AND 2093 _use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4)) 2094curl_add_if("SMBS" NOT CURL_DISABLE_SMB AND _ssl_enabled AND 2095 _use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4)) 2096curl_add_if("SMTP" NOT CURL_DISABLE_SMTP) 2097curl_add_if("SMTPS" NOT CURL_DISABLE_SMTP AND _ssl_enabled) 2098curl_add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH OR USE_WOLFSSH) 2099curl_add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH OR USE_WOLFSSH) 2100curl_add_if("IPFS" NOT CURL_DISABLE_IPFS) 2101curl_add_if("IPNS" NOT CURL_DISABLE_IPFS) 2102curl_add_if("RTSP" NOT CURL_DISABLE_RTSP) 2103curl_add_if("RTMP" USE_LIBRTMP) 2104curl_add_if("MQTT" NOT CURL_DISABLE_MQTT) 2105curl_add_if("WS" NOT CURL_DISABLE_WEBSOCKETS) 2106curl_add_if("WSS" NOT CURL_DISABLE_WEBSOCKETS AND _ssl_enabled) 2107if(_items) 2108 list(SORT _items) 2109endif() 2110set(CURL_SUPPORTED_PROTOCOLS_LIST "${_items}") 2111string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}") 2112string(TOLOWER "${SUPPORT_PROTOCOLS}" _support_protocols_lower) 2113message(STATUS "Protocols: ${_support_protocols_lower}") 2114 2115# Clear list and try to detect available features 2116set(_items "") 2117curl_add_if("SSL" _ssl_enabled) 2118curl_add_if("IPv6" USE_IPV6) 2119curl_add_if("UnixSockets" USE_UNIX_SOCKETS) 2120curl_add_if("libz" HAVE_LIBZ) 2121curl_add_if("brotli" HAVE_BROTLI) 2122curl_add_if("gsasl" USE_GSASL) 2123curl_add_if("zstd" HAVE_ZSTD) 2124curl_add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32) 2125curl_add_if("asyn-rr" USE_ARES AND ENABLE_THREADED_RESOLVER) 2126curl_add_if("IDN" (HAVE_LIBIDN2 AND HAVE_IDN2_H) OR 2127 USE_WIN32_IDN OR 2128 USE_APPLE_IDN) 2129curl_add_if("Largefile" (SIZEOF_CURL_OFF_T GREATER 4) AND 2130 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES)) 2131curl_add_if("SSPI" USE_WINDOWS_SSPI) 2132curl_add_if("GSS-API" HAVE_GSSAPI) 2133curl_add_if("alt-svc" NOT CURL_DISABLE_ALTSVC) 2134curl_add_if("HSTS" NOT CURL_DISABLE_HSTS) 2135curl_add_if("SPNEGO" NOT CURL_DISABLE_NEGOTIATE_AUTH AND 2136 (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) 2137curl_add_if("Kerberos" NOT CURL_DISABLE_KERBEROS_AUTH AND 2138 (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) 2139curl_add_if("NTLM" NOT (CURL_DISABLE_NTLM) AND 2140 (_use_curl_ntlm_core OR USE_WINDOWS_SSPI)) 2141curl_add_if("TLS-SRP" USE_TLS_SRP) 2142curl_add_if("HTTP2" USE_NGHTTP2) 2143curl_add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE OR USE_MSH3 OR USE_OPENSSL_QUIC) 2144curl_add_if("MultiSSL" CURL_WITH_MULTI_SSL) 2145curl_add_if("HTTPS-proxy" _ssl_enabled AND (USE_OPENSSL OR USE_GNUTLS 2146 OR USE_SCHANNEL OR USE_RUSTLS OR USE_BEARSSL OR 2147 USE_MBEDTLS OR USE_SECTRANSP OR 2148 (USE_WOLFSSL AND HAVE_WOLFSSL_BIO))) 2149curl_add_if("Unicode" ENABLE_UNICODE) 2150curl_add_if("threadsafe" HAVE_ATOMIC OR 2151 (USE_THREADS_POSIX AND HAVE_PTHREAD_H) OR 2152 (WIN32 AND HAVE_WIN32_WINNT GREATER_EQUAL 0x0600)) 2153curl_add_if("Debug" ENABLE_DEBUG) 2154curl_add_if("TrackMemory" ENABLE_CURLDEBUG) 2155curl_add_if("ECH" _ssl_enabled AND HAVE_ECH) 2156curl_add_if("HTTPSRR" _ssl_enabled AND USE_HTTPSRR) 2157curl_add_if("PSL" USE_LIBPSL) 2158curl_add_if("CAcert" CURL_CA_EMBED_SET) 2159curl_add_if("SSLS-EXPORT" _ssl_enabled AND USE_SSLS_EXPORT) 2160if(_items) 2161 if(NOT CMAKE_VERSION VERSION_LESS 3.13) 2162 list(SORT _items CASE INSENSITIVE) 2163 else() 2164 list(SORT _items) 2165 endif() 2166endif() 2167set(CURL_SUPPORTED_FEATURES_LIST "${_items}") 2168string(REPLACE ";" " " SUPPORT_FEATURES "${_items}") 2169message(STATUS "Features: ${SUPPORT_FEATURES}") 2170 2171# Clear list and collect SSL backends 2172set(_items "") 2173curl_add_if("Schannel" _ssl_enabled AND USE_SCHANNEL) 2174curl_add_if("${_openssl}" _ssl_enabled AND USE_OPENSSL AND OPENSSL_VERSION VERSION_LESS 3.0.0) 2175curl_add_if("${_openssl} v3+" _ssl_enabled AND USE_OPENSSL AND NOT OPENSSL_VERSION VERSION_LESS 3.0.0) 2176curl_add_if("Secure Transport" _ssl_enabled AND USE_SECTRANSP) 2177curl_add_if("mbedTLS" _ssl_enabled AND USE_MBEDTLS) 2178curl_add_if("BearSSL" _ssl_enabled AND USE_BEARSSL) 2179curl_add_if("wolfSSL" _ssl_enabled AND USE_WOLFSSL) 2180curl_add_if("GnuTLS" _ssl_enabled AND USE_GNUTLS) 2181curl_add_if("rustls" _ssl_enabled AND USE_RUSTLS) 2182 2183if(_items) 2184 if(NOT CMAKE_VERSION VERSION_LESS 3.13) 2185 list(SORT _items CASE INSENSITIVE) 2186 else() 2187 list(SORT _items) 2188 endif() 2189endif() 2190string(REPLACE ";" " " SSL_BACKENDS "${_items}") 2191message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}") 2192if(CURL_DEFAULT_SSL_BACKEND) 2193 message(STATUS "Default SSL backend: ${CURL_DEFAULT_SSL_BACKEND}") 2194endif() 2195 2196if(NOT CURL_DISABLE_INSTALL) 2197 2198 # curl-config needs the following options to be set. 2199 set(CC "${CMAKE_C_COMPILER}") 2200 # TODO: probably put a -D... options here? 2201 set(CONFIGURE_OPTIONS "") 2202 set(CURLVERSION "${_curl_version}") 2203 set(VERSIONNUM "${_curl_version_num}") 2204 set(prefix "${CMAKE_INSTALL_PREFIX}") 2205 set(exec_prefix "\${prefix}") 2206 if(IS_ABSOLUTE ${CMAKE_INSTALL_INCLUDEDIR}) 2207 set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") 2208 else() 2209 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") 2210 endif() 2211 if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR}) 2212 set(libdir "${CMAKE_INSTALL_LIBDIR}") 2213 else() 2214 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") 2215 endif() 2216 # "a" (Linux) or "lib" (Windows) 2217 string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}") 2218 2219 set(_ldflags "") 2220 set(LIBCURL_PC_LIBS_PRIVATE "") 2221 2222 # Filter CMAKE_SHARED_LINKER_FLAGS for libs and libpaths 2223 string(STRIP "${CMAKE_SHARED_LINKER_FLAGS}" _custom_ldflags) 2224 string(REGEX REPLACE " +-([^ \\t;]*)" ";-\\1" _custom_ldflags "${_custom_ldflags}") 2225 2226 set(_custom_libs "") 2227 set(_custom_libdirs "") 2228 foreach(_flag IN LISTS _custom_ldflags) 2229 if(_flag MATCHES "^-l") 2230 string(REGEX REPLACE "^-l" "" _flag "${_flag}") 2231 list(APPEND _custom_libs "${_flag}") 2232 elseif(_flag MATCHES "^-framework|^-F") 2233 list(APPEND _custom_libs "${_flag}") 2234 elseif(_flag MATCHES "^-L") 2235 string(REGEX REPLACE "^-L" "" _flag "${_flag}") 2236 list(APPEND _custom_libdirs "${_flag}") 2237 elseif(_flag MATCHES "^--library-path=") 2238 string(REGEX REPLACE "^--library-path=" "" _flag "${_flag}") 2239 list(APPEND _custom_libdirs "${_flag}") 2240 endif() 2241 endforeach() 2242 2243 # Avoid getting unnecessary -L options for known system directories. 2244 set(_sys_libdirs "") 2245 foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH) 2246 if(_libdir MATCHES "/$") 2247 set(_libdir "${_libdir}lib") 2248 else() 2249 set(_libdir "${_libdir}/lib") 2250 endif() 2251 if(IS_DIRECTORY "${_libdir}") 2252 list(APPEND _sys_libdirs "${_libdir}") 2253 endif() 2254 if(DEFINED CMAKE_LIBRARY_ARCHITECTURE) 2255 set(_libdir "${_libdir}/${CMAKE_LIBRARY_ARCHITECTURE}") 2256 if(IS_DIRECTORY "${_libdir}") 2257 list(APPEND _sys_libdirs "${_libdir}") 2258 endif() 2259 endif() 2260 endforeach() 2261 2262 foreach(_libdir IN LISTS _custom_libdirs CURL_LIBDIRS) 2263 list(FIND _sys_libdirs "${_libdir}" _libdir_index) 2264 if(_libdir_index LESS 0) 2265 list(APPEND _ldflags "-L${_libdir}") 2266 endif() 2267 endforeach() 2268 2269 set(_implicit_libs "") 2270 if(NOT MINGW AND NOT UNIX) 2271 set(_implicit_libs ${CMAKE_C_IMPLICIT_LINK_LIBRARIES}) 2272 endif() 2273 2274 foreach(_lib IN LISTS _implicit_libs _custom_libs CURL_LIBS) 2275 if(TARGET "${_lib}") 2276 set(_libname "${_lib}") 2277 get_target_property(_imported "${_libname}" IMPORTED) 2278 if(NOT _imported) 2279 # Reading the LOCATION property on non-imported target will error out. 2280 # Assume the user will not need this information in the .pc file. 2281 continue() 2282 endif() 2283 get_target_property(_lib "${_libname}" LOCATION) 2284 if(NOT _lib) 2285 message(WARNING "Bad lib in library list: ${_libname}") 2286 continue() 2287 endif() 2288 endif() 2289 if(_lib MATCHES "^-") # '-framework <name>' 2290 list(APPEND _ldflags "${_lib}") 2291 elseif(_lib MATCHES "/") 2292 # This gets a bit more complex, because we want to specify the 2293 # directory separately, and only once per directory 2294 get_filename_component(_libdir ${_lib} DIRECTORY) 2295 get_filename_component(_libname ${_lib} NAME_WE) 2296 if(_libname MATCHES "^lib") 2297 list(FIND _sys_libdirs "${_libdir}" _libdir_index) 2298 if(_libdir_index LESS 0) 2299 list(APPEND _ldflags "-L${_libdir}") 2300 endif() 2301 string(REGEX REPLACE "^lib" "" _libname "${_libname}") 2302 list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_libname}") 2303 else() 2304 list(APPEND LIBCURL_PC_LIBS_PRIVATE "${_lib}") 2305 endif() 2306 else() 2307 list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_lib}") 2308 endif() 2309 endforeach() 2310 2311 if(LIBCURL_PC_REQUIRES_PRIVATE) 2312 string(REPLACE ";" "," LIBCURL_PC_REQUIRES_PRIVATE "${LIBCURL_PC_REQUIRES_PRIVATE}") 2313 endif() 2314 if(LIBCURL_PC_LIBS_PRIVATE) 2315 string(REPLACE ";" " " LIBCURL_PC_LIBS_PRIVATE "${LIBCURL_PC_LIBS_PRIVATE}") 2316 endif() 2317 if(_ldflags) 2318 list(REMOVE_DUPLICATES _ldflags) 2319 string(REPLACE ";" " " _ldflags "${_ldflags}") 2320 set(LIBCURL_PC_LDFLAGS_PRIVATE "${_ldflags}") 2321 string(STRIP "${LIBCURL_PC_LDFLAGS_PRIVATE}" LIBCURL_PC_LDFLAGS_PRIVATE) 2322 else() 2323 set(LIBCURL_PC_LDFLAGS_PRIVATE "") 2324 endif() 2325 set(LIBCURL_PC_CFLAGS_PRIVATE "-DCURL_STATICLIB") 2326 2327 # Merge pkg-config private fields into public ones when static-only 2328 if(BUILD_SHARED_LIBS) 2329 set(ENABLE_SHARED "yes") 2330 set(LIBCURL_PC_REQUIRES "") 2331 set(LIBCURL_PC_LIBS "") 2332 set(LIBCURL_PC_CFLAGS "") 2333 else() 2334 set(ENABLE_SHARED "no") 2335 set(LIBCURL_PC_REQUIRES "${LIBCURL_PC_REQUIRES_PRIVATE}") 2336 set(LIBCURL_PC_LIBS "${LIBCURL_PC_LIBS_PRIVATE}") 2337 set(LIBCURL_PC_CFLAGS "${LIBCURL_PC_CFLAGS_PRIVATE}") 2338 endif() 2339 if(BUILD_STATIC_LIBS) 2340 set(ENABLE_STATIC "yes") 2341 else() 2342 set(ENABLE_STATIC "no") 2343 endif() 2344 2345 # Generate a "curl-config" matching this config. 2346 # Consumed variables: 2347 # CC 2348 # CONFIGURE_OPTIONS 2349 # CURLVERSION 2350 # CURL_CA_BUNDLE 2351 # ENABLE_SHARED 2352 # ENABLE_STATIC 2353 # exec_prefix 2354 # includedir 2355 # LIBCURL_PC_CFLAGS 2356 # LIBCURL_PC_LDFLAGS_PRIVATE 2357 # LIBCURL_PC_LIBS_PRIVATE 2358 # libdir 2359 # libext 2360 # prefix 2361 # SSL_BACKENDS 2362 # SUPPORT_FEATURES 2363 # SUPPORT_PROTOCOLS 2364 # VERSIONNUM 2365 configure_file( 2366 "${PROJECT_SOURCE_DIR}/curl-config.in" 2367 "${PROJECT_BINARY_DIR}/curl-config" @ONLY) 2368 install(FILES "${PROJECT_BINARY_DIR}/curl-config" 2369 DESTINATION ${CMAKE_INSTALL_BINDIR} 2370 PERMISSIONS 2371 OWNER_READ OWNER_WRITE OWNER_EXECUTE 2372 GROUP_READ GROUP_EXECUTE 2373 WORLD_READ WORLD_EXECUTE) 2374 2375 # Generate a pkg-config file matching this config. 2376 # Consumed variables: 2377 # CURLVERSION 2378 # exec_prefix 2379 # includedir 2380 # LIBCURL_PC_CFLAGS 2381 # LIBCURL_PC_CFLAGS_PRIVATE 2382 # LIBCURL_PC_LDFLAGS_PRIVATE 2383 # LIBCURL_PC_LIBS 2384 # LIBCURL_PC_LIBS_PRIVATE 2385 # LIBCURL_PC_REQUIRES 2386 # LIBCURL_PC_REQUIRES_PRIVATE 2387 # libdir 2388 # prefix 2389 # SUPPORT_FEATURES 2390 # SUPPORT_PROTOCOLS 2391 # Documentation: 2392 # https://people.freedesktop.org/~dbn/pkg-config-guide.html 2393 # https://manpages.debian.org/unstable/pkgconf/pkg-config.1.en.html 2394 # https://manpages.debian.org/unstable/pkg-config/pkg-config.1.en.html 2395 # https://www.msys2.org/docs/pkgconfig/ 2396 configure_file( 2397 "${PROJECT_SOURCE_DIR}/libcurl.pc.in" 2398 "${PROJECT_BINARY_DIR}/libcurl.pc" @ONLY) 2399 install(FILES "${PROJECT_BINARY_DIR}/libcurl.pc" 2400 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 2401 2402 # Install headers 2403 install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/curl" 2404 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 2405 FILES_MATCHING PATTERN "*.h") 2406 2407 include(CMakePackageConfigHelpers) 2408 write_basic_package_version_file( 2409 "${_version_config}" 2410 VERSION ${_curl_version} 2411 COMPATIBILITY SameMajorVersion) 2412 file(READ "${_version_config}" _generated_version_config) 2413 file(WRITE "${_version_config}" " 2414 if(NOT PACKAGE_FIND_VERSION_RANGE AND PACKAGE_FIND_VERSION_MAJOR STREQUAL \"7\") 2415 # Version 8 satisfies version 7... requirements 2416 set(PACKAGE_FIND_VERSION_MAJOR 8) 2417 set(PACKAGE_FIND_VERSION_COUNT 1) 2418 endif() 2419 ${_generated_version_config}") 2420 2421 # Consumed custom variables: 2422 # CURLVERSION 2423 # LIB_SELECTED 2424 # TARGETS_EXPORT_NAME 2425 # USE_OPENSSL OPENSSL_VERSION_MAJOR 2426 # HAVE_LIBZ ZLIB_VERSION_MAJOR 2427 # CURL_SUPPORTED_FEATURES_LIST 2428 # CURL_SUPPORTED_PROTOCOLS_LIST 2429 configure_package_config_file("CMake/curl-config.cmake.in" 2430 "${_project_config}" 2431 INSTALL_DESTINATION ${_install_cmake_dir} 2432 PATH_VARS CMAKE_INSTALL_INCLUDEDIR) 2433 2434 if(CURL_ENABLE_EXPORT_TARGET) 2435 install(EXPORT "${TARGETS_EXPORT_NAME}" 2436 NAMESPACE "${PROJECT_NAME}::" 2437 DESTINATION ${_install_cmake_dir}) 2438 endif() 2439 2440 install(FILES ${_version_config} ${_project_config} 2441 DESTINATION ${_install_cmake_dir}) 2442 2443 if(NOT TARGET curl_uninstall) 2444 configure_file( 2445 "${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in" 2446 "${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake" 2447 @ONLY) 2448 2449 add_custom_target(curl_uninstall 2450 COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake") 2451 endif() 2452 2453 install(FILES "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl" 2454 DESTINATION ${CMAKE_INSTALL_BINDIR} 2455 PERMISSIONS 2456 OWNER_READ OWNER_WRITE OWNER_EXECUTE 2457 GROUP_READ GROUP_EXECUTE 2458 WORLD_READ WORLD_EXECUTE) 2459 2460 # The `-DEV` part is important 2461 string(REGEX REPLACE "([0-9]+\.[0-9]+)\.([0-9]+.*)" "\\2" CPACK_PACKAGE_VERSION_PATCH "${_curl_version}") 2462 set(CPACK_GENERATOR "TGZ") 2463 include(CPack) 2464endif() 2465 2466# Save build info for test runner to pick up and log 2467if(CMAKE_OSX_SYSROOT) 2468 set(_cmake_sysroot ${CMAKE_OSX_SYSROOT}) 2469elseif(CMAKE_SYSROOT) 2470 set(_cmake_sysroot ${CMAKE_SYSROOT}) 2471endif() 2472set(_buildinfo "\ 2473buildinfo.configure.tool: cmake 2474buildinfo.configure.command: ${CMAKE_COMMAND} 2475buildinfo.configure.version: ${CMAKE_VERSION} 2476buildinfo.configure.args:${_cmake_args} 2477buildinfo.configure.generator: ${CMAKE_GENERATOR} 2478buildinfo.configure.make: ${CMAKE_MAKE_PROGRAM} 2479buildinfo.host.cpu: ${CMAKE_HOST_SYSTEM_PROCESSOR} 2480buildinfo.host.os: ${CMAKE_HOST_SYSTEM_NAME} 2481buildinfo.target.cpu: ${CMAKE_SYSTEM_PROCESSOR} 2482buildinfo.target.os: ${CMAKE_SYSTEM_NAME} 2483buildinfo.target.flags:${_target_flags} 2484buildinfo.compiler: ${CMAKE_C_COMPILER_ID} 2485buildinfo.compiler.version: ${CMAKE_C_COMPILER_VERSION} 2486buildinfo.sysroot: ${_cmake_sysroot} 2487") 2488file(WRITE "${PROJECT_BINARY_DIR}/buildinfo.txt" "# This is a generated file. Do not edit.\n${_buildinfo}") 2489if(NOT "$ENV{CURL_BUILDINFO}$ENV{CURL_CI}$ENV{CI}" STREQUAL "") 2490 message(STATUS "\n${_buildinfo}") 2491endif() 2492