1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 # SPDX-License-Identifier: curl
23 ###########################################################################
24 # curl/libcurl CMake script
25 # by Tetetest and Sukender (Benoit Neil)
28 # The output .so file lacks the soname number which we currently have within the lib/Makefile.am file
29 # Add full (4 or 5 libs) SSL support
30 # Add INSTALL target (EXTRA_DIST variables in Makefile.am may be moved to Makefile.inc so that CMake/CPack is aware of what's to include).
31 # Check on all possible platforms
32 # Test with as many configurations possible (With or without any option)
33 # Create scripts that help keeping the CMake build system up to date (to reduce maintenance). According to Tetetest:
34 # - lists of headers that 'configure' checks for;
35 # - curl-specific tests (the ones that are in m4/curl-*.m4 files);
36 # - (most obvious thing:) curl version numbers.
37 # Add documentation subproject
40 # (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
41 # (From Daniel Stenberg) The gcc command line use neither -g nor any -O options. As a developer, I also treasure our configure scripts's --enable-debug option that sets a long range of "picky" compiler options.
43 # Note: By default this CMake build script detects the version of some
44 # dependencies using `check_symbol_exists`. Those checks do not work
45 # in the case that both CURL and its dependency are included as
46 # sub-projects in a larger build using `FetchContent`. To support
47 # that case, additional variables may be defined by the parent
48 # project, ideally in the "extra" find package redirect file:
49 # https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package
51 # The following variables are available:
52 # HAVE_SSL_SET0_WBIO: `SSL_set0_wbio` present in OpenSSL/wolfSSL
53 # HAVE_OPENSSL_SRP: `SSL_CTX_set_srp_username` present in OpenSSL/wolfSSL
54 # HAVE_GNUTLS_SRP: `gnutls_srp_verifier` present in GnuTLS
55 # HAVE_SSL_CTX_SET_QUIC_METHOD: `SSL_CTX_set_quic_method` present in OpenSSL/wolfSSL
56 # HAVE_QUICHE_CONN_SET_QLOG_FD: `quiche_conn_set_qlog_fd` present in QUICHE
58 # For each of the above variables, if the variable is DEFINED (either
59 # to ON or OFF), the symbol detection will be skipped. If the
60 # variable is NOT DEFINED, the symbol detection will be performed.
62 cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
63 message(STATUS "Using CMake version ${CMAKE_VERSION}")
65 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
68 include(CMakeDependentOption)
69 include(CheckCCompilerFlag)
73 file(STRINGS ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS REGEX "#define LIBCURL_VERSION( |_NUM )")
74 string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
75 CURL_VERSION ${CURL_VERSION_H_CONTENTS})
76 string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
77 string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
78 CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
79 string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
82 # Setup package meta-data
84 message(STATUS "curl version=[${CURL_VERSION}]")
85 # SET(PACKAGE_TARNAME "curl")
86 # SET(PACKAGE_NAME "curl")
87 # SET(PACKAGE_VERSION "-")
88 # SET(PACKAGE_STRING "curl-")
89 # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.se/mail/")
90 set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
91 if(CMAKE_C_COMPILER_TARGET)
92 set(OS "\"${CMAKE_C_COMPILER_TARGET}\"")
94 set(OS "\"${CMAKE_SYSTEM_NAME}\"")
97 include_directories(${CURL_SOURCE_DIR}/include)
99 set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
101 option(CURL_WERROR "Turn compiler warnings into errors" OFF)
102 option(PICKY_COMPILER "Enable picky compiler options" ON)
103 option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
104 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
105 option(BUILD_STATIC_LIBS "Build static libraries" OFF)
106 option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
107 option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
108 option(CURL_DISABLE_INSTALL "Set to ON to disable instalation targets" OFF)
111 option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
112 option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
113 set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
114 if(CURL_TARGET_WINDOWS_VERSION)
115 add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
116 list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
117 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
120 add_definitions(-DUNICODE -D_UNICODE)
122 add_compile_options(-municode)
126 option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)
128 cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
132 option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
133 option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
135 include(PickyWarnings)
138 # DEBUGBUILD will be defined only for Debug builds
139 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
140 set(ENABLE_CURLDEBUG ON)
144 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
147 # For debug libs and exes, add "-d" postfix
148 if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
149 set(CMAKE_DEBUG_POSTFIX "-d")
152 set(LIB_STATIC "libcurl_static")
153 set(LIB_SHARED "libcurl_shared")
155 if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
156 set(BUILD_STATIC_LIBS ON)
158 if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS)
159 set(BUILD_STATIC_CURL ON)
160 elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS)
161 set(BUILD_STATIC_CURL OFF)
164 # lib flavour selected for curl tool
165 if(BUILD_STATIC_CURL)
166 set(LIB_SELECTED_FOR_EXE ${LIB_STATIC})
168 set(LIB_SELECTED_FOR_EXE ${LIB_SHARED})
171 # lib flavour selected for example and test programs.
172 if(BUILD_SHARED_LIBS)
173 set(LIB_SELECTED ${LIB_SHARED})
175 set(LIB_SELECTED ${LIB_STATIC})
178 # initialize CURL_LIBS
183 find_package(CARES REQUIRED)
184 list(APPEND CURL_LIBS ${CARES_LIBRARY})
187 include(CurlSymbolHiding)
189 option(CURL_ENABLE_EXPORT_TARGET "to enable cmake export target" ON)
190 mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
192 option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF)
193 mark_as_advanced(CURL_DISABLE_ALTSVC)
194 option(CURL_DISABLE_SRP "disables TLS-SRP support" OFF)
195 mark_as_advanced(CURL_DISABLE_SRP)
196 option(CURL_DISABLE_COOKIES "disables cookies support" OFF)
197 mark_as_advanced(CURL_DISABLE_COOKIES)
198 option(CURL_DISABLE_BASIC_AUTH "disables Basic authentication" OFF)
199 mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
200 option(CURL_DISABLE_BEARER_AUTH "disables Bearer authentication" OFF)
201 mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
202 option(CURL_DISABLE_DIGEST_AUTH "disables Digest authentication" OFF)
203 mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
204 option(CURL_DISABLE_KERBEROS_AUTH "disables Kerberos authentication" OFF)
205 mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
206 option(CURL_DISABLE_NEGOTIATE_AUTH "disables negotiate authentication" OFF)
207 mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
208 option(CURL_DISABLE_AWS "disables AWS-SIG4" OFF)
209 mark_as_advanced(CURL_DISABLE_AWS)
210 option(CURL_DISABLE_DICT "disables DICT" OFF)
211 mark_as_advanced(CURL_DISABLE_DICT)
212 option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF)
213 mark_as_advanced(CURL_DISABLE_DOH)
214 option(CURL_DISABLE_FILE "disables FILE" OFF)
215 mark_as_advanced(CURL_DISABLE_FILE)
216 cmake_dependent_option(CURL_DISABLE_FORM_API "disables form api" OFF
217 "NOT CURL_DISABLE_MIME" ON)
218 mark_as_advanced(CURL_DISABLE_FORM_API)
219 option(CURL_DISABLE_FTP "disables FTP" OFF)
220 mark_as_advanced(CURL_DISABLE_FTP)
221 option(CURL_DISABLE_GETOPTIONS "disables curl_easy_options API for existing options to curl_easy_setopt" OFF)
222 mark_as_advanced(CURL_DISABLE_GETOPTIONS)
223 option(CURL_DISABLE_GOPHER "disables Gopher" OFF)
224 mark_as_advanced(CURL_DISABLE_GOPHER)
225 option(CURL_DISABLE_HEADERS_API "disables headers-api support" OFF)
226 mark_as_advanced(CURL_DISABLE_HEADERS_API)
227 option(CURL_DISABLE_HSTS "disables HSTS support" OFF)
228 mark_as_advanced(CURL_DISABLE_HSTS)
229 option(CURL_DISABLE_HTTP "disables HTTP" OFF)
230 mark_as_advanced(CURL_DISABLE_HTTP)
231 option(CURL_DISABLE_HTTP_AUTH "disables all HTTP authentication methods" OFF)
232 mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
233 option(CURL_DISABLE_IMAP "disables IMAP" OFF)
234 mark_as_advanced(CURL_DISABLE_IMAP)
235 option(CURL_DISABLE_LDAP "disables LDAP" OFF)
236 mark_as_advanced(CURL_DISABLE_LDAP)
237 option(CURL_DISABLE_LDAPS "disables LDAPS" OFF)
238 mark_as_advanced(CURL_DISABLE_LDAPS)
239 option(CURL_DISABLE_LIBCURL_OPTION "disables --libcurl option from the curl tool" OFF)
240 mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
241 option(CURL_DISABLE_MIME "disables MIME support" OFF)
242 mark_as_advanced(CURL_DISABLE_MIME)
243 option(CURL_DISABLE_MQTT "disables MQTT" OFF)
244 mark_as_advanced(CURL_DISABLE_BINDLOCAL)
245 option(CURL_DISABLE_BINDLOCAL "disables local binding support" OFF)
246 mark_as_advanced(CURL_DISABLE_MQTT)
247 option(CURL_DISABLE_NETRC "disables netrc parser" OFF)
248 mark_as_advanced(CURL_DISABLE_NETRC)
249 option(CURL_DISABLE_NTLM "disables NTLM support" OFF)
250 mark_as_advanced(CURL_DISABLE_NTLM)
251 option(CURL_DISABLE_PARSEDATE "disables date parsing" OFF)
252 mark_as_advanced(CURL_DISABLE_PARSEDATE)
253 option(CURL_DISABLE_POP3 "disables POP3" OFF)
254 mark_as_advanced(CURL_DISABLE_POP3)
255 option(CURL_DISABLE_PROGRESS_METER "disables built-in progress meter" OFF)
256 mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
257 option(CURL_DISABLE_PROXY "disables proxy support" OFF)
258 mark_as_advanced(CURL_DISABLE_PROXY)
259 option(CURL_DISABLE_RTSP "disables RTSP" OFF)
260 mark_as_advanced(CURL_DISABLE_RTSP)
261 option(CURL_DISABLE_SHUFFLE_DNS "disables shuffle DNS feature" OFF)
262 mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
263 option(CURL_DISABLE_SMB "disables SMB" OFF)
264 mark_as_advanced(CURL_DISABLE_SMB)
265 option(CURL_DISABLE_SMTP "disables SMTP" OFF)
266 mark_as_advanced(CURL_DISABLE_SMTP)
267 option(CURL_DISABLE_SOCKETPAIR "disables use of socketpair for curl_multi_poll" OFF)
268 mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
269 option(CURL_DISABLE_TELNET "disables Telnet" OFF)
270 mark_as_advanced(CURL_DISABLE_TELNET)
271 option(CURL_DISABLE_TFTP "disables TFTP" OFF)
272 mark_as_advanced(CURL_DISABLE_TFTP)
273 option(CURL_DISABLE_VERBOSE_STRINGS "disables verbose strings" OFF)
274 mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
276 # Corresponds to HTTP_ONLY in lib/curl_setup.h
277 option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
278 mark_as_advanced(HTTP_ONLY)
281 set(CURL_DISABLE_DICT ON)
282 set(CURL_DISABLE_FILE ON)
283 set(CURL_DISABLE_FTP ON)
284 set(CURL_DISABLE_GOPHER ON)
285 set(CURL_DISABLE_IMAP ON)
286 set(CURL_DISABLE_LDAP ON)
287 set(CURL_DISABLE_LDAPS ON)
288 set(CURL_DISABLE_MQTT ON)
289 set(CURL_DISABLE_POP3 ON)
290 set(CURL_DISABLE_RTSP ON)
291 set(CURL_DISABLE_SMB ON)
292 set(CURL_DISABLE_SMTP ON)
293 set(CURL_DISABLE_TELNET ON)
294 set(CURL_DISABLE_TFTP ON)
297 option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
298 mark_as_advanced(ENABLE_IPV6)
299 if(ENABLE_IPV6 AND NOT WIN32)
300 include(CheckStructHasMember)
301 check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
302 HAVE_SOCKADDR_IN6_SIN6_ADDR)
303 check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
304 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
305 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
306 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
307 # Force the feature off as this name is used as guard macro...
309 CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
312 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_ARES)
313 set(use_core_foundation_and_core_services ON)
315 find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
316 if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
317 message(FATAL_ERROR "SystemConfiguration framework not found")
320 list(APPEND CURL_LIBS "-framework SystemConfiguration")
325 #nroff is currently only used when USE_MANUAL is set, so we can prevent the warning of no *NROFF if USE_MANUAL is OFF (or not defined), by not even looking for NROFF..
330 cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
331 ON "NROFF_USEFUL;PERL_FOUND"
339 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
340 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
341 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
344 # Disable warnings on Borland to avoid changing 3rd party code.
346 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
349 # If we are on AIX, do the _ALL_SOURCE magic
350 if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
354 # If we are on Haiku, make sure that the network library is brought in.
355 if(${CMAKE_SYSTEM_NAME} MATCHES Haiku)
356 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnetwork")
359 # Include all the necessary files for macros
360 include(CMakePushCheckState)
361 include(CheckFunctionExists)
362 include(CheckIncludeFile)
363 include(CheckIncludeFiles)
364 include(CheckLibraryExists)
365 include(CheckSymbolExists)
366 include(CheckTypeSize)
367 include(CheckCSourceCompiles)
369 # On windows preload settings
371 set(HAVE_WINDOWS_H 1)
372 set(HAVE_WS2TCPIP_H 1)
373 set(HAVE_WINSOCK2_H 1)
374 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
377 if(ENABLE_THREADED_RESOLVER)
379 set(USE_THREADS_WIN32 ON)
381 find_package(Threads REQUIRED)
382 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
383 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
384 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
388 # Check for all needed libraries
389 check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
391 set(CURL_LIBS "socket;${CURL_LIBS}")
394 check_function_exists(gethostname HAVE_GETHOSTNAME)
397 list(APPEND CURL_LIBS "ws2_32" "bcrypt")
399 list(APPEND CURL_LIBS "winmm")
403 # check SSL libraries
404 option(CURL_ENABLE_SSL "Enable SSL support" ON)
406 if(CURL_DEFAULT_SSL_BACKEND)
407 set(valid_default_ssl_backend FALSE)
411 cmake_dependent_option(CURL_USE_SECTRANSP "Enable Apple OS native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
414 cmake_dependent_option(CURL_USE_SCHANNEL "Enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
415 cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without OpenSSL" ON
416 CURL_USE_SCHANNEL OFF)
418 cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
419 cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
420 cmake_dependent_option(CURL_USE_WOLFSSL "Enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
421 cmake_dependent_option(CURL_USE_GNUTLS "Enable GnuTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
423 set(openssl_default ON)
424 if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_WOLFSSL)
425 set(openssl_default OFF)
427 cmake_dependent_option(CURL_USE_OPENSSL "Enable OpenSSL for SSL/TLS" ${openssl_default} CURL_ENABLE_SSL OFF)
428 option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF)
430 count_true(enabled_ssl_options_count
438 if(enabled_ssl_options_count GREATER "1")
439 set(CURL_WITH_MULTI_SSL ON)
442 if(CURL_USE_SCHANNEL)
444 set(USE_SCHANNEL ON) # Windows native SSL/TLS support
445 set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI
447 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "schannel")
448 set(valid_default_ssl_backend TRUE)
451 if(CURL_WINDOWS_SSPI)
452 set(USE_WINDOWS_SSPI ON)
455 if(CURL_USE_SECTRANSP)
456 set(use_core_foundation_and_core_services ON)
458 find_library(SECURITY_FRAMEWORK "Security")
459 if(NOT SECURITY_FRAMEWORK)
460 message(FATAL_ERROR "Security framework not found")
464 set(USE_SECTRANSP ON)
465 list(APPEND CURL_LIBS "-framework Security")
467 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport")
468 set(valid_default_ssl_backend TRUE)
472 if(use_core_foundation_and_core_services)
473 find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
474 find_library(CORESERVICES_FRAMEWORK "CoreServices")
476 if(NOT COREFOUNDATION_FRAMEWORK)
477 message(FATAL_ERROR "CoreFoundation framework not found")
479 if(NOT CORESERVICES_FRAMEWORK)
480 message(FATAL_ERROR "CoreServices framework not found")
483 list(APPEND CURL_LIBS "-framework CoreFoundation -framework CoreServices")
487 find_package(OpenSSL REQUIRED)
491 # Depend on OpenSSL via imported targets if supported by the running
492 # version of CMake. This allows our dependents to get our dependencies
494 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
495 list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
497 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
498 include_directories(${OPENSSL_INCLUDE_DIR})
501 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl")
502 set(valid_default_ssl_backend TRUE)
505 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
506 if(NOT DEFINED HAVE_BORINGSSL)
507 check_symbol_exists(OPENSSL_IS_BORINGSSL "openssl/base.h" HAVE_BORINGSSL)
509 if(NOT DEFINED HAVE_AWSLC)
510 check_symbol_exists(OPENSSL_IS_AWSLC "openssl/base.h" HAVE_AWSLC)
515 find_package(MbedTLS REQUIRED)
518 list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
519 include_directories(${MBEDTLS_INCLUDE_DIRS})
521 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "mbedtls")
522 set(valid_default_ssl_backend TRUE)
527 find_package(BearSSL REQUIRED)
530 list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
531 include_directories(${BEARSSL_INCLUDE_DIRS})
533 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "bearssl")
534 set(valid_default_ssl_backend TRUE)
539 find_package(WolfSSL REQUIRED)
542 list(APPEND CURL_LIBS ${WolfSSL_LIBRARIES})
543 include_directories(${WolfSSL_INCLUDE_DIRS})
545 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "wolfssl")
546 set(valid_default_ssl_backend TRUE)
551 find_package(GnuTLS REQUIRED)
554 list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES} "nettle")
555 include_directories(${GNUTLS_INCLUDE_DIRS})
557 if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls")
558 set(valid_default_ssl_backend TRUE)
561 if(NOT DEFINED HAVE_GNUTLS_SRP AND NOT CURL_DISABLE_SRP)
562 cmake_push_check_state()
563 set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
564 set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
565 check_symbol_exists(gnutls_srp_verifier "gnutls/gnutls.h" HAVE_GNUTLS_SRP)
566 cmake_pop_check_state()
570 if(CURL_DEFAULT_SSL_BACKEND AND NOT valid_default_ssl_backend)
571 message(FATAL_ERROR "CURL_DEFAULT_SSL_BACKEND '${CURL_DEFAULT_SSL_BACKEND}' not enabled.")
574 # Keep ZLIB detection after TLS detection,
575 # and before calling openssl_check_symbol_exists().
579 optional_dependency(ZLIB)
584 # Depend on ZLIB via imported targets if supported by the running
585 # version of CMake. This allows our dependents to get our dependencies
587 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
588 list(APPEND CURL_LIBS ZLIB::ZLIB)
590 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
591 include_directories(${ZLIB_INCLUDE_DIRS})
593 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
596 option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
599 find_package(Brotli REQUIRED)
602 set(CURL_LIBS "${BROTLI_LIBRARIES};${CURL_LIBS}") # For 'ld' linker. Emulate `list(PREPEND ...)` to stay compatible with <v3.15 CMake.
603 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
604 include_directories(${BROTLI_INCLUDE_DIRS})
605 list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
609 option(CURL_ZSTD "Set to ON to enable building curl with zstd support." OFF)
612 find_package(Zstd REQUIRED)
613 if(Zstd_FOUND AND NOT Zstd_VERSION VERSION_LESS "1.0.0")
615 list(APPEND CURL_LIBS ${Zstd_LIBRARIES})
616 include_directories(${Zstd_INCLUDE_DIRS})
618 message(WARNING "zstd v1.0.0 or newer is required, disabling zstd support.")
622 # Check symbol in OpenSSL-like TLS backends.
623 macro(openssl_check_symbol_exists SYMBOL FILES VARIABLE)
624 cmake_push_check_state()
626 set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
627 set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
629 list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
632 list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
633 list(APPEND CMAKE_REQUIRED_LIBRARIES "bcrypt") # for OpenSSL/LibreSSL
636 set(CMAKE_REQUIRED_INCLUDES "${WolfSSL_INCLUDE_DIRS}")
637 set(CMAKE_REQUIRED_LIBRARIES "${WolfSSL_LIBRARIES}")
639 list(APPEND CMAKE_REQUIRED_INCLUDES "${ZLIB_INCLUDE_DIRS}") # Public wolfSSL headers require zlib headers
640 list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
643 list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32" "crypt32")
645 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_UINTPTR_T) # to pull in stdint.h (as of wolfSSL v5.5.4)
647 check_symbol_exists("${SYMBOL}" "${FILES}" "${VARIABLE}")
648 cmake_pop_check_state()
651 # Ensure that the OpenSSL fork actually supports QUIC.
652 macro(openssl_check_quic)
653 if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD)
655 openssl_check_symbol_exists(SSL_CTX_set_quic_method "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD)
657 openssl_check_symbol_exists(wolfSSL_set_quic_method "wolfssl/options.h;wolfssl/openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD)
660 if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD)
661 message(FATAL_ERROR "QUIC support is missing in OpenSSL fork. Try setting -DOPENSSL_ROOT_DIR")
665 if(USE_OPENSSL OR USE_WOLFSSL)
666 if(NOT DEFINED HAVE_SSL_SET0_WBIO)
667 openssl_check_symbol_exists(SSL_set0_wbio "openssl/ssl.h" HAVE_SSL_SET0_WBIO)
669 if(NOT DEFINED HAVE_OPENSSL_SRP AND NOT CURL_DISABLE_SRP)
670 openssl_check_symbol_exists(SSL_CTX_set_srp_username "openssl/ssl.h" HAVE_OPENSSL_SRP)
674 option(USE_NGHTTP2 "Use nghttp2 library" OFF)
676 find_package(NGHTTP2 REQUIRED)
677 include_directories(${NGHTTP2_INCLUDE_DIRS})
678 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
681 option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF)
683 if(USE_OPENSSL OR USE_WOLFSSL)
685 find_package(NGTCP2 REQUIRED wolfSSL)
686 elseif(HAVE_BORINGSSL OR HAVE_AWSLC)
687 find_package(NGTCP2 REQUIRED BoringSSL)
689 find_package(NGTCP2 REQUIRED quictls)
693 find_package(NGTCP2 REQUIRED GnuTLS)
695 message(FATAL_ERROR "ngtcp2 requires OpenSSL, wolfSSL or GnuTLS")
698 include_directories(${NGTCP2_INCLUDE_DIRS})
699 list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES})
701 find_package(NGHTTP3 REQUIRED)
703 include_directories(${NGHTTP3_INCLUDE_DIRS})
704 list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
707 option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF)
710 message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
712 find_package(QUICHE REQUIRED)
713 if(NOT HAVE_BORINGSSL)
714 message(FATAL_ERROR "quiche requires BoringSSL")
718 include_directories(${QUICHE_INCLUDE_DIRS})
719 list(APPEND CURL_LIBS ${QUICHE_LIBRARIES})
720 if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD)
721 cmake_push_check_state()
722 set(CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}")
723 set(CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}")
724 check_symbol_exists(quiche_conn_set_qlog_fd "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD)
725 cmake_pop_check_state()
729 option(USE_MSH3 "Use msquic library for HTTP/3 support" OFF)
731 if(USE_NGTCP2 OR USE_QUICHE)
732 message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
735 include_directories(${MSH3_INCLUDE_DIRS})
736 list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
739 if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP))
743 if(NOT CURL_DISABLE_LDAP)
745 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
747 list(APPEND CURL_LIBS "wldap32")
748 if(NOT CURL_DISABLE_LDAPS)
749 set(HAVE_LDAP_SSL ON)
754 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
755 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
757 # Now that we know, we're not using windows LDAP...
758 if(NOT USE_WIN32_LDAP)
760 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
761 check_library_exists("${CMAKE_LDAP_LIB}" "ldap_init" "" HAVE_LIBLDAP)
763 check_library_exists("${CMAKE_LDAP_LIB};${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
765 check_library_exists("${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
768 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
769 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
770 if(CMAKE_LDAP_INCLUDE_DIR)
771 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
773 check_include_file_concat("ldap.h" HAVE_LDAP_H)
774 check_include_file_concat("lber.h" HAVE_LBER_H)
777 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
778 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
779 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
780 elseif(NOT HAVE_LIBLDAP)
781 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
782 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
783 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
785 if(CMAKE_LDAP_INCLUDE_DIR)
786 include_directories(${CMAKE_LDAP_INCLUDE_DIR})
791 list(APPEND _HEADER_LIST "windows.h")
794 list(APPEND _HEADER_LIST "sys/types.h")
796 list(APPEND _HEADER_LIST "ldap.h")
798 set(_INCLUDE_STRING "")
799 foreach(_HEADER ${_HEADER_LIST})
800 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
803 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DLDAP_DEPRECATED=1)
804 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
805 set(CURL_LIBS "${CMAKE_LDAP_LIB};${CURL_LIBS}")
807 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
808 set(CURL_LIBS "${CMAKE_LBER_LIB};${CURL_LIBS}")
811 check_c_source_compiles("
813 int main(int argc, char ** argv)
815 BerValue *bvp = NULL;
816 BerElement *bep = ber_init(bvp);
823 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
826 check_function_exists(ldap_url_parse HAVE_LDAP_URL_PARSE)
827 check_function_exists(ldap_init_fd HAVE_LDAP_INIT_FD)
829 unset(CMAKE_REQUIRED_LIBRARIES)
831 check_include_file("ldap_ssl.h" HAVE_LDAP_SSL_H)
833 if(HAVE_LDAP_INIT_FD)
835 add_definitions("-DLDAP_DEPRECATED=1")
837 if(NOT CURL_DISABLE_LDAPS)
838 set(HAVE_LDAP_SSL ON)
845 if(CURL_DISABLE_LDAP)
846 if(NOT CURL_DISABLE_LDAPS)
847 message(STATUS "LDAP needs to be enabled to support LDAPS")
848 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
853 option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
855 check_library_exists("idn2" "idn2_lookup_ul" "" HAVE_LIBIDN2)
857 set(CURL_LIBS "idn2;${CURL_LIBS}")
858 check_include_file_concat("idn2.h" HAVE_IDN2_H)
861 set(HAVE_LIBIDN2 OFF)
865 option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF)
867 list(APPEND CURL_LIBS "normaliz")
872 option(CURL_USE_LIBPSL "Use libPSL" ON)
873 mark_as_advanced(CURL_USE_LIBPSL)
879 list(APPEND CURL_LIBS ${LIBPSL_LIBRARY})
880 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIR}")
881 include_directories("${LIBPSL_INCLUDE_DIR}")
887 option(CURL_USE_LIBSSH2 "Use libSSH2" ON)
888 mark_as_advanced(CURL_USE_LIBSSH2)
892 find_package(LibSSH2)
894 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
895 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
896 include_directories("${LIBSSH2_INCLUDE_DIR}")
902 option(CURL_USE_LIBSSH "Use libSSH" OFF)
903 mark_as_advanced(CURL_USE_LIBSSH)
904 if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
905 find_package(libssh CONFIG)
907 message(STATUS "Found libssh ${libssh_VERSION}")
908 # Use imported target for include and library paths.
909 list(APPEND CURL_LIBS ssh)
914 option(CURL_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
915 mark_as_advanced(CURL_USE_GSSAPI)
920 set(HAVE_GSSAPI ${GSS_FOUND})
923 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
925 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
926 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
927 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
928 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
930 if(GSS_FLAVOUR STREQUAL "Heimdal")
931 set(HAVE_GSSHEIMDAL ON)
934 set(_INCLUDE_LIST "")
935 if(HAVE_GSSAPI_GSSAPI_H)
936 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
938 if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
939 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
941 if(HAVE_GSSAPI_GSSAPI_KRB5_H)
942 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
945 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
946 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
948 foreach(_dir ${GSS_LINK_DIRECTORIES})
949 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
952 if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE)
953 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
954 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
955 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
956 unset(CMAKE_REQUIRED_LIBRARIES)
958 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
959 set(HAVE_OLD_GSSMIT ON)
963 include_directories(${GSS_INCLUDE_DIR})
964 link_directories(${GSS_LINK_DIRECTORIES})
965 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
966 string(REPLACE ";" " " GSS_LINKER_FLAGS "${GSS_LINKER_FLAGS}")
967 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
968 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
969 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
970 list(APPEND CURL_LIBS ${GSS_LIBRARIES})
973 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
977 option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
978 if(ENABLE_UNIX_SOCKETS)
979 include(CheckStructHasMember)
981 set(USE_UNIX_SOCKETS ON)
983 check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
986 unset(USE_UNIX_SOCKETS CACHE)
993 set(CURL_CA_BUNDLE "auto" CACHE STRING
994 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
995 set(CURL_CA_FALLBACK OFF CACHE BOOL
996 "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
997 set(CURL_CA_PATH "auto" CACHE STRING
998 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
1000 if("${CURL_CA_BUNDLE}" STREQUAL "")
1001 message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
1002 elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
1003 unset(CURL_CA_BUNDLE CACHE)
1004 elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
1005 unset(CURL_CA_BUNDLE CACHE)
1006 if(NOT CMAKE_CROSSCOMPILING)
1007 set(CURL_CA_BUNDLE_AUTODETECT TRUE)
1010 set(CURL_CA_BUNDLE_SET TRUE)
1013 if("${CURL_CA_PATH}" STREQUAL "")
1014 message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
1015 elseif("${CURL_CA_PATH}" STREQUAL "none")
1016 unset(CURL_CA_PATH CACHE)
1017 elseif("${CURL_CA_PATH}" STREQUAL "auto")
1018 unset(CURL_CA_PATH CACHE)
1019 if(NOT CMAKE_CROSSCOMPILING)
1020 set(CURL_CA_PATH_AUTODETECT TRUE)
1023 set(CURL_CA_PATH_SET TRUE)
1026 if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
1027 # Skip autodetection of unset CA path because CA bundle is set explicitly
1028 elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
1029 # Skip autodetection of unset CA bundle because CA path is set explicitly
1030 elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
1031 # first try autodetecting a CA bundle, then a CA path
1033 if(CURL_CA_BUNDLE_AUTODETECT)
1034 set(SEARCH_CA_BUNDLE_PATHS
1035 /etc/ssl/certs/ca-certificates.crt
1036 /etc/pki/tls/certs/ca-bundle.crt
1037 /usr/share/ssl/certs/ca-bundle.crt
1038 /usr/local/share/certs/ca-root-nss.crt
1041 foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
1042 if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
1043 message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
1044 set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}" CACHE STRING
1045 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
1046 set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
1052 if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
1053 if(EXISTS "/etc/ssl/certs")
1054 set(CURL_CA_PATH "/etc/ssl/certs" CACHE STRING
1055 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
1056 set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
1061 if(CURL_CA_PATH_SET AND
1067 "CA path only supported by OpenSSL, wolfSSL, GnuTLS or mbedTLS. "
1068 "Set CURL_CA_PATH=none or enable one of those TLS backends.")
1071 # Check for header files
1073 check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
1074 check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
1075 check_include_file_concat("windows.h" HAVE_WINDOWS_H)
1079 # detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
1080 curl_internal_test(HAVE_WIN32_WINNT)
1081 if(HAVE_WIN32_WINNT)
1082 string(REGEX MATCH ".*_WIN32_WINNT=0x[0-9a-fA-F]+" OUTPUT "${OUTPUT}")
1083 string(REGEX REPLACE ".*_WIN32_WINNT=" "" OUTPUT "${OUTPUT}")
1084 string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" OUTPUT "${OUTPUT}") # pad to 4 digits
1085 string(TOLOWER "${OUTPUT}" HAVE_WIN32_WINNT)
1086 message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
1088 # avoid storing HAVE_WIN32_WINNT in CMake cache
1089 unset(HAVE_WIN32_WINNT CACHE)
1091 if(HAVE_WIN32_WINNT)
1092 if(HAVE_WIN32_WINNT STRLESS "0x0501")
1093 # Windows XP is required for freeaddrinfo, getaddrinfo
1094 message(FATAL_ERROR "Building for Windows XP or newer is required.")
1097 # pre-fill detection results based on target OS version
1099 if(HAVE_WIN32_WINNT STRLESS "0x0600")
1100 set(HAVE_INET_NTOP 0)
1101 set(HAVE_INET_PTON 0)
1102 else() # Windows Vista or newer
1103 set(HAVE_INET_NTOP 1)
1104 set(HAVE_INET_PTON 1)
1106 unset(HAVE_INET_NTOP CACHE)
1107 unset(HAVE_INET_PTON CACHE)
1112 check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
1113 check_include_file_concat("sys/wait.h" HAVE_SYS_WAIT_H)
1114 check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
1115 check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
1116 check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
1117 check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
1118 check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
1119 check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
1120 check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
1121 check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
1122 check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
1123 check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
1124 check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
1125 check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
1126 check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
1127 check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
1128 check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
1129 check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
1130 check_include_file_concat("io.h" HAVE_IO_H)
1131 check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
1132 check_include_file_concat("locale.h" HAVE_LOCALE_H)
1133 check_include_file_concat("net/if.h" HAVE_NET_IF_H)
1134 check_include_file_concat("netdb.h" HAVE_NETDB_H)
1135 check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
1136 check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
1137 check_include_file_concat("netinet/udp.h" HAVE_NETINET_UDP_H)
1138 check_include_file("linux/tcp.h" HAVE_LINUX_TCP_H)
1140 check_include_file_concat("poll.h" HAVE_POLL_H)
1141 check_include_file_concat("pwd.h" HAVE_PWD_H)
1142 check_include_file_concat("stdatomic.h" HAVE_STDATOMIC_H)
1143 check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
1144 check_include_file_concat("strings.h" HAVE_STRINGS_H)
1145 check_include_file_concat("stropts.h" HAVE_STROPTS_H)
1146 check_include_file_concat("termio.h" HAVE_TERMIO_H)
1147 check_include_file_concat("termios.h" HAVE_TERMIOS_H)
1148 check_include_file_concat("unistd.h" HAVE_UNISTD_H)
1149 check_include_file_concat("utime.h" HAVE_UTIME_H)
1151 check_type_size(size_t SIZEOF_SIZE_T)
1152 check_type_size(ssize_t SIZEOF_SSIZE_T)
1153 check_type_size("long long" SIZEOF_LONG_LONG)
1154 check_type_size("long" SIZEOF_LONG)
1155 check_type_size("int" SIZEOF_INT)
1156 check_type_size("__int64" SIZEOF___INT64)
1157 check_type_size("time_t" SIZEOF_TIME_T)
1158 check_type_size("suseconds_t" SIZEOF_SUSECONDS_T)
1159 if(NOT HAVE_SIZEOF_SSIZE_T)
1160 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
1163 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
1164 set(ssize_t __int64)
1167 # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
1169 if(SIZEOF_LONG_LONG)
1170 set(HAVE_LONGLONG 1)
1172 if(SIZEOF_SUSECONDS_T)
1173 set(HAVE_SUSECONDS_T 1)
1176 if(NOT CMAKE_CROSSCOMPILING)
1177 find_file(RANDOM_FILE urandom /dev)
1178 mark_as_advanced(RANDOM_FILE)
1181 # Check for some functions that are used
1183 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
1184 elseif(HAVE_LIBSOCKET)
1185 set(CMAKE_REQUIRED_LIBRARIES socket)
1188 check_symbol_exists(fnmatch "${CURL_INCLUDES};fnmatch.h" HAVE_FNMATCH)
1189 check_symbol_exists(basename "${CURL_INCLUDES};string.h" HAVE_BASENAME)
1190 check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
1191 check_symbol_exists(sched_yield "${CURL_INCLUDES};sched.h" HAVE_SCHED_YIELD)
1192 check_symbol_exists(socketpair "${CURL_INCLUDES}" HAVE_SOCKETPAIR)
1193 check_symbol_exists(recv "${CURL_INCLUDES}" HAVE_RECV)
1194 check_symbol_exists(send "${CURL_INCLUDES}" HAVE_SEND)
1195 check_symbol_exists(sendmsg "${CURL_INCLUDES}" HAVE_SENDMSG)
1196 check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
1197 check_symbol_exists(strdup "${CURL_INCLUDES};string.h" HAVE_STRDUP)
1198 check_symbol_exists(strtok_r "${CURL_INCLUDES};string.h" HAVE_STRTOK_R)
1199 check_symbol_exists(strcasecmp "${CURL_INCLUDES};string.h" HAVE_STRCASECMP)
1200 check_symbol_exists(stricmp "${CURL_INCLUDES};string.h" HAVE_STRICMP)
1201 check_symbol_exists(strcmpi "${CURL_INCLUDES};string.h" HAVE_STRCMPI)
1202 check_symbol_exists(memrchr "${CURL_INCLUDES};string.h" HAVE_MEMRCHR)
1203 check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
1204 check_symbol_exists(arc4random "${CURL_INCLUDES};stdlib.h" HAVE_ARC4RANDOM)
1205 check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
1206 check_symbol_exists(getppid "${CURL_INCLUDES}" HAVE_GETPPID)
1207 check_symbol_exists(utimes "${CURL_INCLUDES}" HAVE_UTIMES)
1209 check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
1210 check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
1211 check_symbol_exists(sigsetjmp "${CURL_INCLUDES};setjmp.h" HAVE_SIGSETJMP)
1212 check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
1213 check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
1214 check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
1215 check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
1216 check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
1217 check_symbol_exists(gmtime_r "${CURL_INCLUDES};stdlib.h;time.h" HAVE_GMTIME_R)
1219 check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
1221 check_symbol_exists(signal "${CURL_INCLUDES};signal.h" HAVE_SIGNAL)
1222 check_symbol_exists(strtoll "${CURL_INCLUDES};stdlib.h" HAVE_STRTOLL)
1223 check_symbol_exists(strerror_r "${CURL_INCLUDES};stdlib.h;string.h" HAVE_STRERROR_R)
1224 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
1225 check_symbol_exists(siginterrupt "${CURL_INCLUDES};signal.h" HAVE_SIGINTERRUPT)
1226 check_symbol_exists(getaddrinfo "${CURL_INCLUDES};stdlib.h;string.h" HAVE_GETADDRINFO)
1227 check_symbol_exists(getifaddrs "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS)
1228 check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
1229 check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
1230 check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
1231 check_symbol_exists(fseeko "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
1232 check_symbol_exists(_fseeki64 "${CURL_INCLUDES};stdio.h" HAVE__FSEEKI64)
1233 check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
1234 check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
1235 check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
1236 check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
1237 check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
1238 check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
1239 check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
1242 set(HAVE_DECL_FSEEKO 1)
1245 if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900))
1246 # earlier MSVC compilers had faulty snprintf implementations
1247 check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
1249 check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
1250 check_symbol_exists(inet_ntop "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP)
1251 if(MSVC AND (MSVC_VERSION LESS_EQUAL 1600))
1252 set(HAVE_INET_NTOP OFF)
1254 check_symbol_exists(inet_pton "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON)
1256 check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
1258 foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
1259 curl_internal_test(${CURL_TEST})
1263 set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
1264 check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T)
1265 set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T})
1266 set(CMAKE_EXTRA_INCLUDE_FILES "")
1269 set(CMAKE_EXTRA_INCLUDE_FILES "ws2def.h")
1270 check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY)
1271 set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY})
1272 set(CMAKE_EXTRA_INCLUDE_FILES "")
1275 # Do curl specific tests
1277 HAVE_FCNTL_O_NONBLOCK
1279 HAVE_IOCTLSOCKET_CAMEL
1280 HAVE_IOCTLSOCKET_CAMEL_FIONBIO
1281 HAVE_IOCTLSOCKET_FIONBIO
1283 HAVE_IOCTL_SIOCGIFADDR
1284 HAVE_SETSOCKOPT_SO_NONBLOCK
1286 HAVE_GETHOSTBYNAME_R_3
1287 HAVE_GETHOSTBYNAME_R_5
1288 HAVE_GETHOSTBYNAME_R_6
1289 HAVE_GETHOSTBYNAME_R_3_REENTRANT
1290 HAVE_GETHOSTBYNAME_R_5_REENTRANT
1291 HAVE_GETHOSTBYNAME_R_6_REENTRANT
1295 HAVE_FILE_OFFSET_BITS
1298 curl_internal_test(${CURL_TEST})
1301 if(HAVE_FILE_OFFSET_BITS)
1302 set(_FILE_OFFSET_BITS 64)
1303 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
1305 check_type_size("off_t" SIZEOF_OFF_T)
1307 # include this header to get the type
1308 set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
1309 set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
1310 check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
1311 set(CMAKE_EXTRA_INCLUDE_FILES "curl/curl.h")
1312 check_type_size("curl_socket_t" SIZEOF_CURL_SOCKET_T)
1313 set(CMAKE_EXTRA_INCLUDE_FILES "")
1315 if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
1316 # on not-Windows and not-crosscompiling, check for writable argv[]
1317 include(CheckCSourceRuns)
1318 check_c_source_runs("
1319 int main(int argc, char **argv)
1323 return (argv[0][0] == ' ')?0:1;
1324 }" HAVE_WRITABLE_ARGV)
1327 set(CMAKE_REQUIRED_FLAGS)
1329 option(ENABLE_WEBSOCKETS "Set to ON to enable EXPERIMENTAL websockets" OFF)
1331 if(ENABLE_WEBSOCKETS)
1332 if(${SIZEOF_CURL_OFF_T} GREATER "4")
1333 set(USE_WEBSOCKETS ON)
1335 message(WARNING "curl_off_t is too small to enable WebSockets")
1340 HAVE_GLIBC_STRERROR_R
1341 HAVE_POSIX_STRERROR_R
1343 curl_internal_test(${CURL_TEST})
1346 # Check for reentrant
1348 HAVE_GETHOSTBYNAME_R_3
1349 HAVE_GETHOSTBYNAME_R_5
1350 HAVE_GETHOSTBYNAME_R_6)
1351 if(NOT ${CURL_TEST})
1352 if(${CURL_TEST}_REENTRANT)
1353 set(NEED_REENTRANT 1)
1360 HAVE_GETHOSTBYNAME_R_3
1361 HAVE_GETHOSTBYNAME_R_5
1362 HAVE_GETHOSTBYNAME_R_6)
1364 if(${CURL_TEST}_REENTRANT)
1371 # Check clock_gettime(CLOCK_MONOTONIC, x) support
1372 curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
1375 # Check compiler support of __builtin_available()
1376 curl_internal_test(HAVE_BUILTIN_AVAILABLE)
1378 # Some other minor tests
1380 if(NOT HAVE_IN_ADDR_T)
1381 set(in_addr_t "unsigned long")
1384 # Check for nonblocking
1385 set(HAVE_DISABLED_NONBLOCKING 1)
1388 HAVE_IOCTLSOCKET_CASE OR
1390 set(HAVE_DISABLED_NONBLOCKING)
1393 if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1394 include(CheckCCompilerFlag)
1395 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1396 if(HAVE_C_FLAG_Wno_long_double)
1397 # The Mac version of GCC warns about use of long double. Disable it.
1398 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1399 if(MPRINTF_COMPILE_FLAGS)
1400 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1402 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1404 set_source_files_properties(mprintf.c PROPERTIES
1405 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1409 # TODO test which of these headers are required
1411 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
1413 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
1414 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
1415 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
1418 include(CMake/OtherTests.cmake)
1420 add_definitions(-DHAVE_CONFIG_H)
1422 # For Windows, all compilers used by CMake should support large files
1424 set(USE_WIN32_LARGE_FILES ON)
1426 # Use the manifest embedded in the Windows Resource
1427 set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1429 # We use crypto functions that are not available for UWP apps
1430 if(NOT WINDOWS_STORE)
1431 set(USE_WIN32_CRYPTO ON)
1434 # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL
1435 if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
1436 list(APPEND CURL_LIBS "advapi32" "crypt32")
1441 # Disable default manifest added by CMake
1442 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1444 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1445 if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1446 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1448 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1451 # Use multithreaded compilation on VS 2008+
1452 if(MSVC_VERSION GREATER_EQUAL 1500)
1453 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
1459 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1461 # this assumes clang or gcc style options
1462 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1467 if(CMAKE_VERSION VERSION_LESS 3.9)
1468 message(FATAL_ERROR "Requested LTO but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
1471 cmake_policy(SET CMP0069 NEW)
1473 include(CheckIPOSupported)
1474 check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT CURL_LTO_ERROR LANGUAGES C)
1476 message(STATUS "LTO supported and enabled")
1478 message(FATAL_ERROR "LTO was requested - but compiler doesn't support it\n${CURL_LTO_ERROR}")
1483 # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1484 function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
1485 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1486 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1487 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1489 string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1490 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1491 string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1493 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
1494 string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace @@ with ${}, even if that may not be read by CMake scripts.
1495 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1496 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}")
1499 include(GNUInstallDirs)
1501 set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
1502 set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
1503 set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
1504 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
1505 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
1508 add_subdirectory(docs)
1511 add_subdirectory(lib)
1514 add_subdirectory(src)
1517 cmake_dependent_option(BUILD_TESTING "Build tests"
1518 ON "PERL_FOUND;NOT CURL_DISABLE_TESTS"
1521 add_subdirectory(tests)
1524 if(NOT CURL_DISABLE_INSTALL)
1526 # Helper to populate a list (_items) with a label when conditions (the remaining
1527 # args) are satisfied
1528 macro(_add_if label)
1529 # needs to be a macro to allow this indirection
1531 set(_items ${_items} "${label}")
1535 # NTLM support requires crypto function adaptions from various SSL libs
1536 # TODO alternative SSL libs tests for SSP1, GnuTLS, NSS
1537 if(NOT (CURL_DISABLE_NTLM) AND
1538 (USE_OPENSSL OR USE_MBEDTLS OR USE_DARWINSSL OR USE_WIN32_CRYPTO OR USE_GNUTLS))
1539 set(use_curl_ntlm_core ON)
1542 # Clear list and try to detect available features
1544 _add_if("SSL" SSL_ENABLED)
1545 _add_if("IPv6" ENABLE_IPV6)
1546 _add_if("UnixSockets" USE_UNIX_SOCKETS)
1547 _add_if("libz" HAVE_LIBZ)
1548 _add_if("brotli" HAVE_BROTLI)
1549 _add_if("zstd" HAVE_ZSTD)
1550 _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1551 _add_if("IDN" HAVE_LIBIDN2 OR USE_WIN32_IDN)
1552 _add_if("Largefile" (SIZEOF_CURL_OFF_T GREATER 4) AND
1553 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
1554 # TODO SSP1 (Schannel) check is missing
1555 _add_if("SSPI" USE_WINDOWS_SSPI)
1556 _add_if("GSS-API" HAVE_GSSAPI)
1557 _add_if("alt-svc" NOT CURL_DISABLE_ALTSVC)
1558 _add_if("HSTS" NOT CURL_DISABLE_HSTS)
1559 # TODO SSP1 missing for SPNEGO
1560 _add_if("SPNEGO" NOT CURL_DISABLE_NEGOTIATE_AUTH AND
1561 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1562 _add_if("Kerberos" NOT CURL_DISABLE_KERBEROS_AUTH AND
1563 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1564 # NTLM support requires crypto function adaptions from various SSL libs
1565 # TODO alternative SSL libs tests for SSP1, GnuTLS, NSS
1566 _add_if("NTLM" NOT (CURL_DISABLE_NTLM) AND
1567 (use_curl_ntlm_core OR USE_WINDOWS_SSPI))
1568 # TODO missing option (autoconf: --enable-ntlm-wb)
1569 _add_if("NTLM_WB" NOT (CURL_DISABLE_NTLM) AND
1570 (use_curl_ntlm_core OR USE_WINDOWS_SSPI) AND
1571 NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
1572 _add_if("TLS-SRP" USE_TLS_SRP)
1573 # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
1574 _add_if("HTTP2" USE_NGHTTP2)
1575 _add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE)
1576 _add_if("MultiSSL" CURL_WITH_MULTI_SSL)
1577 # TODO wolfSSL only support this from v5.0.0 onwards
1578 _add_if("HTTPS-proxy" SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS
1579 OR USE_SCHANNEL OR USE_RUSTLS OR USE_BEARSSL OR
1580 USE_MBEDTLS OR USE_SECTRANSP))
1581 _add_if("unicode" ENABLE_UNICODE)
1582 _add_if("threadsafe" HAVE_ATOMIC OR
1583 (USE_THREADS_POSIX AND HAVE_PTHREAD_H) OR
1584 (WIN32 AND HAVE_WIN32_WINNT GREATER_EQUAL 0x600))
1585 _add_if("PSL" USE_LIBPSL)
1586 string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1587 message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1589 # Clear list and try to detect available protocols
1591 _add_if("HTTP" NOT CURL_DISABLE_HTTP)
1592 _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1593 _add_if("FTP" NOT CURL_DISABLE_FTP)
1594 _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1595 _add_if("FILE" NOT CURL_DISABLE_FILE)
1596 _add_if("TELNET" NOT CURL_DISABLE_TELNET)
1597 _add_if("LDAP" NOT CURL_DISABLE_LDAP)
1598 # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1599 _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
1600 ((USE_OPENLDAP AND SSL_ENABLED) OR
1601 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1602 _add_if("DICT" NOT CURL_DISABLE_DICT)
1603 _add_if("TFTP" NOT CURL_DISABLE_TFTP)
1604 _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
1605 _add_if("GOPHERS" NOT CURL_DISABLE_GOPHER AND SSL_ENABLED)
1606 _add_if("POP3" NOT CURL_DISABLE_POP3)
1607 _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1608 _add_if("IMAP" NOT CURL_DISABLE_IMAP)
1609 _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1610 _add_if("SMB" NOT CURL_DISABLE_SMB AND
1611 use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
1612 _add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND
1613 use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
1614 _add_if("SMTP" NOT CURL_DISABLE_SMTP)
1615 _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1616 _add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH)
1617 _add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH)
1618 _add_if("RTSP" NOT CURL_DISABLE_RTSP)
1619 _add_if("RTMP" USE_LIBRTMP)
1620 _add_if("MQTT" NOT CURL_DISABLE_MQTT)
1621 _add_if("WS" USE_WEBSOCKETS)
1622 _add_if("WSS" USE_WEBSOCKETS)
1626 string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1627 message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1629 # Clear list and collect SSL backends
1631 _add_if("Schannel" SSL_ENABLED AND USE_SCHANNEL)
1632 _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
1633 _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
1634 _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
1635 _add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL)
1636 _add_if("wolfSSL" SSL_ENABLED AND USE_WOLFSSL)
1637 _add_if("GnuTLS" SSL_ENABLED AND USE_GNUTLS)
1642 string(REPLACE ";" " " SSL_BACKENDS "${_items}")
1643 message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
1644 if(CURL_DEFAULT_SSL_BACKEND)
1645 message(STATUS "Default SSL backend: ${CURL_DEFAULT_SSL_BACKEND}")
1648 # curl-config needs the following options to be set.
1649 set(CC "${CMAKE_C_COMPILER}")
1650 # TODO probably put a -D... options here?
1651 set(CONFIGURE_OPTIONS "")
1652 set(CURLVERSION "${CURL_VERSION}")
1653 set(exec_prefix "\${prefix}")
1654 set(includedir "\${prefix}/include")
1655 set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
1656 set(LIBCURL_LIBS "")
1657 set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
1658 foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
1659 if(TARGET "${_lib}")
1660 set(_libname "${_lib}")
1661 get_target_property(_imported "${_libname}" IMPORTED)
1663 # Reading the LOCATION property on non-imported target will error out.
1664 # Assume the user won't need this information in the .pc file.
1667 get_target_property(_lib "${_libname}" LOCATION)
1669 message(WARNING "Bad lib in library list: ${_libname}")
1673 if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
1674 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
1676 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
1679 if(BUILD_SHARED_LIBS)
1680 set(ENABLE_SHARED "yes")
1681 set(LIBCURL_NO_SHARED "")
1682 set(CPPFLAG_CURL_STATICLIB "")
1684 set(ENABLE_SHARED "no")
1685 set(LIBCURL_NO_SHARED "${LIBCURL_LIBS}")
1686 set(CPPFLAG_CURL_STATICLIB "-DCURL_STATICLIB")
1688 if(BUILD_STATIC_LIBS)
1689 set(ENABLE_STATIC "yes")
1691 set(ENABLE_STATIC "no")
1693 # "a" (Linux) or "lib" (Windows)
1694 string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1695 set(prefix "${CMAKE_INSTALL_PREFIX}")
1696 # Set this to "yes" to append all libraries on which -lcurl is dependent
1697 set(REQUIRE_LIB_DEPS "no")
1700 set(VERSIONNUM "${CURL_VERSION_NUM}")
1702 # Finally generate a "curl-config" matching this config
1706 configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1707 "${CURL_BINARY_DIR}/curl-config" @ONLY)
1708 install(FILES "${CURL_BINARY_DIR}/curl-config"
1709 DESTINATION ${CMAKE_INSTALL_BINDIR}
1711 OWNER_READ OWNER_WRITE OWNER_EXECUTE
1712 GROUP_READ GROUP_EXECUTE
1713 WORLD_READ WORLD_EXECUTE)
1715 # Finally generate a pkg-config file matching this config
1716 configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1717 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
1718 install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
1719 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1722 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1723 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1724 FILES_MATCHING PATTERN "*.h")
1726 include(CMakePackageConfigHelpers)
1727 write_basic_package_version_file(
1729 VERSION ${CURL_VERSION}
1730 COMPATIBILITY SameMajorVersion
1732 file(READ "${version_config}" generated_version_config)
1733 file(WRITE "${version_config}"
1734 "if(NOT PACKAGE_FIND_VERSION_RANGE AND PACKAGE_FIND_VERSION_MAJOR STREQUAL \"7\")
1735 # Version 8 satisfies version 7... requirements
1736 set(PACKAGE_FIND_VERSION_MAJOR 8)
1737 set(PACKAGE_FIND_VERSION_COUNT 1)
1739 ${generated_version_config}"
1743 # * TARGETS_EXPORT_NAME
1745 configure_package_config_file(CMake/curl-config.cmake.in
1747 INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1750 if(CURL_ENABLE_EXPORT_TARGET)
1752 EXPORT "${TARGETS_EXPORT_NAME}"
1753 NAMESPACE "${PROJECT_NAME}::"
1754 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1759 FILES ${version_config} ${project_config}
1760 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1763 # Workaround for MSVS10 to avoid the Dialog Hell
1764 # FIXME: This could be removed with future version of CMake.
1765 if(MSVC_VERSION EQUAL 1600)
1766 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1767 if(EXISTS "${CURL_SLN_FILENAME}")
1768 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1772 if(NOT TARGET curl_uninstall)
1774 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1775 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1778 add_custom_target(curl_uninstall
1779 COMMAND ${CMAKE_COMMAND} -P
1780 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)