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