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