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