1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2022, 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_RAND_EGD: `RAND_egd` present in OpenSSL
53 # HAVE_BORINGSSL: OpenSSL is BoringSSL
54 # HAVE_PK11_CREATEMANAGEDGENERICOBJECTL: `PK11_CreateManagedGenericObject` present in NSS
55 # HAVE_SSL_CTX_SET_QUIC_METHOD: `SSL_CTX_set_quic_method` present in OpenSSL
56 # HAVE_QUICHE_CONN_SET_QLOG_FD: `quiche_conn_set_qlog_fd` present in QUICHE
57 # HAVE_ZSTD_CREATEDSTREAM: `ZSTD_createDStream` present in Zstd
59 # For each of the above variables, if the variable is DEFINED (either
60 # to ON or OFF), the symbol detection will be skipped. If the
61 # variable is NOT DEFINED, the symbol detection will be performed.
63 cmake_minimum_required(VERSION 3.2...3.16 FATAL_ERROR)
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 option(CURL_WERROR "Turn compiler warnings into errors" OFF)
100 option(PICKY_COMPILER "Enable picky compiler options" ON)
101 option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
102 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
103 option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
105 option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
106 option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
107 set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
108 if(CURL_TARGET_WINDOWS_VERSION)
109 add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
110 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
111 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
114 add_definitions(-DUNICODE -D_UNICODE)
116 add_compile_options(-municode)
120 option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)
122 cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
126 option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
127 option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
129 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
131 foreach(_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wfloat-equal -Wsign-compare -Wundef -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wvla -Wdouble-promotion -Wenum-conversion -Warith-conversion)
132 # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
134 string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
135 check_c_compiler_flag(${_CCOPT} ${_optvarname})
137 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
140 foreach(_CCOPT long-long multichar format-nonliteral sign-conversion system-headers pedantic-ms-format)
141 # GCC only warns about unknown -Wno- options if there are also other diagnostic messages,
142 # so test for the positive form instead
143 string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
144 check_c_compiler_flag("-W${_CCOPT}" ${_optvarname})
146 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-${_CCOPT}")
153 # DEBUGBUILD will be defined only for Debug builds
154 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
155 set(ENABLE_CURLDEBUG ON)
159 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
162 # For debug libs and exes, add "-d" postfix
163 if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
164 set(CMAKE_DEBUG_POSTFIX "-d")
167 # initialize CURL_LIBS
172 find_package(CARES REQUIRED)
173 list(APPEND CURL_LIBS ${CARES_LIBRARY})
176 include(CurlSymbolHiding)
178 option(CURL_ENABLE_EXPORT_TARGET "to enable cmake export target" ON)
179 mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
181 option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF)
182 mark_as_advanced(CURL_DISABLE_ALTSVC)
183 option(CURL_DISABLE_COOKIES "disables cookies support" OFF)
184 mark_as_advanced(CURL_DISABLE_COOKIES)
185 option(CURL_DISABLE_CRYPTO_AUTH "disables cryptographic authentication" OFF)
186 mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
187 option(CURL_DISABLE_DICT "disables DICT" OFF)
188 mark_as_advanced(CURL_DISABLE_DICT)
189 option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF)
190 mark_as_advanced(CURL_DISABLE_DOH)
191 option(CURL_DISABLE_FILE "disables FILE" OFF)
192 mark_as_advanced(CURL_DISABLE_FILE)
193 option(CURL_DISABLE_FTP "disables FTP" OFF)
194 mark_as_advanced(CURL_DISABLE_FTP)
195 option(CURL_DISABLE_GETOPTIONS "disables curl_easy_options API for existing options to curl_easy_setopt" OFF)
196 mark_as_advanced(CURL_DISABLE_GETOPTIONS)
197 option(CURL_DISABLE_GOPHER "disables Gopher" OFF)
198 mark_as_advanced(CURL_DISABLE_GOPHER)
199 option(CURL_DISABLE_HSTS "disables HSTS support" OFF)
200 mark_as_advanced(CURL_DISABLE_HSTS)
201 option(CURL_DISABLE_HTTP "disables HTTP" OFF)
202 mark_as_advanced(CURL_DISABLE_HTTP)
203 option(CURL_DISABLE_HTTP_AUTH "disables all HTTP authentication methods" OFF)
204 mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
205 option(CURL_DISABLE_IMAP "disables IMAP" OFF)
206 mark_as_advanced(CURL_DISABLE_IMAP)
207 option(CURL_DISABLE_LDAP "disables LDAP" OFF)
208 mark_as_advanced(CURL_DISABLE_LDAP)
209 option(CURL_DISABLE_LDAPS "disables LDAPS" OFF)
210 mark_as_advanced(CURL_DISABLE_LDAPS)
211 option(CURL_DISABLE_LIBCURL_OPTION "disables --libcurl option from the curl tool" OFF)
212 mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
213 option(CURL_DISABLE_MIME "disables MIME support" OFF)
214 mark_as_advanced(CURL_DISABLE_MIME)
215 option(CURL_DISABLE_MQTT "disables MQTT" OFF)
216 mark_as_advanced(CURL_DISABLE_MQTT)
217 option(CURL_DISABLE_NETRC "disables netrc parser" OFF)
218 mark_as_advanced(CURL_DISABLE_NETRC)
219 option(CURL_DISABLE_NTLM "disables NTLM support" OFF)
220 mark_as_advanced(CURL_DISABLE_NTLM)
221 option(CURL_DISABLE_PARSEDATE "disables date parsing" OFF)
222 mark_as_advanced(CURL_DISABLE_PARSEDATE)
223 option(CURL_DISABLE_POP3 "disables POP3" OFF)
224 mark_as_advanced(CURL_DISABLE_POP3)
225 option(CURL_DISABLE_PROGRESS_METER "disables built-in progress meter" OFF)
226 mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
227 option(CURL_DISABLE_PROXY "disables proxy support" OFF)
228 mark_as_advanced(CURL_DISABLE_PROXY)
229 option(CURL_DISABLE_RTSP "disables RTSP" OFF)
230 mark_as_advanced(CURL_DISABLE_RTSP)
231 option(CURL_DISABLE_SHUFFLE_DNS "disables shuffle DNS feature" OFF)
232 mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
233 option(CURL_DISABLE_SMB "disables SMB" OFF)
234 mark_as_advanced(CURL_DISABLE_SMB)
235 option(CURL_DISABLE_SMTP "disables SMTP" OFF)
236 mark_as_advanced(CURL_DISABLE_SMTP)
237 option(CURL_DISABLE_SOCKETPAIR "disables use of socketpair for curl_multi_poll" OFF)
238 mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
239 option(CURL_DISABLE_TELNET "disables Telnet" OFF)
240 mark_as_advanced(CURL_DISABLE_TELNET)
241 option(CURL_DISABLE_TFTP "disables TFTP" OFF)
242 mark_as_advanced(CURL_DISABLE_TFTP)
243 option(CURL_DISABLE_VERBOSE_STRINGS "disables verbose strings" OFF)
244 mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
246 # Corresponds to HTTP_ONLY in lib/curl_setup.h
247 option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
248 mark_as_advanced(HTTP_ONLY)
251 set(CURL_DISABLE_DICT ON)
252 set(CURL_DISABLE_FILE ON)
253 set(CURL_DISABLE_FTP ON)
254 set(CURL_DISABLE_GOPHER ON)
255 set(CURL_DISABLE_IMAP ON)
256 set(CURL_DISABLE_LDAP ON)
257 set(CURL_DISABLE_LDAPS ON)
258 set(CURL_DISABLE_MQTT ON)
259 set(CURL_DISABLE_POP3 ON)
260 set(CURL_DISABLE_RTSP ON)
261 set(CURL_DISABLE_SMB ON)
262 set(CURL_DISABLE_SMTP ON)
263 set(CURL_DISABLE_TELNET ON)
264 set(CURL_DISABLE_TFTP ON)
267 option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
268 mark_as_advanced(ENABLE_IPV6)
269 if(ENABLE_IPV6 AND NOT WIN32)
270 include(CheckStructHasMember)
271 check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
272 HAVE_SOCKADDR_IN6_SIN6_ADDR)
273 check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
274 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
275 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
276 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
277 # Force the feature off as this name is used as guard macro...
279 CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
282 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_ARES)
283 set(use_core_foundation ON)
285 find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
286 if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
287 message(FATAL_ERROR "SystemConfiguration framework not found")
290 list(APPEND CURL_LIBS "-framework SystemConfiguration")
295 #nroff is currently only used when USE_MANUAL is set, so we can prevent the warning of no *NROFF if USE_MANUAL is OFF (or not defined), by not even looking for NROFF..
300 cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
301 ON "NROFF_USEFUL;PERL_FOUND"
309 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
310 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
311 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
314 # Disable warnings on Borland to avoid changing 3rd party code.
316 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
319 # If we are on AIX, do the _ALL_SOURCE magic
320 if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
324 # Include all the necessary files for macros
325 include(CMakePushCheckState)
326 include(CheckFunctionExists)
327 include(CheckIncludeFile)
328 include(CheckIncludeFiles)
329 include(CheckLibraryExists)
330 include(CheckSymbolExists)
331 include(CheckTypeSize)
332 include(CheckCSourceCompiles)
334 # On windows preload settings
336 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
337 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
340 if(ENABLE_THREADED_RESOLVER)
341 find_package(Threads REQUIRED)
343 set(USE_THREADS_WIN32 ON)
345 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
346 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
348 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
351 # Check for all needed libraries
352 check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
354 check_function_exists(gethostname HAVE_GETHOSTNAME)
357 check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
358 check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
361 # This check below for use of deprecated symbols is only temporary and is to
362 # be removed again after a year's service. Remove after November 25, 2022.
363 set(CURL_RECONFIG_REQUIRED 0)
364 foreach(_LIB GSSAPI OPENLDAP LIBSSH LIBSSH2 BEARSSL MBEDTLS NSS OPENSSL
365 SCHANNEL SECTRANSP WOLFSSL)
366 if(CMAKE_USE_${_LIB})
367 set(CURL_RECONFIG_REQUIRED 1)
368 message(SEND_ERROR "The option CMAKE_USE_${_LIB} was renamed to CURL_USE_${_LIB}.")
372 set(CURL_RECONFIG_REQUIRED 1)
373 message(SEND_ERROR "The option CMAKE_USE_WINSSL was renamed to CURL_USE_SCHANNEL.")
375 if(CURL_RECONFIG_REQUIRED)
376 message(FATAL_ERROR "Reconfig required")
379 # check SSL libraries
380 # TODO support GnuTLS
381 option(CURL_ENABLE_SSL "Enable SSL support" ON)
384 cmake_dependent_option(CURL_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
387 cmake_dependent_option(CURL_USE_SCHANNEL "enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
388 cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
389 CURL_USE_SCHANNEL OFF)
391 cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
392 cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
393 cmake_dependent_option(CURL_USE_NSS "Enable NSS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
394 cmake_dependent_option(CURL_USE_WOLFSSL "enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
396 set(openssl_default ON)
397 if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_NSS OR CURL_USE_WOLFSSL)
398 set(openssl_default OFF)
400 cmake_dependent_option(CURL_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default} CURL_ENABLE_SSL OFF)
401 option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF)
403 count_true(enabled_ssl_options_count
412 if(enabled_ssl_options_count GREATER "1")
413 set(CURL_WITH_MULTI_SSL ON)
416 if(CURL_USE_SCHANNEL)
418 set(USE_SCHANNEL ON) # Windows native SSL/TLS support
419 set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI
421 if(CURL_WINDOWS_SSPI)
422 set(USE_WINDOWS_SSPI ON)
423 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
426 if(CURL_USE_SECTRANSP)
427 set(use_core_foundation ON)
429 find_library(SECURITY_FRAMEWORK "Security")
430 if(NOT SECURITY_FRAMEWORK)
431 message(FATAL_ERROR "Security framework not found")
435 set(USE_SECTRANSP ON)
436 list(APPEND CURL_LIBS "-framework Security")
439 if(use_core_foundation)
440 find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
441 if(NOT COREFOUNDATION_FRAMEWORK)
442 message(FATAL_ERROR "CoreFoundation framework not found")
445 list(APPEND CURL_LIBS "-framework CoreFoundation")
449 find_package(OpenSSL REQUIRED)
453 # Depend on OpenSSL via imported targets if supported by the running
454 # version of CMake. This allows our dependents to get our dependencies
456 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
457 list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
459 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
460 include_directories(${OPENSSL_INCLUDE_DIR})
463 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
464 if(NOT DEFINED HAVE_RAND_EGD)
465 check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
467 if(NOT DEFINED HAVE_BORINGSSL)
468 check_symbol_exists(OPENSSL_IS_BORINGSSL "openssl/base.h" HAVE_BORINGSSL)
471 add_definitions(-DOPENSSL_SUPPRESS_DEPRECATED)
475 find_package(MbedTLS REQUIRED)
478 list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
479 include_directories(${MBEDTLS_INCLUDE_DIRS})
483 find_package(BearSSL REQUIRED)
486 list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
487 include_directories(${BEARSSL_INCLUDE_DIRS})
491 find_package(WolfSSL REQUIRED)
494 list(APPEND CURL_LIBS ${WolfSSL_LIBRARIES})
495 include_directories(${WolfSSL_INCLUDE_DIRS})
499 find_package(NSS REQUIRED)
500 include_directories(${NSS_INCLUDE_DIRS})
501 list(APPEND CURL_LIBS ${NSS_LIBRARIES})
504 if(NOT DEFINED HAVE_PK11_CREATEMANAGEDGENERICOBJECT)
505 cmake_push_check_state()
506 set(CMAKE_REQUIRED_INCLUDES ${NSS_INCLUDE_DIRS})
507 set(CMAKE_REQUIRED_LIBRARIES ${NSS_LIBRARIES})
508 check_symbol_exists(PK11_CreateManagedGenericObject "pk11pub.h" HAVE_PK11_CREATEMANAGEDGENERICOBJECT)
509 cmake_pop_check_state()
513 option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
515 find_package(NGHTTP2 REQUIRED)
516 include_directories(${NGHTTP2_INCLUDE_DIRS})
517 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
520 function(CheckQuicSupportInOpenSSL)
521 # Be sure that the OpenSSL library actually supports QUIC.
522 if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD)
523 cmake_push_check_state()
524 set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
525 set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
526 check_symbol_exists(SSL_CTX_set_quic_method "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD)
527 cmake_pop_check_state()
529 if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD)
530 message(FATAL_ERROR "QUIC support is missing in OpenSSL/BoringSSL. Try setting -DOPENSSL_ROOT_DIR")
534 option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF)
538 find_package(NGTCP2 REQUIRED BoringSSL)
540 find_package(NGTCP2 REQUIRED OpenSSL)
542 CheckQuicSupportInOpenSSL()
544 # TODO add GnuTLS support as vtls library.
545 find_package(NGTCP2 REQUIRED GnuTLS)
547 message(FATAL_ERROR "ngtcp2 requires OpenSSL or GnuTLS")
550 include_directories(${NGTCP2_INCLUDE_DIRS})
551 list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES})
553 find_package(NGHTTP3 REQUIRED)
555 include_directories(${NGHTTP3_INCLUDE_DIRS})
556 list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
559 option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF)
562 message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
564 find_package(QUICHE REQUIRED)
565 CheckQuicSupportInOpenSSL()
567 include_directories(${QUICHE_INCLUDE_DIRS})
568 list(APPEND CURL_LIBS ${QUICHE_LIBRARIES})
569 if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD)
570 cmake_push_check_state()
571 set(CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}")
572 set(CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}")
573 check_symbol_exists(quiche_conn_set_qlog_fd "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD)
574 cmake_pop_check_state()
578 option(USE_MSH3 "Use msquic library for HTTP/3 support" OFF)
580 if(USE_NGTCP2 OR USE_QUICHE)
581 message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
584 include_directories(${MSH3_INCLUDE_DIRS})
585 list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
588 if(NOT CURL_DISABLE_LDAP)
590 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
592 check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
594 set(USE_WIN32_LDAP OFF)
599 option(CURL_USE_OPENLDAP "Use OpenLDAP code." OFF)
600 mark_as_advanced(CURL_USE_OPENLDAP)
601 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
602 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
604 if(CURL_USE_OPENLDAP AND USE_WIN32_LDAP)
605 message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CURL_USE_OPENLDAP at the same time")
608 # Now that we know, we're not using windows LDAP...
610 check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
613 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
614 check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
615 check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
617 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
618 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
619 if(CMAKE_LDAP_INCLUDE_DIR)
620 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
622 check_include_file_concat("ldap.h" HAVE_LDAP_H)
623 check_include_file_concat("lber.h" HAVE_LBER_H)
626 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
627 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
628 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
629 elseif(NOT HAVE_LIBLDAP)
630 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
631 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
632 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
634 if(CURL_USE_OPENLDAP)
637 if(CMAKE_LDAP_INCLUDE_DIR)
638 include_directories(${CMAKE_LDAP_INCLUDE_DIR})
643 list(APPEND _HEADER_LIST "windows.h")
646 list(APPEND _HEADER_LIST "sys/types.h")
648 list(APPEND _HEADER_LIST "ldap.h")
651 foreach(_HEADER ${_HEADER_LIST})
652 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
658 int main(int argc, char ** argv)
660 BerValue *bvp = NULL;
661 BerElement *bep = ber_init(bvp);
666 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
667 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
669 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
671 check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
672 unset(CMAKE_REQUIRED_LIBRARIES)
677 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
684 if(CURL_DISABLE_LDAP)
685 if(NOT CURL_DISABLE_LDAPS)
686 message(STATUS "LDAP needs to be enabled to support LDAPS")
687 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
691 if(NOT CURL_DISABLE_LDAPS)
692 check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
696 option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
698 check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
700 set(HAVE_LIBIDN2 OFF)
704 option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF)
706 list(APPEND CURL_LIBS "normaliz")
707 set(WANT_IDN_PROTOTYPES ON)
713 optional_dependency(ZLIB)
718 # Depend on ZLIB via imported targets if supported by the running
719 # version of CMake. This allows our dependents to get our dependencies
721 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
722 list(APPEND CURL_LIBS ZLIB::ZLIB)
724 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
725 include_directories(${ZLIB_INCLUDE_DIRS})
727 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
730 option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
733 find_package(Brotli QUIET)
736 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
737 include_directories(${BROTLI_INCLUDE_DIRS})
738 list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
742 option(CURL_ZSTD "Set to ON to enable building curl with zstd support." OFF)
745 find_package(Zstd REQUIRED)
746 if (NOT DEFINED HAVE_ZSTD_CREATEDSTREAM)
747 cmake_push_check_state()
748 set(CMAKE_REQUIRED_INCLUDES ${Zstd_INCLUDE_DIRS})
749 set(CMAKE_REQUIRED_LIBRARIES ${Zstd_LIBRARIES})
750 check_symbol_exists(ZSTD_createDStream "zstd.h" HAVE_ZSTD_CREATEDSTREAM)
751 cmake_pop_check_state()
753 if(Zstd_FOUND AND HAVE_ZSTD_CREATEDSTREAM)
755 list(APPEND CURL_LIBS ${Zstd_LIBRARIES})
756 include_directories(${Zstd_INCLUDE_DIRS})
761 option(CURL_USE_LIBPSL "Use libPSL" ON)
762 mark_as_advanced(CURL_USE_LIBPSL)
768 list(APPEND CURL_LIBS ${LIBPSL_LIBRARY})
769 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIR}")
770 include_directories("${LIBPSL_INCLUDE_DIR}")
776 option(CURL_USE_LIBSSH2 "Use libSSH2" ON)
777 mark_as_advanced(CURL_USE_LIBSSH2)
781 find_package(LibSSH2)
783 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
784 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
785 include_directories("${LIBSSH2_INCLUDE_DIR}")
791 option(CURL_USE_LIBSSH "Use libSSH" OFF)
792 mark_as_advanced(CURL_USE_LIBSSH)
793 if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
794 find_package(libssh CONFIG)
796 message(STATUS "Found libssh ${libssh_VERSION}")
797 # Use imported target for include and library paths.
798 list(APPEND CURL_LIBS ssh)
803 option(CURL_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
804 mark_as_advanced(CURL_USE_GSSAPI)
809 set(HAVE_GSSAPI ${GSS_FOUND})
812 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
814 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
815 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
816 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
817 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
819 if(GSS_FLAVOUR STREQUAL "Heimdal")
820 set(HAVE_GSSHEIMDAL ON)
823 set(_INCLUDE_LIST "")
824 if(HAVE_GSSAPI_GSSAPI_H)
825 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
827 if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
828 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
830 if(HAVE_GSSAPI_GSSAPI_KRB5_H)
831 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
834 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
835 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
837 foreach(_dir ${GSS_LINK_DIRECTORIES})
838 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
841 if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE)
842 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
843 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
844 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
845 unset(CMAKE_REQUIRED_LIBRARIES)
847 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
848 set(HAVE_OLD_GSSMIT ON)
852 include_directories(${GSS_INCLUDE_DIR})
853 link_directories(${GSS_LINK_DIRECTORIES})
854 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
855 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
856 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
857 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
858 list(APPEND CURL_LIBS ${GSS_LIBRARIES})
861 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
865 option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
866 if(ENABLE_UNIX_SOCKETS)
867 include(CheckStructHasMember)
869 set(USE_UNIX_SOCKETS ON)
871 check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
874 unset(USE_UNIX_SOCKETS CACHE)
881 set(CURL_CA_BUNDLE "auto" CACHE STRING
882 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
883 set(CURL_CA_FALLBACK OFF CACHE BOOL
884 "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
885 set(CURL_CA_PATH "auto" CACHE STRING
886 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
888 if("${CURL_CA_BUNDLE}" STREQUAL "")
889 message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
890 elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
891 unset(CURL_CA_BUNDLE CACHE)
892 elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
893 unset(CURL_CA_BUNDLE CACHE)
894 set(CURL_CA_BUNDLE_AUTODETECT TRUE)
896 set(CURL_CA_BUNDLE_SET TRUE)
899 if("${CURL_CA_PATH}" STREQUAL "")
900 message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
901 elseif("${CURL_CA_PATH}" STREQUAL "none")
902 unset(CURL_CA_PATH CACHE)
903 elseif("${CURL_CA_PATH}" STREQUAL "auto")
904 unset(CURL_CA_PATH CACHE)
906 set(CURL_CA_PATH_AUTODETECT TRUE)
909 set(CURL_CA_PATH_SET TRUE)
912 if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
913 # Skip autodetection of unset CA path because CA bundle is set explicitly
914 elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
915 # Skip autodetection of unset CA bundle because CA path is set explicitly
916 elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
917 # first try autodetecting a CA bundle, then a CA path
919 if(CURL_CA_BUNDLE_AUTODETECT)
920 set(SEARCH_CA_BUNDLE_PATHS
921 /etc/ssl/certs/ca-certificates.crt
922 /etc/pki/tls/certs/ca-bundle.crt
923 /usr/share/ssl/certs/ca-bundle.crt
924 /usr/local/share/certs/ca-root-nss.crt
927 foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
928 if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
929 message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
930 set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}" CACHE STRING
931 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
932 set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
938 if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
939 if(EXISTS "/etc/ssl/certs")
940 set(CURL_CA_PATH "/etc/ssl/certs" CACHE STRING
941 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
942 set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
947 if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
949 "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
950 "Set CURL_CA_PATH=none or enable one of those TLS backends.")
953 # Check for header files
955 check_include_file_concat("windows.h" HAVE_WINDOWS_H)
956 check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
957 check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
958 check_include_file_concat("wincrypt.h" HAVE_WINCRYPT_H)
961 check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
962 check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
963 check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
964 check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
965 check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
966 check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
967 check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
968 check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
969 check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
970 check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
971 check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
972 check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
973 check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
974 check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
975 check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
976 check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
977 check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
978 check_include_file_concat("assert.h" HAVE_ASSERT_H)
979 check_include_file_concat("errno.h" HAVE_ERRNO_H)
980 check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
981 check_include_file_concat("idn2.h" HAVE_IDN2_H)
982 check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
983 check_include_file_concat("io.h" HAVE_IO_H)
984 check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
985 check_include_file_concat("locale.h" HAVE_LOCALE_H)
986 check_include_file_concat("net/if.h" HAVE_NET_IF_H)
987 check_include_file_concat("netdb.h" HAVE_NETDB_H)
988 check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
989 check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
990 check_include_file("linux/tcp.h" HAVE_LINUX_TCP_H)
992 check_include_file_concat("poll.h" HAVE_POLL_H)
993 check_include_file_concat("pwd.h" HAVE_PWD_H)
994 check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
995 check_include_file_concat("signal.h" HAVE_SIGNAL_H)
996 check_include_file_concat("ssl.h" HAVE_SSL_H)
997 check_include_file_concat("stdatomic.h" HAVE_STDATOMIC_H)
998 check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
999 check_include_file_concat("stdint.h" HAVE_STDINT_H)
1000 check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
1001 check_include_file_concat("string.h" HAVE_STRING_H)
1002 check_include_file_concat("strings.h" HAVE_STRINGS_H)
1003 check_include_file_concat("stropts.h" HAVE_STROPTS_H)
1004 check_include_file_concat("termio.h" HAVE_TERMIO_H)
1005 check_include_file_concat("termios.h" HAVE_TERMIOS_H)
1006 check_include_file_concat("time.h" HAVE_TIME_H)
1007 check_include_file_concat("unistd.h" HAVE_UNISTD_H)
1008 check_include_file_concat("utime.h" HAVE_UTIME_H)
1010 check_include_file_concat("process.h" HAVE_PROCESS_H)
1011 check_include_file_concat("stddef.h" HAVE_STDDEF_H)
1012 check_include_file_concat("stdint.h" HAVE_STDINT_H)
1013 check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
1015 check_type_size(size_t SIZEOF_SIZE_T)
1016 check_type_size(ssize_t SIZEOF_SSIZE_T)
1017 check_type_size("long long" SIZEOF_LONG_LONG)
1018 check_type_size("long" SIZEOF_LONG)
1019 check_type_size("int" SIZEOF_INT)
1020 check_type_size("__int64" SIZEOF___INT64)
1021 check_type_size("time_t" SIZEOF_TIME_T)
1022 if(NOT HAVE_SIZEOF_SSIZE_T)
1023 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
1026 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
1027 set(ssize_t __int64)
1030 # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
1032 if(HAVE_SIZEOF_LONG_LONG)
1033 set(HAVE_LONGLONG 1)
1036 if(NOT CMAKE_CROSSCOMPILING)
1037 find_file(RANDOM_FILE urandom /dev)
1038 mark_as_advanced(RANDOM_FILE)
1041 # Check for some functions that are used
1043 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
1044 elseif(HAVE_LIBSOCKET)
1045 set(CMAKE_REQUIRED_LIBRARIES socket)
1048 check_symbol_exists(fchmod "${CURL_INCLUDES}" HAVE_FCHMOD)
1049 check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
1050 check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
1051 check_symbol_exists(socketpair "${CURL_INCLUDES}" HAVE_SOCKETPAIR)
1052 check_symbol_exists(recv "${CURL_INCLUDES}" HAVE_RECV)
1053 check_symbol_exists(send "${CURL_INCLUDES}" HAVE_SEND)
1054 check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
1055 check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
1056 check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
1057 check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
1058 check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
1059 check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
1060 check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
1061 check_symbol_exists(getppid "${CURL_INCLUDES}" HAVE_GETPPID)
1062 check_symbol_exists(utimes "${CURL_INCLUDES}" HAVE_UTIMES)
1064 check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
1065 check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
1066 check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
1067 check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
1068 check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
1069 check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
1070 check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
1071 check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
1072 check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
1074 check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
1076 check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL)
1077 check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
1078 check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
1079 check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
1080 check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
1081 check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
1082 if(NOT HAVE_GETADDRINFO)
1083 set(HAVE_GETADDRINFO_THREADSAFE OFF)
1085 check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
1086 check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
1087 check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
1088 check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
1089 check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
1090 check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
1091 check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
1092 check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
1093 check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
1094 check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
1096 if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900))
1097 # earlier MSVC compilers had faulty snprintf implementations
1098 check_symbol_exists(snprintf "${CURL_INCLUDES}" HAVE_SNPRINTF)
1100 check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
1101 check_symbol_exists(inet_ntop "${CURL_INCLUDES}" HAVE_INET_NTOP)
1102 if(MSVC AND (MSVC_VERSION LESS_EQUAL 1600))
1103 set(HAVE_INET_NTOP OFF)
1105 check_symbol_exists(inet_pton "${CURL_INCLUDES}" HAVE_INET_PTON)
1107 check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
1109 foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
1110 curl_internal_test(${CURL_TEST})
1114 set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
1115 check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T)
1116 set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T})
1117 set(CMAKE_EXTRA_INCLUDE_FILES "")
1119 set(CMAKE_EXTRA_INCLUDE_FILES "ws2def.h")
1120 check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY)
1121 set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY})
1122 set(CMAKE_EXTRA_INCLUDE_FILES "")
1124 # sigaction and sigsetjmp are special. Use special mechanism for
1125 # detecting those, but only if previous attempt failed.
1127 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
1130 if(NOT HAVE_SIGSETJMP)
1132 check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
1133 if(HAVE_MACRO_SIGSETJMP)
1134 set(HAVE_SIGSETJMP 1)
1139 # If there is no stricmp(), do not allow LDAP to parse URLs
1140 if(NOT HAVE_STRICMP)
1141 set(HAVE_LDAP_URL_PARSE 1)
1144 # Do curl specific tests
1146 HAVE_FCNTL_O_NONBLOCK
1148 HAVE_IOCTLSOCKET_CAMEL
1149 HAVE_IOCTLSOCKET_CAMEL_FIONBIO
1150 HAVE_IOCTLSOCKET_FIONBIO
1152 HAVE_IOCTL_SIOCGIFADDR
1153 HAVE_SETSOCKOPT_SO_NONBLOCK
1156 HAVE_GETHOSTBYNAME_R_3
1157 HAVE_GETHOSTBYNAME_R_5
1158 HAVE_GETHOSTBYNAME_R_6
1159 HAVE_GETHOSTBYNAME_R_3_REENTRANT
1160 HAVE_GETHOSTBYNAME_R_5_REENTRANT
1161 HAVE_GETHOSTBYNAME_R_6_REENTRANT
1165 HAVE_FILE_OFFSET_BITS
1166 HAVE_VARIADIC_MACROS_C99
1167 HAVE_VARIADIC_MACROS_GCC
1170 curl_internal_test(${CURL_TEST})
1173 if(HAVE_FILE_OFFSET_BITS)
1174 set(_FILE_OFFSET_BITS 64)
1175 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
1177 check_type_size("off_t" SIZEOF_OFF_T)
1179 # include this header to get the type
1180 set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
1181 set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
1182 check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
1183 set(CMAKE_EXTRA_INCLUDE_FILES "")
1186 # detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
1187 curl_internal_test(HAVE_WIN32_WINNT)
1188 if(HAVE_WIN32_WINNT)
1189 string(REGEX MATCH ".*_WIN32_WINNT=0x[0-9a-fA-F]+" OUTPUT "${OUTPUT}")
1190 string(REGEX REPLACE ".*_WIN32_WINNT=" "" HAVE_WIN32_WINNT "${OUTPUT}")
1191 message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
1193 # avoid storing HAVE_WIN32_WINNT in CMake cache
1194 unset(HAVE_WIN32_WINNT CACHE)
1197 set(CMAKE_REQUIRED_FLAGS)
1199 option(ENABLE_WEBSOCKETS "Set to ON to enable EXPERIMENTAL websockets" OFF)
1201 if(ENABLE_WEBSOCKETS)
1202 if(${SIZEOF_CURL_OFF_T} GREATER "4")
1203 set(USE_WEBSOCKETS ON)
1205 message(WARNING "curl_off_t is too small to enable WebSockets")
1210 HAVE_GLIBC_STRERROR_R
1211 HAVE_POSIX_STRERROR_R
1213 curl_internal_test(${CURL_TEST})
1216 # Check for reentrant
1218 HAVE_GETHOSTBYNAME_R_3
1219 HAVE_GETHOSTBYNAME_R_5
1220 HAVE_GETHOSTBYNAME_R_6)
1221 if(NOT ${CURL_TEST})
1222 if(${CURL_TEST}_REENTRANT)
1223 set(NEED_REENTRANT 1)
1230 HAVE_GETHOSTBYNAME_R_3
1231 HAVE_GETHOSTBYNAME_R_5
1232 HAVE_GETHOSTBYNAME_R_6)
1234 if(${CURL_TEST}_REENTRANT)
1240 # Check clock_gettime(CLOCK_MONOTONIC, x) support
1241 curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
1243 # Check compiler support of __builtin_available()
1244 curl_internal_test(HAVE_BUILTIN_AVAILABLE)
1246 # Some other minor tests
1248 if(NOT HAVE_IN_ADDR_T)
1249 set(in_addr_t "unsigned long")
1252 # Check for nonblocking
1253 set(HAVE_DISABLED_NONBLOCKING 1)
1256 HAVE_IOCTLSOCKET_CASE OR
1258 set(HAVE_DISABLED_NONBLOCKING)
1261 if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1262 include(CheckCCompilerFlag)
1263 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1264 if(HAVE_C_FLAG_Wno_long_double)
1265 # The Mac version of GCC warns about use of long double. Disable it.
1266 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1267 if(MPRINTF_COMPILE_FLAGS)
1268 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1270 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1272 set_source_files_properties(mprintf.c PROPERTIES
1273 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1277 # TODO test which of these headers are required
1279 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
1281 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
1282 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
1283 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
1285 set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
1286 set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
1288 include(CMake/OtherTests.cmake)
1290 add_definitions(-DHAVE_CONFIG_H)
1292 # For Windows, all compilers used by CMake should support large files
1294 set(USE_WIN32_LARGE_FILES ON)
1296 # Use the manifest embedded in the Windows Resource
1297 set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1299 # Check if crypto functions in wincrypt.h are actually available
1301 check_symbol_exists(CryptAcquireContext "${CURL_INCLUDES}" USE_WINCRYPT)
1304 set(USE_WIN32_CRYPTO ON)
1307 # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL
1308 if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
1309 list(APPEND CURL_LIBS "advapi32" "crypt32")
1312 # Matching logic used for Curl_win32_random()
1314 check_c_source_compiles("
1316 #if defined(__MINGW64_VERSION_MAJOR)
1322 HAVE_MINGW_ORIGINAL)
1325 if(NOT HAVE_MINGW_ORIGINAL)
1326 list(APPEND CURL_LIBS "bcrypt")
1328 set(HAVE_FTRUNCATE OFF)
1333 # Disable default manifest added by CMake
1334 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1336 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1337 if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1338 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1340 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1343 # Use multithreaded compilation on VS 2008+
1344 if(MSVC_VERSION GREATER_EQUAL 1500)
1345 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
1351 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1353 # this assumes clang or gcc style options
1354 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1359 if(CMAKE_VERSION VERSION_LESS 3.9)
1360 message(FATAL_ERROR "Requested LTO but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
1363 cmake_policy(SET CMP0069 NEW)
1365 include(CheckIPOSupported)
1366 check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT CURL_LTO_ERROR LANGUAGES C)
1368 message(STATUS "LTO supported and enabled")
1370 message(FATAL_ERROR "LTO was requested - but compiler doesn't support it\n${CURL_LTO_ERROR}")
1375 # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1376 function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
1377 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1378 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1379 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1381 string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1382 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1383 string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1385 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
1386 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.
1387 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1388 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}")
1391 include(GNUInstallDirs)
1393 set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
1394 set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
1395 set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
1396 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
1397 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
1400 add_subdirectory(docs)
1403 add_subdirectory(lib)
1406 add_subdirectory(src)
1409 cmake_dependent_option(BUILD_TESTING "Build tests"
1410 ON "PERL_FOUND;NOT CURL_DISABLE_TESTS"
1413 add_subdirectory(tests)
1416 # Helper to populate a list (_items) with a label when conditions (the remaining
1417 # args) are satisfied
1418 macro(_add_if label)
1419 # needs to be a macro to allow this indirection
1421 set(_items ${_items} "${label}")
1425 # NTLM support requires crypto function adaptions from various SSL libs
1426 # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
1427 if(NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND
1428 (USE_OPENSSL OR USE_MBEDTLS OR USE_DARWINSSL OR USE_WIN32_CRYPTO))
1429 set(use_curl_ntlm_core ON)
1432 # Clear list and try to detect available features
1434 _add_if("SSL" SSL_ENABLED)
1435 _add_if("IPv6" ENABLE_IPV6)
1436 _add_if("unixsockets" USE_UNIX_SOCKETS)
1437 _add_if("libz" HAVE_LIBZ)
1438 _add_if("brotli" HAVE_BROTLI)
1439 _add_if("zstd" HAVE_ZSTD)
1440 _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1441 _add_if("IDN" HAVE_LIBIDN2 OR USE_WIN32_IDN)
1442 _add_if("Largefile" (SIZEOF_CURL_OFF_T GREATER 4) AND
1443 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
1444 # TODO SSP1 (Schannel) check is missing
1445 _add_if("SSPI" USE_WINDOWS_SSPI)
1446 _add_if("GSS-API" HAVE_GSSAPI)
1447 _add_if("alt-svc" NOT CURL_DISABLE_ALTSVC)
1448 _add_if("HSTS" NOT CURL_DISABLE_HSTS)
1449 # TODO SSP1 missing for SPNEGO
1450 _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
1451 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1452 _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
1453 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1454 # NTLM support requires crypto function adaptions from various SSL libs
1455 # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
1456 _add_if("NTLM" NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND
1457 (use_curl_ntlm_core OR USE_WINDOWS_SSPI))
1458 # TODO missing option (autoconf: --enable-ntlm-wb)
1459 _add_if("NTLM_WB" NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND
1460 (use_curl_ntlm_core OR USE_WINDOWS_SSPI) AND
1461 NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
1462 # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
1463 _add_if("TLS-SRP" USE_TLS_SRP)
1464 # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
1465 _add_if("HTTP2" USE_NGHTTP2)
1466 _add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE)
1467 _add_if("MultiSSL" CURL_WITH_MULTI_SSL)
1468 _add_if("HTTPS-proxy" SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS OR USE_NSS))
1469 _add_if("unicode" ENABLE_UNICODE)
1470 _add_if("threadsafe" HAVE_ATOMIC OR (WIN32 AND
1471 HAVE_WIN32_WINNT GREATER_EQUAL 0x600))
1472 _add_if("PSL" USE_LIBPSL)
1473 string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1474 message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1476 # Clear list and try to detect available protocols
1478 _add_if("HTTP" NOT CURL_DISABLE_HTTP)
1479 _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1480 _add_if("FTP" NOT CURL_DISABLE_FTP)
1481 _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1482 _add_if("FILE" NOT CURL_DISABLE_FILE)
1483 _add_if("TELNET" NOT CURL_DISABLE_TELNET)
1484 _add_if("LDAP" NOT CURL_DISABLE_LDAP)
1485 # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1486 # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
1487 _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
1488 ((USE_OPENLDAP AND SSL_ENABLED) OR
1489 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1490 _add_if("DICT" NOT CURL_DISABLE_DICT)
1491 _add_if("TFTP" NOT CURL_DISABLE_TFTP)
1492 _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
1493 _add_if("GOPHERS" NOT CURL_DISABLE_GOPHER AND SSL_ENABLED)
1494 _add_if("POP3" NOT CURL_DISABLE_POP3)
1495 _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1496 _add_if("IMAP" NOT CURL_DISABLE_IMAP)
1497 _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1498 _add_if("SMB" NOT CURL_DISABLE_SMB AND
1499 use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
1500 _add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND
1501 use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
1502 _add_if("SMTP" NOT CURL_DISABLE_SMTP)
1503 _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1504 _add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH)
1505 _add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH)
1506 _add_if("RTSP" NOT CURL_DISABLE_RTSP)
1507 _add_if("RTMP" USE_LIBRTMP)
1508 _add_if("MQTT" NOT CURL_DISABLE_MQTT)
1509 _add_if("WS" USE_WEBSOCKETS)
1510 _add_if("WSS" USE_WEBSOCKETS)
1514 string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1515 message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1517 # Clear list and collect SSL backends
1519 _add_if("Schannel" SSL_ENABLED AND USE_SCHANNEL)
1520 _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
1521 _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
1522 _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
1523 _add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL)
1524 _add_if("NSS" SSL_ENABLED AND USE_NSS)
1525 _add_if("wolfSSL" SSL_ENABLED AND USE_WOLFSSL)
1529 string(REPLACE ";" " " SSL_BACKENDS "${_items}")
1530 message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
1532 # curl-config needs the following options to be set.
1533 set(CC "${CMAKE_C_COMPILER}")
1534 # TODO probably put a -D... options here?
1535 set(CONFIGURE_OPTIONS "")
1536 # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
1537 set(CPPFLAG_CURL_STATICLIB "")
1538 set(CURLVERSION "${CURL_VERSION}")
1539 set(exec_prefix "\${prefix}")
1540 set(includedir "\${prefix}/include")
1541 set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
1542 set(LIBCURL_LIBS "")
1543 set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
1544 foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
1545 if(TARGET "${_lib}")
1546 set(_libname "${_lib}")
1547 get_target_property(_imported "${_libname}" IMPORTED)
1549 # Reading the LOCATION property on non-imported target will error out.
1550 # Assume the user won't need this information in the .pc file.
1553 get_target_property(_lib "${_libname}" LOCATION)
1555 message(WARNING "Bad lib in library list: ${_libname}")
1559 if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
1560 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
1562 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
1565 if(BUILD_SHARED_LIBS)
1566 set(ENABLE_SHARED "yes")
1567 set(ENABLE_STATIC "no")
1568 set(LIBCURL_NO_SHARED "")
1570 set(ENABLE_SHARED "no")
1571 set(ENABLE_STATIC "yes")
1572 set(LIBCURL_NO_SHARED "${LIBCURL_LIBS}")
1574 # "a" (Linux) or "lib" (Windows)
1575 string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1576 set(prefix "${CMAKE_INSTALL_PREFIX}")
1577 # Set this to "yes" to append all libraries on which -lcurl is dependent
1578 set(REQUIRE_LIB_DEPS "no")
1581 set(VERSIONNUM "${CURL_VERSION_NUM}")
1583 # Finally generate a "curl-config" matching this config
1587 configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1588 "${CURL_BINARY_DIR}/curl-config" @ONLY)
1589 install(FILES "${CURL_BINARY_DIR}/curl-config"
1590 DESTINATION ${CMAKE_INSTALL_BINDIR}
1592 OWNER_READ OWNER_WRITE OWNER_EXECUTE
1593 GROUP_READ GROUP_EXECUTE
1594 WORLD_READ WORLD_EXECUTE)
1596 # Finally generate a pkg-config file matching this config
1597 configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1598 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
1599 install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
1600 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1603 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1604 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1605 FILES_MATCHING PATTERN "*.h")
1607 include(CMakePackageConfigHelpers)
1608 write_basic_package_version_file(
1610 VERSION ${CURL_VERSION}
1611 COMPATIBILITY SameMajorVersion
1615 # * TARGETS_EXPORT_NAME
1617 configure_package_config_file(CMake/curl-config.cmake.in
1619 INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1622 if(CURL_ENABLE_EXPORT_TARGET)
1624 EXPORT "${TARGETS_EXPORT_NAME}"
1625 NAMESPACE "${PROJECT_NAME}::"
1626 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1631 FILES ${version_config} ${project_config}
1632 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1635 # Workaround for MSVS10 to avoid the Dialog Hell
1636 # FIXME: This could be removed with future version of CMake.
1637 if(MSVC_VERSION EQUAL 1600)
1638 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1639 if(EXISTS "${CURL_SLN_FILENAME}")
1640 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1644 if(NOT TARGET curl_uninstall)
1646 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1647 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1650 add_custom_target(curl_uninstall
1651 COMMAND ${CMAKE_COMMAND} -P
1652 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)