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# curl/libcurl CMake script 25# by Tetetest and Sukender (Benoit Neil) 26 27# TODO: 28# The output .so file lacks the soname number which we currently have within the lib/Makefile.am file 29# Add full (4 or 5 libs) SSL support 30# Add INSTALL target (EXTRA_DIST variables in Makefile.am may be moved to Makefile.inc so that CMake/CPack is aware of what's to include). 31# Check on all possible platforms 32# Test with as many configurations possible (With or without any option) 33# Create scripts that help keeping the CMake build system up to date (to reduce maintenance). According to Tetetest: 34# - lists of headers that 'configure' checks for; 35# - curl-specific tests (the ones that are in m4/curl-*.m4 files); 36# - (most obvious thing:) curl version numbers. 37# Add documentation subproject 38# 39# To check: 40# (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not. 41# (From Daniel Stenberg) The gcc command line use neither -g nor any -O options. As a developer, I also treasure our configure scripts's --enable-debug option that sets a long range of "picky" compiler options. 42 43# Note: By default this CMake build script detects the version of some 44# dependencies using `check_symbol_exists`. Those checks do not work 45# in the case that both CURL and its dependency are included as 46# sub-projects in a larger build using `FetchContent`. To support 47# that case, additional variables may be defined by the parent 48# project, ideally in the "extra" find package redirect file: 49# https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package 50# 51# The following variables are available: 52# HAVE_RAND_EGD: `RAND_egd` present in OpenSSL 53# HAVE_BORINGSSL: OpenSSL is BoringSSL 54# HAVE_PK11_CREATEMANAGEDGENERICOBJECTL: `PK11_CreateManagedGenericObject` present in NSS 55# HAVE_SSL_CTX_SET_QUIC_METHOD: `SSL_CTX_set_quic_method` present in OpenSSL/wolfSSL 56# HAVE_QUICHE_CONN_SET_QLOG_FD: `quiche_conn_set_qlog_fd` present in QUICHE 57# HAVE_ZSTD_CREATEDSTREAM: `ZSTD_createDStream` present in Zstd 58# 59# For each of the above variables, if the variable is DEFINED (either 60# to ON or OFF), the symbol detection will be skipped. If the 61# variable is NOT DEFINED, the symbol detection will be performed. 62 63cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR) 64 65set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}") 66include(Utilities) 67include(Macros) 68include(CMakeDependentOption) 69include(CheckCCompilerFlag) 70 71project(CURL C) 72 73file(STRINGS ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS REGEX "#define LIBCURL_VERSION( |_NUM )") 74string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*" 75 CURL_VERSION ${CURL_VERSION_H_CONTENTS}) 76string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION}) 77string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+" 78 CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS}) 79string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM}) 80 81 82# Setup package meta-data 83# SET(PACKAGE "curl") 84message(STATUS "curl version=[${CURL_VERSION}]") 85# SET(PACKAGE_TARNAME "curl") 86# SET(PACKAGE_NAME "curl") 87# SET(PACKAGE_VERSION "-") 88# SET(PACKAGE_STRING "curl-") 89# SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.se/mail/") 90set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}") 91if(CMAKE_C_COMPILER_TARGET) 92 set(OS "\"${CMAKE_C_COMPILER_TARGET}\"") 93else() 94 set(OS "\"${CMAKE_SYSTEM_NAME}\"") 95endif() 96 97include_directories(${CURL_SOURCE_DIR}/include) 98 99option(CURL_WERROR "Turn compiler warnings into errors" OFF) 100option(PICKY_COMPILER "Enable picky compiler options" ON) 101option(BUILD_CURL_EXE "Set to ON to build curl executable." ON) 102option(BUILD_SHARED_LIBS "Build shared libraries" ON) 103option(ENABLE_ARES "Set to ON to enable c-ares support" OFF) 104if(WIN32) 105 option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF) 106 option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF) 107 set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string") 108 if(CURL_TARGET_WINDOWS_VERSION) 109 add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}) 110 list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}) 111 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") 112 endif() 113 if(ENABLE_UNICODE) 114 add_definitions(-DUNICODE -D_UNICODE) 115 if(MINGW) 116 add_compile_options(-municode) 117 endif() 118 endif() 119endif() 120option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF) 121 122cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup" 123 ON "NOT ENABLE_ARES" 124 OFF) 125 126option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF) 127option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF) 128 129if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") 130 if(PICKY_COMPILER) 131 foreach(_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wfloat-equal -Wsign-compare -Wundef -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wvla -Wdouble-promotion -Wenum-conversion -Warith-conversion) 132 # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new 133 # test result in. 134 string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname) 135 check_c_compiler_flag(${_CCOPT} ${_optvarname}) 136 if(${_optvarname}) 137 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}") 138 endif() 139 endforeach() 140 foreach(_CCOPT long-long multichar format-nonliteral sign-conversion system-headers pedantic-ms-format) 141 # GCC only warns about unknown -Wno- options if there are also other diagnostic messages, 142 # so test for the positive form instead 143 string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname) 144 check_c_compiler_flag("-W${_CCOPT}" ${_optvarname}) 145 if(${_optvarname}) 146 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-${_CCOPT}") 147 endif() 148 endforeach() 149 endif() 150endif() 151 152if(ENABLE_DEBUG) 153 # DEBUGBUILD will be defined only for Debug builds 154 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>) 155 set(ENABLE_CURLDEBUG ON) 156endif() 157 158if(ENABLE_CURLDEBUG) 159 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG) 160endif() 161 162# For debug libs and exes, add "-d" postfix 163if(NOT DEFINED CMAKE_DEBUG_POSTFIX) 164 set(CMAKE_DEBUG_POSTFIX "-d") 165endif() 166 167# initialize CURL_LIBS 168set(CURL_LIBS "") 169 170if(ENABLE_ARES) 171 set(USE_ARES 1) 172 find_package(CARES REQUIRED) 173 list(APPEND CURL_LIBS ${CARES_LIBRARY}) 174endif() 175 176include(CurlSymbolHiding) 177 178option(CURL_ENABLE_EXPORT_TARGET "to enable cmake export target" ON) 179mark_as_advanced(CURL_ENABLE_EXPORT_TARGET) 180 181option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF) 182mark_as_advanced(CURL_DISABLE_ALTSVC) 183option(CURL_DISABLE_COOKIES "disables cookies support" OFF) 184mark_as_advanced(CURL_DISABLE_COOKIES) 185option(CURL_DISABLE_CRYPTO_AUTH "disables cryptographic authentication" OFF) 186mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH) 187option(CURL_DISABLE_DICT "disables DICT" OFF) 188mark_as_advanced(CURL_DISABLE_DICT) 189option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF) 190mark_as_advanced(CURL_DISABLE_DOH) 191option(CURL_DISABLE_FILE "disables FILE" OFF) 192mark_as_advanced(CURL_DISABLE_FILE) 193option(CURL_DISABLE_FTP "disables FTP" OFF) 194mark_as_advanced(CURL_DISABLE_FTP) 195option(CURL_DISABLE_GETOPTIONS "disables curl_easy_options API for existing options to curl_easy_setopt" OFF) 196mark_as_advanced(CURL_DISABLE_GETOPTIONS) 197option(CURL_DISABLE_GOPHER "disables Gopher" OFF) 198mark_as_advanced(CURL_DISABLE_GOPHER) 199option(CURL_DISABLE_HSTS "disables HSTS support" OFF) 200mark_as_advanced(CURL_DISABLE_HSTS) 201option(CURL_DISABLE_HTTP "disables HTTP" OFF) 202mark_as_advanced(CURL_DISABLE_HTTP) 203option(CURL_DISABLE_HTTP_AUTH "disables all HTTP authentication methods" OFF) 204mark_as_advanced(CURL_DISABLE_HTTP_AUTH) 205option(CURL_DISABLE_IMAP "disables IMAP" OFF) 206mark_as_advanced(CURL_DISABLE_IMAP) 207option(CURL_DISABLE_LDAP "disables LDAP" OFF) 208mark_as_advanced(CURL_DISABLE_LDAP) 209option(CURL_DISABLE_LDAPS "disables LDAPS" OFF) 210mark_as_advanced(CURL_DISABLE_LDAPS) 211option(CURL_DISABLE_LIBCURL_OPTION "disables --libcurl option from the curl tool" OFF) 212mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION) 213option(CURL_DISABLE_MIME "disables MIME support" OFF) 214mark_as_advanced(CURL_DISABLE_MIME) 215option(CURL_DISABLE_MQTT "disables MQTT" OFF) 216mark_as_advanced(CURL_DISABLE_MQTT) 217option(CURL_DISABLE_NETRC "disables netrc parser" OFF) 218mark_as_advanced(CURL_DISABLE_NETRC) 219option(CURL_DISABLE_NTLM "disables NTLM support" OFF) 220mark_as_advanced(CURL_DISABLE_NTLM) 221option(CURL_DISABLE_PARSEDATE "disables date parsing" OFF) 222mark_as_advanced(CURL_DISABLE_PARSEDATE) 223option(CURL_DISABLE_POP3 "disables POP3" OFF) 224mark_as_advanced(CURL_DISABLE_POP3) 225option(CURL_DISABLE_PROGRESS_METER "disables built-in progress meter" OFF) 226mark_as_advanced(CURL_DISABLE_PROGRESS_METER) 227option(CURL_DISABLE_PROXY "disables proxy support" OFF) 228mark_as_advanced(CURL_DISABLE_PROXY) 229option(CURL_DISABLE_RTSP "disables RTSP" OFF) 230mark_as_advanced(CURL_DISABLE_RTSP) 231option(CURL_DISABLE_SHUFFLE_DNS "disables shuffle DNS feature" OFF) 232mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS) 233option(CURL_DISABLE_SMB "disables SMB" OFF) 234mark_as_advanced(CURL_DISABLE_SMB) 235option(CURL_DISABLE_SMTP "disables SMTP" OFF) 236mark_as_advanced(CURL_DISABLE_SMTP) 237option(CURL_DISABLE_SOCKETPAIR "disables use of socketpair for curl_multi_poll" OFF) 238mark_as_advanced(CURL_DISABLE_SOCKETPAIR) 239option(CURL_DISABLE_TELNET "disables Telnet" OFF) 240mark_as_advanced(CURL_DISABLE_TELNET) 241option(CURL_DISABLE_TFTP "disables TFTP" OFF) 242mark_as_advanced(CURL_DISABLE_TFTP) 243option(CURL_DISABLE_VERBOSE_STRINGS "disables verbose strings" OFF) 244mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS) 245 246# Corresponds to HTTP_ONLY in lib/curl_setup.h 247option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF) 248mark_as_advanced(HTTP_ONLY) 249 250if(HTTP_ONLY) 251 set(CURL_DISABLE_DICT ON) 252 set(CURL_DISABLE_FILE ON) 253 set(CURL_DISABLE_FTP ON) 254 set(CURL_DISABLE_GOPHER ON) 255 set(CURL_DISABLE_IMAP ON) 256 set(CURL_DISABLE_LDAP ON) 257 set(CURL_DISABLE_LDAPS ON) 258 set(CURL_DISABLE_MQTT ON) 259 set(CURL_DISABLE_POP3 ON) 260 set(CURL_DISABLE_RTSP ON) 261 set(CURL_DISABLE_SMB ON) 262 set(CURL_DISABLE_SMTP ON) 263 set(CURL_DISABLE_TELNET ON) 264 set(CURL_DISABLE_TFTP ON) 265endif() 266 267option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON) 268mark_as_advanced(ENABLE_IPV6) 269if(ENABLE_IPV6 AND NOT WIN32) 270 include(CheckStructHasMember) 271 check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h" 272 HAVE_SOCKADDR_IN6_SIN6_ADDR) 273 check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h" 274 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) 275 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR) 276 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support") 277 # Force the feature off as this name is used as guard macro... 278 set(ENABLE_IPV6 OFF 279 CACHE BOOL "Define if you want to enable IPv6 support" FORCE) 280 endif() 281 282 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_ARES) 283 set(use_core_foundation ON) 284 285 find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration") 286 if(NOT SYSTEMCONFIGURATION_FRAMEWORK) 287 message(FATAL_ERROR "SystemConfiguration framework not found") 288 endif() 289 290 list(APPEND CURL_LIBS "-framework SystemConfiguration") 291 endif() 292endif() 293 294if(USE_MANUAL) 295 #nroff is currently only used when USE_MANUAL is set, so we can prevent the warning of no *NROFF if USE_MANUAL is OFF (or not defined), by not even looking for NROFF.. 296 curl_nroff_check() 297endif() 298find_package(Perl) 299 300cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual" 301 ON "NROFF_USEFUL;PERL_FOUND" 302 OFF) 303 304if(ENABLE_MANUAL) 305 set(USE_MANUAL ON) 306endif() 307 308if(CURL_STATIC_CRT) 309 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") 310 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT") 311 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd") 312endif() 313 314# Disable warnings on Borland to avoid changing 3rd party code. 315if(BORLAND) 316 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-") 317endif() 318 319# If we are on AIX, do the _ALL_SOURCE magic 320if(${CMAKE_SYSTEM_NAME} MATCHES AIX) 321 set(_ALL_SOURCE 1) 322endif() 323 324# Include all the necessary files for macros 325include(CMakePushCheckState) 326include(CheckFunctionExists) 327include(CheckIncludeFile) 328include(CheckIncludeFiles) 329include(CheckLibraryExists) 330include(CheckSymbolExists) 331include(CheckTypeSize) 332include(CheckCSourceCompiles) 333 334# On windows preload settings 335if(WIN32) 336 list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_WINSOCKAPI_=) 337 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake) 338endif() 339 340if(ENABLE_THREADED_RESOLVER) 341 find_package(Threads REQUIRED) 342 if(WIN32) 343 set(USE_THREADS_WIN32 ON) 344 else() 345 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT}) 346 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT}) 347 endif() 348 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 349endif() 350 351# Check for all needed libraries 352check_library_exists_concat("socket" connect HAVE_LIBSOCKET) 353 354check_function_exists(gethostname HAVE_GETHOSTNAME) 355 356if(WIN32) 357 check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32) 358 check_library_exists_concat("winmm" getch HAVE_LIBWINMM) 359endif() 360 361# check SSL libraries 362# TODO support GnuTLS 363option(CURL_ENABLE_SSL "Enable SSL support" ON) 364 365if(APPLE) 366 cmake_dependent_option(CURL_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF CURL_ENABLE_SSL OFF) 367endif() 368if(WIN32) 369 cmake_dependent_option(CURL_USE_SCHANNEL "enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF) 370 cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without OpenSSL" ON 371 CURL_USE_SCHANNEL OFF) 372endif() 373cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 374cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 375cmake_dependent_option(CURL_USE_NSS "Enable NSS for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 376cmake_dependent_option(CURL_USE_WOLFSSL "enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF) 377 378set(openssl_default ON) 379if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_NSS OR CURL_USE_WOLFSSL) 380 set(openssl_default OFF) 381endif() 382cmake_dependent_option(CURL_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default} CURL_ENABLE_SSL OFF) 383option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF) 384 385count_true(enabled_ssl_options_count 386 CURL_USE_SCHANNEL 387 CURL_USE_SECTRANSP 388 CURL_USE_OPENSSL 389 CURL_USE_MBEDTLS 390 CURL_USE_BEARSSL 391 CURL_USE_NSS 392 CURL_USE_WOLFSSL 393) 394if(enabled_ssl_options_count GREATER "1") 395 set(CURL_WITH_MULTI_SSL ON) 396endif() 397 398if(CURL_USE_SCHANNEL) 399 set(SSL_ENABLED ON) 400 set(USE_SCHANNEL ON) # Windows native SSL/TLS support 401 set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI 402endif() 403if(CURL_WINDOWS_SSPI) 404 set(USE_WINDOWS_SSPI ON) 405endif() 406 407if(CURL_USE_SECTRANSP) 408 set(use_core_foundation ON) 409 410 find_library(SECURITY_FRAMEWORK "Security") 411 if(NOT SECURITY_FRAMEWORK) 412 message(FATAL_ERROR "Security framework not found") 413 endif() 414 415 set(SSL_ENABLED ON) 416 set(USE_SECTRANSP ON) 417 list(APPEND CURL_LIBS "-framework Security") 418endif() 419 420if(use_core_foundation) 421 find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation") 422 if(NOT COREFOUNDATION_FRAMEWORK) 423 message(FATAL_ERROR "CoreFoundation framework not found") 424 endif() 425 426 list(APPEND CURL_LIBS "-framework CoreFoundation") 427endif() 428 429# Keep compression lib detection before TLS detection, which 430# might depend on it. 431 432set(HAVE_LIBZ OFF) 433set(USE_ZLIB OFF) 434optional_dependency(ZLIB) 435if(ZLIB_FOUND) 436 set(HAVE_LIBZ ON) 437 set(USE_ZLIB ON) 438 439 # Depend on ZLIB via imported targets if supported by the running 440 # version of CMake. This allows our dependents to get our dependencies 441 # transitively. 442 if(NOT CMAKE_VERSION VERSION_LESS 3.4) 443 list(APPEND CURL_LIBS ZLIB::ZLIB) 444 else() 445 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES}) 446 include_directories(${ZLIB_INCLUDE_DIRS}) 447 endif() 448 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS}) 449endif() 450 451option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF) 452set(HAVE_BROTLI OFF) 453if(CURL_BROTLI) 454 find_package(Brotli QUIET) 455 if(BROTLI_FOUND) 456 set(HAVE_BROTLI ON) 457 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES}) 458 include_directories(${BROTLI_INCLUDE_DIRS}) 459 list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS}) 460 endif() 461endif() 462 463option(CURL_ZSTD "Set to ON to enable building curl with zstd support." OFF) 464set(HAVE_ZSTD OFF) 465if(CURL_ZSTD) 466 find_package(Zstd REQUIRED) 467 if (NOT DEFINED HAVE_ZSTD_CREATEDSTREAM) 468 cmake_push_check_state() 469 set(CMAKE_REQUIRED_INCLUDES ${Zstd_INCLUDE_DIRS}) 470 set(CMAKE_REQUIRED_LIBRARIES ${Zstd_LIBRARIES}) 471 check_symbol_exists(ZSTD_createDStream "zstd.h" HAVE_ZSTD_CREATEDSTREAM) 472 cmake_pop_check_state() 473 endif() 474 if(Zstd_FOUND AND HAVE_ZSTD_CREATEDSTREAM) 475 set(HAVE_ZSTD ON) 476 list(APPEND CURL_LIBS ${Zstd_LIBRARIES}) 477 include_directories(${Zstd_INCLUDE_DIRS}) 478 endif() 479endif() 480 481if(CURL_USE_OPENSSL) 482 find_package(OpenSSL REQUIRED) 483 set(SSL_ENABLED ON) 484 set(USE_OPENSSL ON) 485 486 # Depend on OpenSSL via imported targets if supported by the running 487 # version of CMake. This allows our dependents to get our dependencies 488 # transitively. 489 if(NOT CMAKE_VERSION VERSION_LESS 3.4) 490 list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto) 491 else() 492 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES}) 493 include_directories(${OPENSSL_INCLUDE_DIR}) 494 endif() 495 496 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) 497 if(NOT DEFINED HAVE_RAND_EGD) 498 check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD) 499 endif() 500 if(NOT DEFINED HAVE_BORINGSSL) 501 check_symbol_exists(OPENSSL_IS_BORINGSSL "openssl/base.h" HAVE_BORINGSSL) 502 endif() 503endif() 504 505if(CURL_USE_MBEDTLS) 506 find_package(MbedTLS REQUIRED) 507 set(SSL_ENABLED ON) 508 set(USE_MBEDTLS ON) 509 list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES}) 510 include_directories(${MBEDTLS_INCLUDE_DIRS}) 511endif() 512 513if(CURL_USE_BEARSSL) 514 find_package(BearSSL REQUIRED) 515 set(SSL_ENABLED ON) 516 set(USE_BEARSSL ON) 517 list(APPEND CURL_LIBS ${BEARSSL_LIBRARY}) 518 include_directories(${BEARSSL_INCLUDE_DIRS}) 519endif() 520 521if(CURL_USE_WOLFSSL) 522 find_package(WolfSSL REQUIRED) 523 set(SSL_ENABLED ON) 524 set(USE_WOLFSSL ON) 525 list(APPEND CURL_LIBS ${WolfSSL_LIBRARIES}) 526 include_directories(${WolfSSL_INCLUDE_DIRS}) 527endif() 528 529if(CURL_USE_NSS) 530 find_package(NSS REQUIRED) 531 include_directories(${NSS_INCLUDE_DIRS}) 532 list(APPEND CURL_LIBS ${NSS_LIBRARIES}) 533 set(SSL_ENABLED ON) 534 set(USE_NSS ON) 535 if(NOT DEFINED HAVE_PK11_CREATEMANAGEDGENERICOBJECT) 536 cmake_push_check_state() 537 set(CMAKE_REQUIRED_INCLUDES ${NSS_INCLUDE_DIRS}) 538 set(CMAKE_REQUIRED_LIBRARIES ${NSS_LIBRARIES}) 539 check_symbol_exists(PK11_CreateManagedGenericObject "pk11pub.h" HAVE_PK11_CREATEMANAGEDGENERICOBJECT) 540 cmake_pop_check_state() 541 endif() 542endif() 543 544option(USE_NGHTTP2 "Use Nghttp2 library" OFF) 545if(USE_NGHTTP2) 546 find_package(NGHTTP2 REQUIRED) 547 include_directories(${NGHTTP2_INCLUDE_DIRS}) 548 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES}) 549endif() 550 551function(CheckQuicSupportInOpenSSL) 552 # Be sure that the OpenSSL/wolfSSL library actually supports QUIC. 553 if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD) 554 cmake_push_check_state() 555 if(USE_WOLFSSL) 556 set(CMAKE_REQUIRED_INCLUDES "${WolfSSL_INCLUDE_DIRS}") 557 set(CMAKE_REQUIRED_LIBRARIES "${WolfSSL_LIBRARIES}") 558 if(HAVE_LIBZ) 559 list(APPEND CMAKE_REQUIRED_INCLUDES "${ZLIB_INCLUDE_DIRS}") 560 list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}") 561 endif() 562 if(WIN32) 563 list(APPEND CMAKE_REQUIRED_LIBRARIES "crypt32") 564 endif() 565 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_UINTPTR_T) # to pull in stdint.h (as of wolfSSL v5.5.4) 566 check_symbol_exists(wolfSSL_set_quic_method "wolfssl/options.h;wolfssl/openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD) 567 else() 568 set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}") 569 set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}") 570 check_symbol_exists(SSL_CTX_set_quic_method "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD) 571 endif() 572 cmake_pop_check_state() 573 endif() 574 if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD) 575 message(FATAL_ERROR "QUIC support is missing in OpenSSL/BoringSSL/wolfSSL. Try setting -DOPENSSL_ROOT_DIR") 576 endif() 577endfunction() 578 579option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF) 580if(USE_NGTCP2) 581 if(USE_OPENSSL OR USE_WOLFSSL) 582 if(USE_WOLFSSL) 583 find_package(NGTCP2 REQUIRED wolfSSL) 584 elseif(HAVE_BORINGSSL) 585 find_package(NGTCP2 REQUIRED BoringSSL) 586 else() 587 find_package(NGTCP2 REQUIRED OpenSSL) 588 endif() 589 CheckQuicSupportInOpenSSL() 590 elseif(USE_GNUTLS) 591 # TODO add GnuTLS support as vtls library. 592 find_package(NGTCP2 REQUIRED GnuTLS) 593 else() 594 message(FATAL_ERROR "ngtcp2 requires OpenSSL, wolfSSL or GnuTLS") 595 endif() 596 set(USE_NGTCP2 ON) 597 include_directories(${NGTCP2_INCLUDE_DIRS}) 598 list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES}) 599 600 find_package(NGHTTP3 REQUIRED) 601 set(USE_NGHTTP3 ON) 602 include_directories(${NGHTTP3_INCLUDE_DIRS}) 603 list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES}) 604endif() 605 606option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF) 607if(USE_QUICHE) 608 if(USE_NGTCP2) 609 message(FATAL_ERROR "Only one HTTP/3 backend can be selected!") 610 endif() 611 find_package(QUICHE REQUIRED) 612 CheckQuicSupportInOpenSSL() 613 set(USE_QUICHE ON) 614 include_directories(${QUICHE_INCLUDE_DIRS}) 615 list(APPEND CURL_LIBS ${QUICHE_LIBRARIES}) 616 if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD) 617 cmake_push_check_state() 618 set(CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}") 619 set(CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}") 620 check_symbol_exists(quiche_conn_set_qlog_fd "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD) 621 cmake_pop_check_state() 622 endif() 623endif() 624 625option(USE_MSH3 "Use msquic library for HTTP/3 support" OFF) 626if(USE_MSH3) 627 if(USE_NGTCP2 OR USE_QUICHE) 628 message(FATAL_ERROR "Only one HTTP/3 backend can be selected!") 629 endif() 630 set(USE_MSH3 ON) 631 include_directories(${MSH3_INCLUDE_DIRS}) 632 list(APPEND CURL_LIBS ${MSH3_LIBRARIES}) 633endif() 634 635if(NOT CURL_DISABLE_LDAP) 636 if(WIN32) 637 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON) 638 if(USE_WIN32_LDAP) 639 check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32) 640 if(NOT HAVE_WLDAP32) 641 set(USE_WIN32_LDAP OFF) 642 elseif(NOT CURL_DISABLE_LDAPS) 643 set(HAVE_LDAP_SSL ON) 644 endif() 645 endif() 646 endif() 647 648 option(CURL_USE_OPENLDAP "Use OpenLDAP code." OFF) 649 mark_as_advanced(CURL_USE_OPENLDAP) 650 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library") 651 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library") 652 653 if(CURL_USE_OPENLDAP AND USE_WIN32_LDAP) 654 message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CURL_USE_OPENLDAP at the same time") 655 endif() 656 657 # Now that we know, we're not using windows LDAP... 658 if(USE_WIN32_LDAP) 659 check_include_file_concat("winldap.h" HAVE_WINLDAP_H) 660 else() 661 # Check for LDAP 662 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}) 663 check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP) 664 check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER) 665 666 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES}) 667 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory") 668 if(CMAKE_LDAP_INCLUDE_DIR) 669 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR}) 670 endif() 671 check_include_file_concat("ldap.h" HAVE_LDAP_H) 672 check_include_file_concat("lber.h" HAVE_LBER_H) 673 674 if(NOT HAVE_LDAP_H) 675 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON") 676 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE) 677 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used 678 elseif(NOT HAVE_LIBLDAP) 679 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON") 680 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE) 681 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used 682 else() 683 if(CURL_USE_OPENLDAP) 684 set(USE_OPENLDAP ON) 685 endif() 686 if(CMAKE_LDAP_INCLUDE_DIR) 687 include_directories(${CMAKE_LDAP_INCLUDE_DIR}) 688 endif() 689 set(NEED_LBER_H ON) 690 set(_HEADER_LIST) 691 if(HAVE_WINDOWS_H) 692 list(APPEND _HEADER_LIST "windows.h") 693 endif() 694 if(HAVE_SYS_TYPES_H) 695 list(APPEND _HEADER_LIST "sys/types.h") 696 endif() 697 list(APPEND _HEADER_LIST "ldap.h") 698 699 set(_SRC_STRING "") 700 foreach(_HEADER ${_HEADER_LIST}) 701 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n") 702 endforeach() 703 704 set(_SRC_STRING 705 " 706 ${_INCLUDE_STRING} 707 int main(int argc, char ** argv) 708 { 709 BerValue *bvp = NULL; 710 BerElement *bep = ber_init(bvp); 711 ber_free(bep, 1); 712 return 0; 713 }" 714 ) 715 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DLDAP_DEPRECATED=1) 716 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB}) 717 if(HAVE_LIBLBER) 718 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB}) 719 endif() 720 check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H) 721 unset(CMAKE_REQUIRED_LIBRARIES) 722 723 if(NOT_NEED_LBER_H) 724 set(NEED_LBER_H OFF) 725 else() 726 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H") 727 endif() 728 endif() 729 endif() 730endif() 731 732# No ldap, no ldaps. 733if(CURL_DISABLE_LDAP) 734 if(NOT CURL_DISABLE_LDAPS) 735 message(STATUS "LDAP needs to be enabled to support LDAPS") 736 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE) 737 endif() 738endif() 739 740if(NOT CURL_DISABLE_LDAPS) 741 check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H) 742endif() 743 744# Check for idn2 745option(USE_LIBIDN2 "Use libidn2 for IDN support" ON) 746if(USE_LIBIDN2) 747 check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2) 748else() 749 set(HAVE_LIBIDN2 OFF) 750endif() 751 752if(WIN32) 753 option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF) 754 if(USE_WIN32_IDN) 755 list(APPEND CURL_LIBS "normaliz") 756 endif() 757endif() 758 759#libpsl 760option(CURL_USE_LIBPSL "Use libPSL" ON) 761mark_as_advanced(CURL_USE_LIBPSL) 762set(USE_LIBPSL OFF) 763 764if(CURL_USE_LIBPSL) 765 find_package(LibPSL) 766 if(LIBPSL_FOUND) 767 list(APPEND CURL_LIBS ${LIBPSL_LIBRARY}) 768 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIR}") 769 include_directories("${LIBPSL_INCLUDE_DIR}") 770 set(USE_LIBPSL ON) 771 endif() 772endif() 773 774#libSSH2 775option(CURL_USE_LIBSSH2 "Use libSSH2" ON) 776mark_as_advanced(CURL_USE_LIBSSH2) 777set(USE_LIBSSH2 OFF) 778 779if(CURL_USE_LIBSSH2) 780 find_package(LibSSH2) 781 if(LIBSSH2_FOUND) 782 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY}) 783 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}") 784 include_directories("${LIBSSH2_INCLUDE_DIR}") 785 set(USE_LIBSSH2 ON) 786 endif() 787endif() 788 789# libssh 790option(CURL_USE_LIBSSH "Use libSSH" OFF) 791mark_as_advanced(CURL_USE_LIBSSH) 792if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH) 793 find_package(libssh CONFIG) 794 if(libssh_FOUND) 795 message(STATUS "Found libssh ${libssh_VERSION}") 796 # Use imported target for include and library paths. 797 list(APPEND CURL_LIBS ssh) 798 set(USE_LIBSSH ON) 799 endif() 800endif() 801 802option(CURL_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF) 803mark_as_advanced(CURL_USE_GSSAPI) 804 805if(CURL_USE_GSSAPI) 806 find_package(GSS) 807 808 set(HAVE_GSSAPI ${GSS_FOUND}) 809 if(GSS_FOUND) 810 811 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"") 812 813 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR}) 814 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H) 815 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H) 816 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H) 817 818 if(GSS_FLAVOUR STREQUAL "Heimdal") 819 set(HAVE_GSSHEIMDAL ON) 820 else() # MIT 821 set(HAVE_GSSMIT ON) 822 set(_INCLUDE_LIST "") 823 if(HAVE_GSSAPI_GSSAPI_H) 824 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h") 825 endif() 826 if(HAVE_GSSAPI_GSSAPI_GENERIC_H) 827 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h") 828 endif() 829 if(HAVE_GSSAPI_GSSAPI_KRB5_H) 830 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h") 831 endif() 832 833 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}") 834 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}") 835 836 foreach(_dir ${GSS_LINK_DIRECTORIES}) 837 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"") 838 endforeach() 839 840 if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE) 841 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}") 842 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES}) 843 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE) 844 unset(CMAKE_REQUIRED_LIBRARIES) 845 endif() 846 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE) 847 set(HAVE_OLD_GSSMIT ON) 848 endif() 849 endif() 850 851 include_directories(${GSS_INCLUDE_DIR}) 852 link_directories(${GSS_LINK_DIRECTORIES}) 853 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}") 854 string(REPLACE ";" " " GSS_LINKER_FLAGS "${GSS_LINKER_FLAGS}") 855 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}") 856 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}") 857 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${GSS_LINKER_FLAGS}") 858 list(APPEND CURL_LIBS ${GSS_LIBRARIES}) 859 860 else() 861 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.") 862 endif() 863endif() 864 865option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON) 866if(ENABLE_UNIX_SOCKETS) 867 include(CheckStructHasMember) 868 if(WIN32) 869 set(USE_UNIX_SOCKETS ON) 870 else() 871 check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS) 872 endif() 873else() 874 unset(USE_UNIX_SOCKETS CACHE) 875endif() 876 877 878# 879# CA handling 880# 881set(CURL_CA_BUNDLE "auto" CACHE STRING 882 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 883set(CURL_CA_FALLBACK OFF CACHE BOOL 884 "Set ON to use built-in CA store of TLS backend. Defaults to OFF") 885set(CURL_CA_PATH "auto" CACHE STRING 886 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 887 888if("${CURL_CA_BUNDLE}" STREQUAL "") 889 message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.") 890elseif("${CURL_CA_BUNDLE}" STREQUAL "none") 891 unset(CURL_CA_BUNDLE CACHE) 892elseif("${CURL_CA_BUNDLE}" STREQUAL "auto") 893 unset(CURL_CA_BUNDLE CACHE) 894 if(NOT CMAKE_CROSSCOMPILING) 895 set(CURL_CA_BUNDLE_AUTODETECT TRUE) 896 endif() 897else() 898 set(CURL_CA_BUNDLE_SET TRUE) 899endif() 900 901if("${CURL_CA_PATH}" STREQUAL "") 902 message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.") 903elseif("${CURL_CA_PATH}" STREQUAL "none") 904 unset(CURL_CA_PATH CACHE) 905elseif("${CURL_CA_PATH}" STREQUAL "auto") 906 unset(CURL_CA_PATH CACHE) 907 if(NOT CMAKE_CROSSCOMPILING AND NOT USE_NSS) 908 set(CURL_CA_PATH_AUTODETECT TRUE) 909 endif() 910else() 911 set(CURL_CA_PATH_SET TRUE) 912endif() 913 914if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT) 915 # Skip autodetection of unset CA path because CA bundle is set explicitly 916elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT) 917 # Skip autodetection of unset CA bundle because CA path is set explicitly 918elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT) 919 # first try autodetecting a CA bundle, then a CA path 920 921 if(CURL_CA_BUNDLE_AUTODETECT) 922 set(SEARCH_CA_BUNDLE_PATHS 923 /etc/ssl/certs/ca-certificates.crt 924 /etc/pki/tls/certs/ca-bundle.crt 925 /usr/share/ssl/certs/ca-bundle.crt 926 /usr/local/share/certs/ca-root-nss.crt 927 /etc/ssl/cert.pem) 928 929 foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS}) 930 if(EXISTS "${SEARCH_CA_BUNDLE_PATH}") 931 message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}") 932 set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}" CACHE STRING 933 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 934 set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set") 935 break() 936 endif() 937 endforeach() 938 endif() 939 940 if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET)) 941 if(EXISTS "/etc/ssl/certs") 942 set(CURL_CA_PATH "/etc/ssl/certs" CACHE STRING 943 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") 944 set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set") 945 endif() 946 endif() 947endif() 948 949if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS) 950 message(STATUS 951 "CA path only supported by OpenSSL, GnuTLS or mbed TLS. " 952 "Set CURL_CA_PATH=none or enable one of those TLS backends.") 953endif() 954 955# Check for header files 956if(NOT UNIX) 957 check_include_file_concat("windows.h" HAVE_WINDOWS_H) 958 check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H) 959 check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H) 960 check_include_file_concat("wincrypt.h" HAVE_WINCRYPT_H) 961endif() 962 963check_include_file_concat("inttypes.h" HAVE_INTTYPES_H) 964check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H) 965check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H) 966check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H) 967check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H) 968check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H) 969check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H) 970check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H) 971check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H) 972check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H) 973check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H) 974check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H) 975check_include_file_concat("sys/un.h" HAVE_SYS_UN_H) 976check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H) 977check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H) 978check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H) 979check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H) 980check_include_file_concat("fcntl.h" HAVE_FCNTL_H) 981check_include_file_concat("idn2.h" HAVE_IDN2_H) 982check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H) 983check_include_file_concat("io.h" HAVE_IO_H) 984check_include_file_concat("libgen.h" HAVE_LIBGEN_H) 985check_include_file_concat("locale.h" HAVE_LOCALE_H) 986check_include_file_concat("net/if.h" HAVE_NET_IF_H) 987check_include_file_concat("netdb.h" HAVE_NETDB_H) 988check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H) 989check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H) 990check_include_file("linux/tcp.h" HAVE_LINUX_TCP_H) 991 992check_include_file_concat("poll.h" HAVE_POLL_H) 993check_include_file_concat("pwd.h" HAVE_PWD_H) 994check_include_file_concat("setjmp.h" HAVE_SETJMP_H) 995check_include_file_concat("signal.h" HAVE_SIGNAL_H) 996check_include_file_concat("ssl.h" HAVE_SSL_H) 997check_include_file_concat("stdatomic.h" HAVE_STDATOMIC_H) 998check_include_file_concat("stdbool.h" HAVE_STDBOOL_H) 999check_include_file_concat("stdint.h" HAVE_STDINT_H) 1000check_include_file_concat("stdlib.h" HAVE_STDLIB_H) 1001check_include_file_concat("string.h" HAVE_STRING_H) 1002check_include_file_concat("strings.h" HAVE_STRINGS_H) 1003check_include_file_concat("stropts.h" HAVE_STROPTS_H) 1004check_include_file_concat("termio.h" HAVE_TERMIO_H) 1005check_include_file_concat("termios.h" HAVE_TERMIOS_H) 1006check_include_file_concat("time.h" HAVE_TIME_H) 1007check_include_file_concat("unistd.h" HAVE_UNISTD_H) 1008check_include_file_concat("utime.h" HAVE_UTIME_H) 1009 1010check_include_file_concat("stddef.h" HAVE_STDDEF_H) 1011check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H) 1012 1013check_type_size(size_t SIZEOF_SIZE_T) 1014check_type_size(ssize_t SIZEOF_SSIZE_T) 1015check_type_size("long long" SIZEOF_LONG_LONG) 1016check_type_size("long" SIZEOF_LONG) 1017check_type_size("int" SIZEOF_INT) 1018check_type_size("__int64" SIZEOF___INT64) 1019check_type_size("time_t" SIZEOF_TIME_T) 1020if(NOT HAVE_SIZEOF_SSIZE_T) 1021 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T) 1022 set(ssize_t long) 1023 endif() 1024 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T) 1025 set(ssize_t __int64) 1026 endif() 1027endif() 1028# off_t is sized later, after the HAVE_FILE_OFFSET_BITS test 1029 1030if(HAVE_SIZEOF_LONG_LONG) 1031 set(HAVE_LONGLONG 1) 1032endif() 1033 1034if(NOT CMAKE_CROSSCOMPILING) 1035 find_file(RANDOM_FILE urandom /dev) 1036 mark_as_advanced(RANDOM_FILE) 1037endif() 1038 1039# Check for some functions that are used 1040if(HAVE_LIBWS2_32) 1041 set(CMAKE_REQUIRED_LIBRARIES ws2_32) 1042elseif(HAVE_LIBSOCKET) 1043 set(CMAKE_REQUIRED_LIBRARIES socket) 1044endif() 1045 1046check_symbol_exists(fchmod "${CURL_INCLUDES}" HAVE_FCHMOD) 1047check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME) 1048check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET) 1049check_symbol_exists(socketpair "${CURL_INCLUDES}" HAVE_SOCKETPAIR) 1050check_symbol_exists(recv "${CURL_INCLUDES}" HAVE_RECV) 1051check_symbol_exists(send "${CURL_INCLUDES}" HAVE_SEND) 1052check_symbol_exists(sendmsg "${CURL_INCLUDES}" HAVE_SENDMSG) 1053check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT) 1054check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP) 1055check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R) 1056check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP) 1057check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP) 1058check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI) 1059check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM) 1060check_symbol_exists(getppid "${CURL_INCLUDES}" HAVE_GETPPID) 1061check_symbol_exists(utimes "${CURL_INCLUDES}" HAVE_UTIMES) 1062 1063check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY) 1064check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET) 1065check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP) 1066check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R) 1067check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID) 1068check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R) 1069check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID) 1070check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME) 1071check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R) 1072 1073check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R) 1074 1075check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL) 1076check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL) 1077check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R) 1078check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT) 1079check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO) 1080if(WIN32) 1081 set(HAVE_GETADDRINFO_THREADSAFE ${HAVE_GETADDRINFO}) 1082endif() 1083check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO) 1084check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE) 1085check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE) 1086check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME) 1087check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME) 1088check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX) 1089check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT) 1090check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE) 1091check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE) 1092check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT) 1093 1094if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900)) 1095 # earlier MSVC compilers had faulty snprintf implementations 1096 check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) 1097endif() 1098check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME) 1099check_symbol_exists(inet_ntop "${CURL_INCLUDES}" HAVE_INET_NTOP) 1100if(MSVC AND (MSVC_VERSION LESS_EQUAL 1600)) 1101 set(HAVE_INET_NTOP OFF) 1102endif() 1103check_symbol_exists(inet_pton "${CURL_INCLUDES}" HAVE_INET_PTON) 1104 1105check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR) 1106if(HAVE_FSETXATTR) 1107 foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6) 1108 curl_internal_test(${CURL_TEST}) 1109 endforeach() 1110endif() 1111 1112set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h") 1113check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T) 1114set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T}) 1115set(CMAKE_EXTRA_INCLUDE_FILES "") 1116 1117set(CMAKE_EXTRA_INCLUDE_FILES "ws2def.h") 1118check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY) 1119set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY}) 1120set(CMAKE_EXTRA_INCLUDE_FILES "") 1121 1122# sigaction and sigsetjmp are special. Use special mechanism for 1123# detecting those, but only if previous attempt failed. 1124if(HAVE_SIGNAL_H) 1125 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION) 1126endif() 1127 1128if(NOT HAVE_SIGSETJMP) 1129 if(HAVE_SETJMP_H) 1130 check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP) 1131 if(HAVE_MACRO_SIGSETJMP) 1132 set(HAVE_SIGSETJMP 1) 1133 endif() 1134 endif() 1135endif() 1136 1137# If there is no stricmp(), do not allow LDAP to parse URLs 1138if(NOT HAVE_STRICMP) 1139 set(HAVE_LDAP_URL_PARSE 1) 1140endif() 1141 1142# Do curl specific tests 1143foreach(CURL_TEST 1144 HAVE_FCNTL_O_NONBLOCK 1145 HAVE_IOCTLSOCKET 1146 HAVE_IOCTLSOCKET_CAMEL 1147 HAVE_IOCTLSOCKET_CAMEL_FIONBIO 1148 HAVE_IOCTLSOCKET_FIONBIO 1149 HAVE_IOCTL_FIONBIO 1150 HAVE_IOCTL_SIOCGIFADDR 1151 HAVE_SETSOCKOPT_SO_NONBLOCK 1152 TIME_WITH_SYS_TIME 1153 HAVE_O_NONBLOCK 1154 HAVE_GETHOSTBYNAME_R_3 1155 HAVE_GETHOSTBYNAME_R_5 1156 HAVE_GETHOSTBYNAME_R_6 1157 HAVE_GETHOSTBYNAME_R_3_REENTRANT 1158 HAVE_GETHOSTBYNAME_R_5_REENTRANT 1159 HAVE_GETHOSTBYNAME_R_6_REENTRANT 1160 HAVE_IN_ADDR_T 1161 HAVE_BOOL_T 1162 STDC_HEADERS 1163 HAVE_FILE_OFFSET_BITS 1164 HAVE_VARIADIC_MACROS_C99 1165 HAVE_VARIADIC_MACROS_GCC 1166 HAVE_ATOMIC 1167 ) 1168 curl_internal_test(${CURL_TEST}) 1169endforeach() 1170 1171if(HAVE_FILE_OFFSET_BITS) 1172 set(_FILE_OFFSET_BITS 64) 1173 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64") 1174endif() 1175check_type_size("off_t" SIZEOF_OFF_T) 1176 1177# include this header to get the type 1178set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include") 1179set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h") 1180check_type_size("curl_off_t" SIZEOF_CURL_OFF_T) 1181set(CMAKE_EXTRA_INCLUDE_FILES "") 1182 1183if(WIN32) 1184 # detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT 1185 curl_internal_test(HAVE_WIN32_WINNT) 1186 if(HAVE_WIN32_WINNT) 1187 string(REGEX MATCH ".*_WIN32_WINNT=0x[0-9a-fA-F]+" OUTPUT "${OUTPUT}") 1188 string(REGEX REPLACE ".*_WIN32_WINNT=" "" HAVE_WIN32_WINNT "${OUTPUT}") 1189 message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}") 1190 endif() 1191 # avoid storing HAVE_WIN32_WINNT in CMake cache 1192 unset(HAVE_WIN32_WINNT CACHE) 1193endif() 1194 1195set(CMAKE_REQUIRED_FLAGS) 1196 1197option(ENABLE_WEBSOCKETS "Set to ON to enable EXPERIMENTAL websockets" OFF) 1198 1199if(ENABLE_WEBSOCKETS) 1200 if(${SIZEOF_CURL_OFF_T} GREATER "4") 1201 set(USE_WEBSOCKETS ON) 1202 else() 1203 message(WARNING "curl_off_t is too small to enable WebSockets") 1204 endif() 1205endif() 1206 1207foreach(CURL_TEST 1208 HAVE_GLIBC_STRERROR_R 1209 HAVE_POSIX_STRERROR_R 1210 ) 1211 curl_internal_test(${CURL_TEST}) 1212endforeach() 1213 1214# Check for reentrant 1215foreach(CURL_TEST 1216 HAVE_GETHOSTBYNAME_R_3 1217 HAVE_GETHOSTBYNAME_R_5 1218 HAVE_GETHOSTBYNAME_R_6) 1219 if(NOT ${CURL_TEST}) 1220 if(${CURL_TEST}_REENTRANT) 1221 set(NEED_REENTRANT 1) 1222 endif() 1223 endif() 1224endforeach() 1225 1226if(NEED_REENTRANT) 1227 foreach(CURL_TEST 1228 HAVE_GETHOSTBYNAME_R_3 1229 HAVE_GETHOSTBYNAME_R_5 1230 HAVE_GETHOSTBYNAME_R_6) 1231 set(${CURL_TEST} 0) 1232 if(${CURL_TEST}_REENTRANT) 1233 set(${CURL_TEST} 1) 1234 endif() 1235 endforeach() 1236endif() 1237 1238# Check clock_gettime(CLOCK_MONOTONIC, x) support 1239curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC) 1240 1241# Check compiler support of __builtin_available() 1242curl_internal_test(HAVE_BUILTIN_AVAILABLE) 1243 1244# Some other minor tests 1245 1246if(NOT HAVE_IN_ADDR_T) 1247 set(in_addr_t "unsigned long") 1248endif() 1249 1250# Check for nonblocking 1251set(HAVE_DISABLED_NONBLOCKING 1) 1252if(HAVE_FIONBIO OR 1253 HAVE_IOCTLSOCKET OR 1254 HAVE_IOCTLSOCKET_CASE OR 1255 HAVE_O_NONBLOCK) 1256 set(HAVE_DISABLED_NONBLOCKING) 1257endif() 1258 1259if(CMAKE_COMPILER_IS_GNUCC AND APPLE) 1260 include(CheckCCompilerFlag) 1261 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double) 1262 if(HAVE_C_FLAG_Wno_long_double) 1263 # The Mac version of GCC warns about use of long double. Disable it. 1264 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS) 1265 if(MPRINTF_COMPILE_FLAGS) 1266 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double") 1267 else() 1268 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double") 1269 endif() 1270 set_source_files_properties(mprintf.c PROPERTIES 1271 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS}) 1272 endif() 1273endif() 1274 1275# TODO test which of these headers are required 1276if(WIN32) 1277 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H}) 1278else() 1279 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H}) 1280 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H}) 1281 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H}) 1282endif() 1283 1284include(CMake/OtherTests.cmake) 1285 1286add_definitions(-DHAVE_CONFIG_H) 1287 1288# For Windows, all compilers used by CMake should support large files 1289if(WIN32) 1290 set(USE_WIN32_LARGE_FILES ON) 1291 1292 # Use the manifest embedded in the Windows Resource 1293 set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST") 1294 1295 # Check if crypto functions in wincrypt.h are actually available 1296 if(HAVE_WINCRYPT_H) 1297 check_symbol_exists(CryptAcquireContext "windows.h;wincrypt.h" USE_WINCRYPT) 1298 endif() 1299 if(USE_WINCRYPT) 1300 set(USE_WIN32_CRYPTO ON) 1301 endif() 1302 1303 # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL 1304 if(USE_WIN32_CRYPTO OR USE_SCHANNEL) 1305 list(APPEND CURL_LIBS "advapi32" "crypt32") 1306 endif() 1307 1308 # Matching logic used for Curl_win32_random() 1309 if(MINGW) 1310 check_c_source_compiles(" 1311 #include <_mingw.h> 1312 #if defined(__MINGW64_VERSION_MAJOR) 1313 #error 1314 #endif 1315 int main(void) { 1316 return 0; 1317 }" 1318 HAVE_MINGW_ORIGINAL) 1319 endif() 1320 1321 if(NOT HAVE_MINGW_ORIGINAL) 1322 list(APPEND CURL_LIBS "bcrypt") 1323 else() 1324 set(HAVE_FTRUNCATE OFF) 1325 endif() 1326endif() 1327 1328if(MSVC) 1329 # Disable default manifest added by CMake 1330 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO") 1331 1332 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) 1333 if(CMAKE_C_FLAGS MATCHES "/W[0-4]") 1334 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 1335 else() 1336 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") 1337 endif() 1338 1339 # Use multithreaded compilation on VS 2008+ 1340 if(MSVC_VERSION GREATER_EQUAL 1500) 1341 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") 1342 endif() 1343endif() 1344 1345if(CURL_WERROR) 1346 if(MSVC_VERSION) 1347 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") 1348 else() 1349 # this assumes clang or gcc style options 1350 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") 1351 endif() 1352endif() 1353 1354if(CURL_LTO) 1355 if(CMAKE_VERSION VERSION_LESS 3.9) 1356 message(FATAL_ERROR "Requested LTO but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9") 1357 endif() 1358 1359 cmake_policy(SET CMP0069 NEW) 1360 1361 include(CheckIPOSupported) 1362 check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT CURL_LTO_ERROR LANGUAGES C) 1363 if(CURL_HAS_LTO) 1364 message(STATUS "LTO supported and enabled") 1365 else() 1366 message(FATAL_ERROR "LTO was requested - but compiler doesn't support it\n${CURL_LTO_ERROR}") 1367 endif() 1368endif() 1369 1370 1371# Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it). 1372function(transform_makefile_inc INPUT_FILE OUTPUT_FILE) 1373 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT) 1374 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1375 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1376 1377 string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1378 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1379 string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1380 1381 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${} 1382 string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace @@ with ${}, even if that may not be read by CMake scripts. 1383 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT}) 1384 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}") 1385endfunction() 1386 1387include(GNUInstallDirs) 1388 1389set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) 1390set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") 1391set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") 1392set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") 1393set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") 1394 1395if(USE_MANUAL) 1396 add_subdirectory(docs) 1397endif() 1398 1399add_subdirectory(lib) 1400 1401if(BUILD_CURL_EXE) 1402 add_subdirectory(src) 1403endif() 1404 1405cmake_dependent_option(BUILD_TESTING "Build tests" 1406 ON "PERL_FOUND;NOT CURL_DISABLE_TESTS" 1407 OFF) 1408if(BUILD_TESTING) 1409 add_subdirectory(tests) 1410endif() 1411 1412# Helper to populate a list (_items) with a label when conditions (the remaining 1413# args) are satisfied 1414macro(_add_if label) 1415 # needs to be a macro to allow this indirection 1416 if(${ARGN}) 1417 set(_items ${_items} "${label}") 1418 endif() 1419endmacro() 1420 1421# NTLM support requires crypto function adaptions from various SSL libs 1422# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS 1423if(NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND 1424 (USE_OPENSSL OR USE_MBEDTLS OR USE_DARWINSSL OR USE_WIN32_CRYPTO)) 1425 set(use_curl_ntlm_core ON) 1426endif() 1427 1428# Clear list and try to detect available features 1429set(_items) 1430_add_if("SSL" SSL_ENABLED) 1431_add_if("IPv6" ENABLE_IPV6) 1432_add_if("unixsockets" USE_UNIX_SOCKETS) 1433_add_if("libz" HAVE_LIBZ) 1434_add_if("brotli" HAVE_BROTLI) 1435_add_if("zstd" HAVE_ZSTD) 1436_add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32) 1437_add_if("IDN" HAVE_LIBIDN2 OR USE_WIN32_IDN) 1438_add_if("Largefile" (SIZEOF_CURL_OFF_T GREATER 4) AND 1439 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES)) 1440# TODO SSP1 (Schannel) check is missing 1441_add_if("SSPI" USE_WINDOWS_SSPI) 1442_add_if("GSS-API" HAVE_GSSAPI) 1443_add_if("alt-svc" NOT CURL_DISABLE_ALTSVC) 1444_add_if("HSTS" NOT CURL_DISABLE_HSTS) 1445# TODO SSP1 missing for SPNEGO 1446_add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND 1447 (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) 1448_add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND 1449 (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) 1450# NTLM support requires crypto function adaptions from various SSL libs 1451# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS 1452_add_if("NTLM" NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND 1453 (use_curl_ntlm_core OR USE_WINDOWS_SSPI)) 1454# TODO missing option (autoconf: --enable-ntlm-wb) 1455_add_if("NTLM_WB" NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND 1456 (use_curl_ntlm_core OR USE_WINDOWS_SSPI) AND 1457 NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED) 1458# TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP 1459_add_if("TLS-SRP" USE_TLS_SRP) 1460# TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header 1461_add_if("HTTP2" USE_NGHTTP2) 1462_add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE) 1463_add_if("MultiSSL" CURL_WITH_MULTI_SSL) 1464# TODO wolfSSL only support this from v5.0.0 onwards 1465_add_if("HTTPS-proxy" SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS OR USE_NSS 1466 OR USE_SCHANNEL OR USE_RUSTLS OR USE_BEARSSL OR 1467 USE_MBEDTLS OR USE_SECTRANSP)) 1468_add_if("unicode" ENABLE_UNICODE) 1469_add_if("threadsafe" HAVE_ATOMIC OR (WIN32 AND 1470 HAVE_WIN32_WINNT GREATER_EQUAL 0x600)) 1471_add_if("PSL" USE_LIBPSL) 1472string(REPLACE ";" " " SUPPORT_FEATURES "${_items}") 1473message(STATUS "Enabled features: ${SUPPORT_FEATURES}") 1474 1475# Clear list and try to detect available protocols 1476set(_items) 1477_add_if("HTTP" NOT CURL_DISABLE_HTTP) 1478_add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED) 1479_add_if("FTP" NOT CURL_DISABLE_FTP) 1480_add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED) 1481_add_if("FILE" NOT CURL_DISABLE_FILE) 1482_add_if("TELNET" NOT CURL_DISABLE_TELNET) 1483_add_if("LDAP" NOT CURL_DISABLE_LDAP) 1484# CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS 1485# TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps) 1486_add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND 1487 ((USE_OPENLDAP AND SSL_ENABLED) OR 1488 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL))) 1489_add_if("DICT" NOT CURL_DISABLE_DICT) 1490_add_if("TFTP" NOT CURL_DISABLE_TFTP) 1491_add_if("GOPHER" NOT CURL_DISABLE_GOPHER) 1492_add_if("GOPHERS" NOT CURL_DISABLE_GOPHER AND SSL_ENABLED) 1493_add_if("POP3" NOT CURL_DISABLE_POP3) 1494_add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED) 1495_add_if("IMAP" NOT CURL_DISABLE_IMAP) 1496_add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED) 1497_add_if("SMB" NOT CURL_DISABLE_SMB AND 1498 use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4)) 1499_add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND 1500 use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4)) 1501_add_if("SMTP" NOT CURL_DISABLE_SMTP) 1502_add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED) 1503_add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH) 1504_add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH) 1505_add_if("RTSP" NOT CURL_DISABLE_RTSP) 1506_add_if("RTMP" USE_LIBRTMP) 1507_add_if("MQTT" NOT CURL_DISABLE_MQTT) 1508_add_if("WS" USE_WEBSOCKETS) 1509_add_if("WSS" USE_WEBSOCKETS) 1510if(_items) 1511 list(SORT _items) 1512endif() 1513string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}") 1514message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}") 1515 1516# Clear list and collect SSL backends 1517set(_items) 1518_add_if("Schannel" SSL_ENABLED AND USE_SCHANNEL) 1519_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL) 1520_add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP) 1521_add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS) 1522_add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL) 1523_add_if("NSS" SSL_ENABLED AND USE_NSS) 1524_add_if("wolfSSL" SSL_ENABLED AND USE_WOLFSSL) 1525if(_items) 1526 list(SORT _items) 1527endif() 1528string(REPLACE ";" " " SSL_BACKENDS "${_items}") 1529message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}") 1530 1531# curl-config needs the following options to be set. 1532set(CC "${CMAKE_C_COMPILER}") 1533# TODO probably put a -D... options here? 1534set(CONFIGURE_OPTIONS "") 1535# TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB? 1536set(CPPFLAG_CURL_STATICLIB "") 1537set(CURLVERSION "${CURL_VERSION}") 1538set(exec_prefix "\${prefix}") 1539set(includedir "\${prefix}/include") 1540set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}") 1541set(LIBCURL_LIBS "") 1542set(libdir "${CMAKE_INSTALL_PREFIX}/lib") 1543foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS}) 1544 if(TARGET "${_lib}") 1545 set(_libname "${_lib}") 1546 get_target_property(_imported "${_libname}" IMPORTED) 1547 if(NOT _imported) 1548 # Reading the LOCATION property on non-imported target will error out. 1549 # Assume the user won't need this information in the .pc file. 1550 continue() 1551 endif() 1552 get_target_property(_lib "${_libname}" LOCATION) 1553 if(NOT _lib) 1554 message(WARNING "Bad lib in library list: ${_libname}") 1555 continue() 1556 endif() 1557 endif() 1558 if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-") 1559 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}") 1560 else() 1561 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}") 1562 endif() 1563endforeach() 1564if(BUILD_SHARED_LIBS) 1565 set(ENABLE_SHARED "yes") 1566 set(ENABLE_STATIC "no") 1567 set(LIBCURL_NO_SHARED "") 1568else() 1569 set(ENABLE_SHARED "no") 1570 set(ENABLE_STATIC "yes") 1571 set(LIBCURL_NO_SHARED "${LIBCURL_LIBS}") 1572endif() 1573# "a" (Linux) or "lib" (Windows) 1574string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}") 1575set(prefix "${CMAKE_INSTALL_PREFIX}") 1576# Set this to "yes" to append all libraries on which -lcurl is dependent 1577set(REQUIRE_LIB_DEPS "no") 1578# SUPPORT_FEATURES 1579# SUPPORT_PROTOCOLS 1580set(VERSIONNUM "${CURL_VERSION_NUM}") 1581 1582# Finally generate a "curl-config" matching this config 1583# Use: 1584# * ENABLE_SHARED 1585# * ENABLE_STATIC 1586configure_file("${CURL_SOURCE_DIR}/curl-config.in" 1587 "${CURL_BINARY_DIR}/curl-config" @ONLY) 1588install(FILES "${CURL_BINARY_DIR}/curl-config" 1589 DESTINATION ${CMAKE_INSTALL_BINDIR} 1590 PERMISSIONS 1591 OWNER_READ OWNER_WRITE OWNER_EXECUTE 1592 GROUP_READ GROUP_EXECUTE 1593 WORLD_READ WORLD_EXECUTE) 1594 1595# Finally generate a pkg-config file matching this config 1596configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in" 1597 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY) 1598install(FILES "${CURL_BINARY_DIR}/libcurl.pc" 1599 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 1600 1601# install headers 1602install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl" 1603 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 1604 FILES_MATCHING PATTERN "*.h") 1605 1606include(CMakePackageConfigHelpers) 1607write_basic_package_version_file( 1608 "${version_config}" 1609 VERSION ${CURL_VERSION} 1610 COMPATIBILITY SameMajorVersion 1611) 1612 1613# Use: 1614# * TARGETS_EXPORT_NAME 1615# * PROJECT_NAME 1616configure_package_config_file(CMake/curl-config.cmake.in 1617 "${project_config}" 1618 INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR} 1619) 1620 1621if(CURL_ENABLE_EXPORT_TARGET) 1622 install( 1623 EXPORT "${TARGETS_EXPORT_NAME}" 1624 NAMESPACE "${PROJECT_NAME}::" 1625 DESTINATION ${CURL_INSTALL_CMAKE_DIR} 1626 ) 1627endif() 1628 1629install( 1630 FILES ${version_config} ${project_config} 1631 DESTINATION ${CURL_INSTALL_CMAKE_DIR} 1632) 1633 1634# Workaround for MSVS10 to avoid the Dialog Hell 1635# FIXME: This could be removed with future version of CMake. 1636if(MSVC_VERSION EQUAL 1600) 1637 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln") 1638 if(EXISTS "${CURL_SLN_FILENAME}") 1639 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n") 1640 endif() 1641endif() 1642 1643if(NOT TARGET curl_uninstall) 1644 configure_file( 1645 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in 1646 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake 1647 IMMEDIATE @ONLY) 1648 1649 add_custom_target(curl_uninstall 1650 COMMAND ${CMAKE_COMMAND} -P 1651 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake) 1652endif() 1653