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