xref: /curl/CMakeLists.txt (revision add22fee)
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24# by Tetetest and Sukender (Benoit Neil)
25
26# Note: By default this CMake build script detects the version of some
27# dependencies using `check_symbol_exists`.  Those checks do not work
28# in the case that both CURL and its dependency are included as
29# sub-projects in a larger build using `FetchContent`.  To support
30# that case, additional variables may be defined by the parent
31# project, ideally in the "extra" find package redirect file:
32# https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package
33#
34# The following variables are available:
35#   HAVE_SSL_SET0_WBIO: `SSL_set0_wbio` present in OpenSSL/wolfSSL
36#   HAVE_OPENSSL_SRP: `SSL_CTX_set_srp_username` present in OpenSSL/wolfSSL
37#   HAVE_GNUTLS_SRP: `gnutls_srp_verifier` present in GnuTLS
38#   HAVE_SSL_CTX_SET_QUIC_METHOD: `SSL_CTX_set_quic_method` present in OpenSSL/wolfSSL
39#   HAVE_QUICHE_CONN_SET_QLOG_FD: `quiche_conn_set_qlog_fd` present in QUICHE
40#   HAVE_ECH: ECH API checks for OpenSSL, BoringSSL or wolfSSL
41#
42# For each of the above variables, if the variable is DEFINED (either
43# to ON or OFF), the symbol detection will be skipped.  If the
44# variable is NOT DEFINED, the symbol detection will be performed.
45
46cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
47message(STATUS "Using CMake version ${CMAKE_VERSION}")
48
49set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
50include(Utilities)
51include(Macros)
52include(CMakeDependentOption)
53include(CheckCCompilerFlag)
54
55project(CURL C)
56
57file(STRINGS ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS REGEX "#define LIBCURL_VERSION( |_NUM )")
58string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
59  CURL_VERSION ${CURL_VERSION_H_CONTENTS})
60string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
61string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
62  CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
63string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
64
65
66# Setup package meta-data
67# SET(PACKAGE "curl")
68message(STATUS "curl version=[${CURL_VERSION}]")
69# SET(PACKAGE_TARNAME "curl")
70# SET(PACKAGE_NAME "curl")
71# SET(PACKAGE_VERSION "-")
72# SET(PACKAGE_STRING "curl-")
73# SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.se/mail/")
74set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
75if(CMAKE_C_COMPILER_TARGET)
76  set(OS "\"${CMAKE_C_COMPILER_TARGET}\"")
77else()
78  set(OS "\"${CMAKE_SYSTEM_NAME}\"")
79endif()
80
81include_directories(${CURL_SOURCE_DIR}/include)
82
83set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
84
85option(CURL_WERROR "Turn compiler warnings into errors" OFF)
86option(PICKY_COMPILER "Enable picky compiler options" ON)
87option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
88option(BUILD_SHARED_LIBS "Build shared libraries" ON)
89option(BUILD_STATIC_LIBS "Build static libraries" OFF)
90option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
91option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
92option(CURL_DISABLE_INSTALL "Set to ON to disable installation targets" OFF)
93
94if(WIN32)
95  option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
96  option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
97  set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
98  if(CURL_TARGET_WINDOWS_VERSION)
99    add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
100    list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
101    set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
102  endif()
103  if(ENABLE_UNICODE)
104    add_definitions(-DUNICODE -D_UNICODE)
105    if(MINGW)
106      add_compile_options(-municode)
107    endif()
108  endif()
109endif()
110option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)
111
112cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
113        ON "NOT ENABLE_ARES"
114        OFF)
115
116option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
117option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
118
119include(PickyWarnings)
120
121if(ENABLE_DEBUG)
122  # DEBUGBUILD will be defined only for Debug builds
123  set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
124  set(ENABLE_CURLDEBUG ON)
125endif()
126
127if(ENABLE_CURLDEBUG)
128  set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
129endif()
130
131# For debug libs and exes, add "-d" postfix
132if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
133  set(CMAKE_DEBUG_POSTFIX "-d")
134endif()
135
136set(LIB_STATIC "libcurl_static")
137set(LIB_SHARED "libcurl_shared")
138
139if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
140  set(BUILD_STATIC_LIBS ON)
141endif()
142if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS)
143  set(BUILD_STATIC_CURL ON)
144elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS)
145  set(BUILD_STATIC_CURL OFF)
146endif()
147
148# lib flavour selected for curl tool
149if(BUILD_STATIC_CURL)
150  set(LIB_SELECTED_FOR_EXE ${LIB_STATIC})
151else()
152  set(LIB_SELECTED_FOR_EXE ${LIB_SHARED})
153endif()
154
155# lib flavour selected for example and test programs.
156if(BUILD_SHARED_LIBS)
157  set(LIB_SELECTED ${LIB_SHARED})
158else()
159  set(LIB_SELECTED ${LIB_STATIC})
160endif()
161
162# initialize CURL_LIBS
163set(CURL_LIBS "")
164
165if(ENABLE_ARES)
166  set(USE_ARES 1)
167  find_package(CARES REQUIRED)
168  list(APPEND CURL_LIBS ${CARES_LIBRARY})
169endif()
170
171include(CurlSymbolHiding)
172
173option(CURL_ENABLE_EXPORT_TARGET "to enable cmake export target" ON)
174mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
175
176option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF)
177mark_as_advanced(CURL_DISABLE_ALTSVC)
178option(CURL_DISABLE_SRP "disables TLS-SRP support" OFF)
179mark_as_advanced(CURL_DISABLE_SRP)
180option(CURL_DISABLE_COOKIES "disables cookies support" OFF)
181mark_as_advanced(CURL_DISABLE_COOKIES)
182option(CURL_DISABLE_BASIC_AUTH "disables Basic authentication" OFF)
183mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
184option(CURL_DISABLE_BEARER_AUTH "disables Bearer authentication" OFF)
185mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
186option(CURL_DISABLE_DIGEST_AUTH "disables Digest authentication" OFF)
187mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
188option(CURL_DISABLE_KERBEROS_AUTH "disables Kerberos authentication" OFF)
189mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
190option(CURL_DISABLE_NEGOTIATE_AUTH "disables negotiate authentication" OFF)
191mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
192option(CURL_DISABLE_AWS "disables AWS-SIG4" OFF)
193mark_as_advanced(CURL_DISABLE_AWS)
194option(CURL_DISABLE_DICT "disables DICT" OFF)
195mark_as_advanced(CURL_DISABLE_DICT)
196option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF)
197mark_as_advanced(CURL_DISABLE_DOH)
198option(CURL_DISABLE_FILE "disables FILE" OFF)
199mark_as_advanced(CURL_DISABLE_FILE)
200cmake_dependent_option(CURL_DISABLE_FORM_API "disables form api" OFF
201                       "NOT CURL_DISABLE_MIME" ON)
202mark_as_advanced(CURL_DISABLE_FORM_API)
203option(CURL_DISABLE_FTP "disables FTP" OFF)
204mark_as_advanced(CURL_DISABLE_FTP)
205option(CURL_DISABLE_GETOPTIONS "disables curl_easy_options API for existing options to curl_easy_setopt" OFF)
206mark_as_advanced(CURL_DISABLE_GETOPTIONS)
207option(CURL_DISABLE_GOPHER "disables Gopher" OFF)
208mark_as_advanced(CURL_DISABLE_GOPHER)
209option(CURL_DISABLE_HEADERS_API "disables headers-api support" OFF)
210mark_as_advanced(CURL_DISABLE_HEADERS_API)
211option(CURL_DISABLE_HSTS "disables HSTS support" OFF)
212mark_as_advanced(CURL_DISABLE_HSTS)
213option(CURL_DISABLE_HTTP "disables HTTP" OFF)
214mark_as_advanced(CURL_DISABLE_HTTP)
215option(CURL_DISABLE_HTTP_AUTH "disables all HTTP authentication methods" OFF)
216mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
217option(CURL_DISABLE_IMAP "disables IMAP" OFF)
218mark_as_advanced(CURL_DISABLE_IMAP)
219option(CURL_DISABLE_LDAP "disables LDAP" OFF)
220mark_as_advanced(CURL_DISABLE_LDAP)
221option(CURL_DISABLE_LDAPS "disables LDAPS" OFF)
222mark_as_advanced(CURL_DISABLE_LDAPS)
223option(CURL_DISABLE_LIBCURL_OPTION "disables --libcurl option from the curl tool" OFF)
224mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
225option(CURL_DISABLE_MIME "disables MIME support" OFF)
226mark_as_advanced(CURL_DISABLE_MIME)
227option(CURL_DISABLE_MQTT "disables MQTT" OFF)
228mark_as_advanced(CURL_DISABLE_BINDLOCAL)
229option(CURL_DISABLE_BINDLOCAL "disables local binding support" OFF)
230mark_as_advanced(CURL_DISABLE_MQTT)
231option(CURL_DISABLE_NETRC "disables netrc parser" OFF)
232mark_as_advanced(CURL_DISABLE_NETRC)
233option(CURL_DISABLE_NTLM "disables NTLM support" OFF)
234mark_as_advanced(CURL_DISABLE_NTLM)
235option(CURL_DISABLE_PARSEDATE "disables date parsing" OFF)
236mark_as_advanced(CURL_DISABLE_PARSEDATE)
237option(CURL_DISABLE_POP3 "disables POP3" OFF)
238mark_as_advanced(CURL_DISABLE_POP3)
239option(CURL_DISABLE_PROGRESS_METER "disables built-in progress meter" OFF)
240mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
241option(CURL_DISABLE_PROXY "disables proxy support" OFF)
242mark_as_advanced(CURL_DISABLE_PROXY)
243option(CURL_DISABLE_RTSP "disables RTSP" OFF)
244mark_as_advanced(CURL_DISABLE_RTSP)
245option(CURL_DISABLE_SHUFFLE_DNS "disables shuffle DNS feature" OFF)
246mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
247option(CURL_DISABLE_SMB "disables SMB" OFF)
248mark_as_advanced(CURL_DISABLE_SMB)
249option(CURL_DISABLE_SMTP "disables SMTP" OFF)
250mark_as_advanced(CURL_DISABLE_SMTP)
251option(CURL_DISABLE_SOCKETPAIR "disables use of socketpair for curl_multi_poll" OFF)
252mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
253option(CURL_DISABLE_TELNET "disables Telnet" OFF)
254mark_as_advanced(CURL_DISABLE_TELNET)
255option(CURL_DISABLE_TFTP "disables TFTP" OFF)
256mark_as_advanced(CURL_DISABLE_TFTP)
257option(CURL_DISABLE_VERBOSE_STRINGS "disables verbose strings" OFF)
258mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
259
260# Corresponds to HTTP_ONLY in lib/curl_setup.h
261option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
262mark_as_advanced(HTTP_ONLY)
263
264if(HTTP_ONLY)
265  set(CURL_DISABLE_DICT ON)
266  set(CURL_DISABLE_FILE ON)
267  set(CURL_DISABLE_FTP ON)
268  set(CURL_DISABLE_GOPHER ON)
269  set(CURL_DISABLE_IMAP ON)
270  set(CURL_DISABLE_LDAP ON)
271  set(CURL_DISABLE_LDAPS ON)
272  set(CURL_DISABLE_MQTT ON)
273  set(CURL_DISABLE_POP3 ON)
274  set(CURL_DISABLE_RTSP ON)
275  set(CURL_DISABLE_SMB ON)
276  set(CURL_DISABLE_SMTP ON)
277  set(CURL_DISABLE_TELNET ON)
278  set(CURL_DISABLE_TFTP ON)
279endif()
280
281option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
282mark_as_advanced(ENABLE_IPV6)
283if(ENABLE_IPV6 AND NOT WIN32)
284  include(CheckStructHasMember)
285  check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
286                          HAVE_SOCKADDR_IN6_SIN6_ADDR)
287  check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
288                          HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
289  if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
290    message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
291    # Force the feature off as this name is used as guard macro...
292    set(ENABLE_IPV6 OFF
293        CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
294  endif()
295
296  if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_ARES)
297    set(use_core_foundation_and_core_services ON)
298
299    find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
300    if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
301      message(FATAL_ERROR "SystemConfiguration framework not found")
302    endif()
303
304    list(APPEND CURL_LIBS "-framework SystemConfiguration")
305  endif()
306endif()
307if(ENABLE_IPV6)
308  set(USE_IPV6 ON)
309endif()
310
311find_package(Perl)
312
313option(BUILD_LIBCURL_DOCS "to build libcurl man pages" ON)
314option(BUILD_MISC_DOCS "to build misc man pages (e.g. curl-config and mk-ca-bundle)" ON)
315option(ENABLE_CURL_MANUAL "to build the man page for curl and enable its -M/--manual option" ON)
316
317if(ENABLE_CURL_MANUAL OR BUILD_LIBCURL_DOCS)
318  if(PERL_FOUND)
319    set(HAVE_MANUAL_TOOLS ON)
320  endif()
321  if(NOT HAVE_MANUAL_TOOLS)
322    message(WARNING "Perl not found. Will not build manuals.")
323  endif()
324endif()
325
326if(CURL_STATIC_CRT)
327  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
328  set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
329  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
330endif()
331
332# Disable warnings on Borland to avoid changing 3rd party code.
333if(BORLAND)
334  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
335endif()
336
337# If we are on AIX, do the _ALL_SOURCE magic
338if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
339  set(_ALL_SOURCE 1)
340endif()
341
342# If we are on Haiku, make sure that the network library is brought in.
343if(${CMAKE_SYSTEM_NAME} MATCHES Haiku)
344  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnetwork")
345endif()
346
347# Include all the necessary files for macros
348include(CMakePushCheckState)
349include(CheckFunctionExists)
350include(CheckIncludeFile)
351include(CheckIncludeFiles)
352include(CheckLibraryExists)
353include(CheckSymbolExists)
354include(CheckTypeSize)
355include(CheckCSourceCompiles)
356
357# On windows preload settings
358if(WIN32)
359  include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
360endif()
361
362if(ENABLE_THREADED_RESOLVER)
363  if(WIN32)
364    set(USE_THREADS_WIN32 ON)
365  else()
366    find_package(Threads REQUIRED)
367    set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
368    set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
369    set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
370  endif()
371endif()
372
373# Check for all needed libraries
374check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
375if(HAVE_LIBSOCKET)
376  set(CURL_LIBS "socket;${CURL_LIBS}")
377endif()
378
379check_function_exists(gethostname HAVE_GETHOSTNAME)
380
381if(WIN32)
382  list(APPEND CURL_LIBS "ws2_32" "bcrypt")
383endif()
384
385# check SSL libraries
386option(CURL_ENABLE_SSL "Enable SSL support" ON)
387
388if(CURL_DEFAULT_SSL_BACKEND)
389  set(valid_default_ssl_backend FALSE)
390endif()
391
392if(APPLE)
393  cmake_dependent_option(CURL_USE_SECTRANSP "Enable Apple OS native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
394endif()
395if(WIN32)
396  cmake_dependent_option(CURL_USE_SCHANNEL "Enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
397  option(CURL_WINDOWS_SSPI "Enable SSPI on Windows" ${CURL_USE_SCHANNEL})
398endif()
399cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
400cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
401cmake_dependent_option(CURL_USE_WOLFSSL "Enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
402cmake_dependent_option(CURL_USE_GNUTLS "Enable GnuTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
403
404set(openssl_default ON)
405if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_WOLFSSL)
406  set(openssl_default OFF)
407endif()
408cmake_dependent_option(CURL_USE_OPENSSL "Enable OpenSSL for SSL/TLS" ${openssl_default} CURL_ENABLE_SSL OFF)
409option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF)
410
411count_true(enabled_ssl_options_count
412  CURL_USE_SCHANNEL
413  CURL_USE_SECTRANSP
414  CURL_USE_OPENSSL
415  CURL_USE_MBEDTLS
416  CURL_USE_BEARSSL
417  CURL_USE_WOLFSSL
418)
419if(enabled_ssl_options_count GREATER "1")
420  set(CURL_WITH_MULTI_SSL ON)
421endif()
422
423if(CURL_USE_SCHANNEL)
424  set(SSL_ENABLED ON)
425  set(USE_SCHANNEL ON) # Windows native SSL/TLS support
426  set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI
427
428  if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "schannel")
429    set(valid_default_ssl_backend TRUE)
430  endif()
431endif()
432if(CURL_WINDOWS_SSPI)
433  set(USE_WINDOWS_SSPI ON)
434endif()
435
436if(CURL_USE_SECTRANSP)
437  set(use_core_foundation_and_core_services ON)
438
439  find_library(SECURITY_FRAMEWORK "Security")
440  if(NOT SECURITY_FRAMEWORK)
441    message(FATAL_ERROR "Security framework not found")
442  endif()
443
444  set(SSL_ENABLED ON)
445  set(USE_SECTRANSP ON)
446  list(APPEND CURL_LIBS "-framework Security")
447
448  if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport")
449    set(valid_default_ssl_backend TRUE)
450  endif()
451endif()
452
453if(use_core_foundation_and_core_services)
454  find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
455  find_library(CORESERVICES_FRAMEWORK "CoreServices")
456
457  if(NOT COREFOUNDATION_FRAMEWORK)
458    message(FATAL_ERROR "CoreFoundation framework not found")
459  endif()
460  if(NOT CORESERVICES_FRAMEWORK)
461    message(FATAL_ERROR "CoreServices framework not found")
462  endif()
463
464  list(APPEND CURL_LIBS "-framework CoreFoundation -framework CoreServices")
465endif()
466
467if(CURL_USE_OPENSSL)
468  find_package(OpenSSL REQUIRED)
469  set(SSL_ENABLED ON)
470  set(USE_OPENSSL ON)
471
472  # Depend on OpenSSL via imported targets if supported by the running
473  # version of CMake.  This allows our dependents to get our dependencies
474  # transitively.
475  if(NOT CMAKE_VERSION VERSION_LESS 3.4)
476    list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
477  else()
478    list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
479    include_directories(${OPENSSL_INCLUDE_DIR})
480  endif()
481
482  if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl")
483    set(valid_default_ssl_backend TRUE)
484  endif()
485
486  set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
487  if(NOT DEFINED HAVE_BORINGSSL)
488    check_symbol_exists(OPENSSL_IS_BORINGSSL "openssl/base.h" HAVE_BORINGSSL)
489  endif()
490  if(NOT DEFINED HAVE_AWSLC)
491    check_symbol_exists(OPENSSL_IS_AWSLC "openssl/base.h" HAVE_AWSLC)
492  endif()
493endif()
494
495if(CURL_USE_MBEDTLS)
496  find_package(MbedTLS REQUIRED)
497  set(SSL_ENABLED ON)
498  set(USE_MBEDTLS ON)
499  list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
500  include_directories(${MBEDTLS_INCLUDE_DIRS})
501
502  if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "mbedtls")
503    set(valid_default_ssl_backend TRUE)
504  endif()
505endif()
506
507if(CURL_USE_BEARSSL)
508  find_package(BearSSL REQUIRED)
509  set(SSL_ENABLED ON)
510  set(USE_BEARSSL ON)
511  list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
512  include_directories(${BEARSSL_INCLUDE_DIRS})
513
514  if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "bearssl")
515    set(valid_default_ssl_backend TRUE)
516  endif()
517endif()
518
519if(CURL_USE_WOLFSSL)
520  find_package(WolfSSL REQUIRED)
521  set(SSL_ENABLED ON)
522  set(USE_WOLFSSL ON)
523  list(APPEND CURL_LIBS ${WolfSSL_LIBRARIES})
524  include_directories(${WolfSSL_INCLUDE_DIRS})
525
526  if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "wolfssl")
527    set(valid_default_ssl_backend TRUE)
528  endif()
529endif()
530
531if(CURL_USE_GNUTLS)
532  find_package(GnuTLS REQUIRED)
533  set(SSL_ENABLED ON)
534  set(USE_GNUTLS ON)
535  list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES} "nettle")
536  include_directories(${GNUTLS_INCLUDE_DIRS})
537
538  if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls")
539    set(valid_default_ssl_backend TRUE)
540  endif()
541
542  if(NOT DEFINED HAVE_GNUTLS_SRP AND NOT CURL_DISABLE_SRP)
543    cmake_push_check_state()
544    set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
545    set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
546    check_symbol_exists(gnutls_srp_verifier "gnutls/gnutls.h" HAVE_GNUTLS_SRP)
547    cmake_pop_check_state()
548  endif()
549endif()
550
551if(CURL_DEFAULT_SSL_BACKEND AND NOT valid_default_ssl_backend)
552  message(FATAL_ERROR "CURL_DEFAULT_SSL_BACKEND '${CURL_DEFAULT_SSL_BACKEND}' not enabled.")
553endif()
554
555# Keep ZLIB detection after TLS detection,
556# and before calling openssl_check_symbol_exists().
557
558set(HAVE_LIBZ OFF)
559set(USE_ZLIB OFF)
560optional_dependency(ZLIB)
561if(ZLIB_FOUND)
562  set(HAVE_LIBZ ON)
563  set(USE_ZLIB ON)
564
565  # Depend on ZLIB via imported targets if supported by the running
566  # version of CMake.  This allows our dependents to get our dependencies
567  # transitively.
568  if(NOT CMAKE_VERSION VERSION_LESS 3.4)
569    list(APPEND CURL_LIBS ZLIB::ZLIB)
570  else()
571    list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
572    include_directories(${ZLIB_INCLUDE_DIRS})
573  endif()
574  list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
575endif()
576
577option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
578set(HAVE_BROTLI OFF)
579if(CURL_BROTLI)
580  find_package(Brotli REQUIRED)
581  if(BROTLI_FOUND)
582    set(HAVE_BROTLI ON)
583    set(CURL_LIBS "${BROTLI_LIBRARIES};${CURL_LIBS}")  # For 'ld' linker. Emulate `list(PREPEND ...)` to stay compatible with <v3.15 CMake.
584    list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
585    include_directories(${BROTLI_INCLUDE_DIRS})
586    list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
587  endif()
588endif()
589
590option(CURL_ZSTD "Set to ON to enable building curl with zstd support." OFF)
591set(HAVE_ZSTD OFF)
592if(CURL_ZSTD)
593  find_package(Zstd REQUIRED)
594  if(Zstd_FOUND AND NOT Zstd_VERSION VERSION_LESS "1.0.0")
595    set(HAVE_ZSTD ON)
596    list(APPEND CURL_LIBS ${Zstd_LIBRARIES})
597    include_directories(${Zstd_INCLUDE_DIRS})
598  else()
599    message(WARNING "zstd v1.0.0 or newer is required, disabling zstd support.")
600  endif()
601endif()
602
603# Check symbol in an OpenSSL-like TLS backend, or in EXTRA_LIBS depending on it.
604macro(openssl_check_symbol_exists SYMBOL FILES VARIABLE EXTRA_LIBS)
605  cmake_push_check_state()
606  if(USE_OPENSSL)
607    set(CMAKE_REQUIRED_INCLUDES   "${OPENSSL_INCLUDE_DIR}")
608    set(CMAKE_REQUIRED_LIBRARIES  "${OPENSSL_LIBRARIES}")
609    if(HAVE_LIBZ)
610      list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
611    endif()
612    if(WIN32)
613      list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
614      list(APPEND CMAKE_REQUIRED_LIBRARIES "bcrypt")  # for OpenSSL/LibreSSL
615    endif()
616  elseif(USE_WOLFSSL)
617    set(CMAKE_REQUIRED_INCLUDES   "${WolfSSL_INCLUDE_DIRS}")
618    set(CMAKE_REQUIRED_LIBRARIES  "${WolfSSL_LIBRARIES}")
619    if(HAVE_LIBZ)
620      list(APPEND CMAKE_REQUIRED_INCLUDES  "${ZLIB_INCLUDE_DIRS}")  # Public wolfSSL headers require zlib headers
621      list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
622    endif()
623    if(WIN32)
624      list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32" "crypt32")
625    endif()
626    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_UINTPTR_T)  # to pull in stdint.h (as of wolfSSL v5.5.4)
627  endif()
628  if(NOT "${EXTRA_LIBS}" STREQUAL "")
629    list(APPEND CMAKE_REQUIRED_LIBRARIES "${EXTRA_LIBS}")
630  endif()
631  check_symbol_exists("${SYMBOL}" "${FILES}" "${VARIABLE}")
632  cmake_pop_check_state()
633endmacro()
634
635# Ensure that the OpenSSL fork actually supports QUIC.
636macro(openssl_check_quic)
637  if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD)
638    if(USE_OPENSSL)
639      openssl_check_symbol_exists(SSL_CTX_set_quic_method "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD "")
640    elseif(USE_WOLFSSL)
641      openssl_check_symbol_exists(wolfSSL_set_quic_method "wolfssl/options.h;wolfssl/openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD "")
642    endif()
643  endif()
644  if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD)
645    message(FATAL_ERROR "QUIC support is missing in OpenSSL fork. Try setting -DOPENSSL_ROOT_DIR")
646  endif()
647endmacro()
648
649if(USE_OPENSSL OR USE_WOLFSSL)
650  if(NOT DEFINED HAVE_SSL_SET0_WBIO)
651    openssl_check_symbol_exists(SSL_set0_wbio "openssl/ssl.h" HAVE_SSL_SET0_WBIO "")
652  endif()
653  if(NOT DEFINED HAVE_OPENSSL_SRP AND NOT CURL_DISABLE_SRP)
654    openssl_check_symbol_exists(SSL_CTX_set_srp_username "openssl/ssl.h" HAVE_OPENSSL_SRP "")
655  endif()
656endif()
657
658option(USE_HTTPSRR "Enable HTTPS RR support for ECH (experimental)" OFF)
659option(USE_ECH "Enable ECH support" OFF)
660if(USE_ECH)
661  if(USE_OPENSSL OR USE_WOLFSSL)
662    # Be sure that the TLS library actually supports ECH.
663    if(NOT DEFINED HAVE_ECH)
664      if(USE_OPENSSL AND HAVE_BORINGSSL)
665        openssl_check_symbol_exists(SSL_set1_ech_config_list "openssl/ssl.h" HAVE_ECH "")
666      elseif(USE_OPENSSL)
667        openssl_check_symbol_exists(SSL_ech_set1_echconfig "openssl/ech.h" HAVE_ECH "")
668      elseif(USE_WOLFSSL)
669        openssl_check_symbol_exists(wolfSSL_CTX_GenerateEchConfig "wolfssl/options.h;wolfssl/ssl.h" HAVE_ECH "")
670      endif()
671    endif()
672    if(NOT HAVE_ECH)
673      message(FATAL_ERROR "ECH support missing in OpenSSL/BoringSSL/wolfSSL")
674    else()
675      message(STATUS "ECH enabled.")
676    endif()
677  else()
678    message(FATAL_ERROR "ECH requires ECH-enablded OpenSSL, BoringSSL or wolfSSL")
679  endif()
680endif()
681
682option(USE_NGHTTP2 "Use nghttp2 library" OFF)
683if(USE_NGHTTP2)
684  find_package(NGHTTP2 REQUIRED)
685  include_directories(${NGHTTP2_INCLUDE_DIRS})
686  list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
687endif()
688
689option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF)
690if(USE_NGTCP2)
691  if(USE_OPENSSL OR USE_WOLFSSL)
692    if(USE_WOLFSSL)
693      find_package(NGTCP2 REQUIRED wolfSSL)
694    elseif(HAVE_BORINGSSL OR HAVE_AWSLC)
695      find_package(NGTCP2 REQUIRED BoringSSL)
696    else()
697      find_package(NGTCP2 REQUIRED quictls)
698    endif()
699    openssl_check_quic()
700  elseif(USE_GNUTLS)
701    find_package(NGTCP2 REQUIRED GnuTLS)
702  else()
703    message(FATAL_ERROR "ngtcp2 requires OpenSSL, wolfSSL or GnuTLS")
704  endif()
705  set(USE_NGTCP2 ON)
706  include_directories(${NGTCP2_INCLUDE_DIRS})
707  list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES})
708
709  find_package(NGHTTP3 REQUIRED)
710  set(USE_NGHTTP3 ON)
711  include_directories(${NGHTTP3_INCLUDE_DIRS})
712  list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
713endif()
714
715option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF)
716if(USE_QUICHE)
717  if(USE_NGTCP2)
718    message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
719  endif()
720  find_package(QUICHE REQUIRED)
721  if(NOT HAVE_BORINGSSL)
722    message(FATAL_ERROR "quiche requires BoringSSL")
723  endif()
724  openssl_check_quic()
725  set(USE_QUICHE ON)
726  include_directories(${QUICHE_INCLUDE_DIRS})
727  list(APPEND CURL_LIBS ${QUICHE_LIBRARIES})
728  if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD)
729    cmake_push_check_state()
730    set(CMAKE_REQUIRED_INCLUDES   "${QUICHE_INCLUDE_DIRS}")
731    set(CMAKE_REQUIRED_LIBRARIES  "${QUICHE_LIBRARIES}")
732    check_symbol_exists(quiche_conn_set_qlog_fd "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD)
733    cmake_pop_check_state()
734  endif()
735endif()
736
737option(USE_MSH3 "Use msquic library for HTTP/3 support" OFF)
738if(USE_MSH3)
739  if(USE_NGTCP2 OR USE_QUICHE)
740    message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
741  endif()
742  set(USE_MSH3 ON)
743  include_directories(${MSH3_INCLUDE_DIRS})
744  list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
745endif()
746
747option(USE_OPENSSL_QUIC "Use openssl and nghttp3 libraries for HTTP/3 support" OFF)
748if(USE_OPENSSL_QUIC)
749  if(USE_NGTCP2 OR USE_QUICHE OR USE_MSH3)
750    message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
751  endif()
752  find_package(OpenSSL 3.2.0 REQUIRED)
753
754  find_package(NGHTTP3 REQUIRED)
755  set(USE_NGHTTP3 ON)
756  include_directories(${NGHTTP3_INCLUDE_DIRS})
757  list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
758endif()
759
760if(USE_MBEDTLS OR
761   USE_BEARSSL OR
762   USE_SECTRANSP)
763  message(WARNING "A selected TLS library does not support TLS 1.3.")
764endif()
765
766if(CURL_WITH_MULTI_SSL AND (USE_NGTCP2 OR USE_QUICHE OR USE_MSH3 OR USE_OPENSSL_QUIC))
767  message(FATAL_ERROR "MultiSSL cannot be enabled with HTTP/3 and vice versa.")
768endif()
769
770if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP))
771  set(USE_TLS_SRP 1)
772endif()
773
774if(NOT CURL_DISABLE_LDAP)
775  if(WIN32)
776    option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
777    if(USE_WIN32_LDAP)
778      list(APPEND CURL_LIBS "wldap32")
779      if(NOT CURL_DISABLE_LDAPS)
780        set(HAVE_LDAP_SSL ON)
781      endif()
782    endif()
783  endif()
784
785  set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
786  set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
787
788  # Now that we know, we're not using windows LDAP...
789  if(NOT USE_WIN32_LDAP)
790    # Check for LDAP
791    set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
792    check_library_exists("${CMAKE_LDAP_LIB}" "ldap_init" "" HAVE_LIBLDAP)
793    if(HAVE_LIBLDAP)
794      check_library_exists("${CMAKE_LDAP_LIB};${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
795    else()
796      check_library_exists("${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
797    endif()
798
799    set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
800    set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
801    if(CMAKE_LDAP_INCLUDE_DIR)
802      list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
803    endif()
804    check_include_file_concat("ldap.h"           HAVE_LDAP_H)
805    check_include_file_concat("lber.h"           HAVE_LBER_H)
806
807    if(NOT HAVE_LDAP_H)
808      message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
809      set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
810      set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
811    elseif(NOT HAVE_LIBLDAP)
812      message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
813      set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
814      set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
815    else()
816      if(CMAKE_LDAP_INCLUDE_DIR)
817        include_directories(${CMAKE_LDAP_INCLUDE_DIR})
818      endif()
819      set(NEED_LBER_H ON)
820      set(_HEADER_LIST)
821      if(WIN32)
822        list(APPEND _HEADER_LIST "windows.h")
823      endif()
824      if(HAVE_SYS_TYPES_H)
825        list(APPEND _HEADER_LIST "sys/types.h")
826      endif()
827      list(APPEND _HEADER_LIST "ldap.h")
828
829      set(_INCLUDE_STRING "")
830      foreach(_HEADER ${_HEADER_LIST})
831        set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
832      endforeach()
833
834      list(APPEND CMAKE_REQUIRED_DEFINITIONS -DLDAP_DEPRECATED=1)
835      list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
836      set(CURL_LIBS "${CMAKE_LDAP_LIB};${CURL_LIBS}")
837      if(HAVE_LIBLBER)
838        list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
839        set(CURL_LIBS "${CMAKE_LBER_LIB};${CURL_LIBS}")
840      endif()
841
842      check_c_source_compiles("
843        ${_INCLUDE_STRING}
844        int main(int argc, char ** argv)
845        {
846          BerValue *bvp = NULL;
847          BerElement *bep = ber_init(bvp);
848          ber_free(bep, 1);
849          return 0;
850        }" NOT_NEED_LBER_H)
851      if(NOT_NEED_LBER_H)
852        set(NEED_LBER_H OFF)
853      else()
854        set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
855      endif()
856
857      check_function_exists(ldap_url_parse HAVE_LDAP_URL_PARSE)
858      check_function_exists(ldap_init_fd HAVE_LDAP_INIT_FD)
859
860      unset(CMAKE_REQUIRED_LIBRARIES)
861
862      check_include_file("ldap_ssl.h" HAVE_LDAP_SSL_H)
863
864      if(HAVE_LDAP_INIT_FD)
865        set(USE_OPENLDAP ON)
866        add_definitions("-DLDAP_DEPRECATED=1")
867      endif()
868      if(NOT CURL_DISABLE_LDAPS)
869        set(HAVE_LDAP_SSL ON)
870      endif()
871    endif()
872  endif()
873endif()
874
875# No ldap, no ldaps.
876if(CURL_DISABLE_LDAP)
877  if(NOT CURL_DISABLE_LDAPS)
878    message(STATUS "LDAP needs to be enabled to support LDAPS")
879    set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
880  endif()
881endif()
882
883# Check for idn2
884option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
885if(USE_LIBIDN2)
886  check_library_exists("idn2" "idn2_lookup_ul" "" HAVE_LIBIDN2)
887  if(HAVE_LIBIDN2)
888    set(CURL_LIBS "idn2;${CURL_LIBS}")
889    check_include_file_concat("idn2.h" HAVE_IDN2_H)
890  endif()
891else()
892  set(HAVE_LIBIDN2 OFF)
893endif()
894
895if(WIN32)
896  option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF)
897  if(USE_WIN32_IDN)
898    list(APPEND CURL_LIBS "normaliz")
899  endif()
900endif()
901
902if(APPLE)
903  option(USE_APPLE_IDN "Use Apple built-in IDN support" OFF)
904  if(USE_APPLE_IDN)
905    cmake_push_check_state()
906    set(CMAKE_REQUIRED_LIBRARIES "icucore")
907    check_symbol_exists("uidna_openUTS46" "unicode/uidna.h" HAVE_APPLE_IDN)
908    cmake_pop_check_state()
909    if(HAVE_APPLE_IDN)
910      list(APPEND CURL_LIBS "icucore")
911    else()
912      set(USE_APPLE_IDN OFF)
913    endif()
914  endif()
915endif()
916
917#libpsl
918option(CURL_USE_LIBPSL "Use libPSL" ON)
919mark_as_advanced(CURL_USE_LIBPSL)
920set(USE_LIBPSL OFF)
921
922if(CURL_USE_LIBPSL)
923  find_package(LibPSL)
924  if(LIBPSL_FOUND)
925    list(APPEND CURL_LIBS ${LIBPSL_LIBRARY})
926    list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIR}")
927    include_directories("${LIBPSL_INCLUDE_DIR}")
928    set(USE_LIBPSL ON)
929  endif()
930endif()
931
932#libSSH2
933option(CURL_USE_LIBSSH2 "Use libSSH2" ON)
934mark_as_advanced(CURL_USE_LIBSSH2)
935set(USE_LIBSSH2 OFF)
936
937if(CURL_USE_LIBSSH2)
938  find_package(LibSSH2)
939  if(LIBSSH2_FOUND)
940    list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
941    list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
942    include_directories("${LIBSSH2_INCLUDE_DIR}")
943    set(USE_LIBSSH2 ON)
944  endif()
945endif()
946
947# libssh
948option(CURL_USE_LIBSSH "Use libSSH" OFF)
949mark_as_advanced(CURL_USE_LIBSSH)
950if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
951  find_package(libssh CONFIG)
952  if(libssh_FOUND)
953    message(STATUS "Found libssh ${libssh_VERSION}")
954    # Use imported target for include and library paths.
955    list(APPEND CURL_LIBS ssh)
956    set(USE_LIBSSH ON)
957  endif()
958endif()
959
960option(CURL_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
961mark_as_advanced(CURL_USE_GSSAPI)
962
963if(CURL_USE_GSSAPI)
964  find_package(GSS)
965
966  set(HAVE_GSSAPI ${GSS_FOUND})
967  if(GSS_FOUND)
968
969    message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
970
971    list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
972    check_include_file_concat("gssapi/gssapi.h"  HAVE_GSSAPI_GSSAPI_H)
973    check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
974    check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
975
976    if(NOT GSS_FLAVOUR STREQUAL "Heimdal")
977      # MIT
978      set(_INCLUDE_LIST "")
979      if(HAVE_GSSAPI_GSSAPI_H)
980        list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
981      endif()
982      if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
983        list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
984      endif()
985      if(HAVE_GSSAPI_GSSAPI_KRB5_H)
986        list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
987      endif()
988
989      string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
990      string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
991
992      foreach(_dir ${GSS_LINK_DIRECTORIES})
993        set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
994      endforeach()
995
996      if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE)
997        set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
998        set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
999        check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
1000        unset(CMAKE_REQUIRED_LIBRARIES)
1001      endif()
1002      if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
1003        set(HAVE_OLD_GSSMIT ON)
1004      endif()
1005    endif()
1006
1007    include_directories(${GSS_INCLUDE_DIR})
1008    link_directories(${GSS_LINK_DIRECTORIES})
1009    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
1010    string(REPLACE ";" " " GSS_LINKER_FLAGS "${GSS_LINKER_FLAGS}")
1011    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
1012    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
1013    set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
1014    list(APPEND CURL_LIBS ${GSS_LIBRARIES})
1015
1016  else()
1017    message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
1018  endif()
1019endif()
1020
1021option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF)
1022if(USE_LIBRTMP)
1023  cmake_push_check_state()
1024  set(_extra_libs "rtmp")
1025  if(WIN32)
1026    list(APPEND _extra_libs "winmm")
1027  endif()
1028  openssl_check_symbol_exists("RTMP_Init" "librtmp/rtmp.h" HAVE_LIBRTMP "${_extra_libs}")
1029  cmake_pop_check_state()
1030  if(HAVE_LIBRTMP)
1031    list(APPEND CURL_LIBS "rtmp")
1032    if(WIN32)
1033      list(APPEND CURL_LIBS "winmm")
1034    endif()
1035  else()
1036    message(WARNING "librtmp requested, but not found or missing OpenSSL. Skipping.")
1037    set(USE_LIBRTMP OFF)
1038  endif()
1039endif()
1040
1041option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
1042if(ENABLE_UNIX_SOCKETS)
1043  include(CheckStructHasMember)
1044  if(WIN32)
1045    set(USE_UNIX_SOCKETS ON)
1046  else()
1047    check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
1048  endif()
1049else()
1050  unset(USE_UNIX_SOCKETS CACHE)
1051endif()
1052
1053
1054#
1055# CA handling
1056#
1057set(CURL_CA_BUNDLE "auto" CACHE STRING
1058    "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
1059set(CURL_CA_FALLBACK OFF CACHE BOOL
1060    "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
1061set(CURL_CA_PATH "auto" CACHE STRING
1062    "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
1063
1064if("${CURL_CA_BUNDLE}" STREQUAL "")
1065  message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
1066elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
1067  unset(CURL_CA_BUNDLE CACHE)
1068elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
1069  unset(CURL_CA_BUNDLE CACHE)
1070  if(NOT CMAKE_CROSSCOMPILING)
1071    set(CURL_CA_BUNDLE_AUTODETECT TRUE)
1072  endif()
1073else()
1074  set(CURL_CA_BUNDLE_SET TRUE)
1075endif()
1076
1077if("${CURL_CA_PATH}" STREQUAL "")
1078  message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
1079elseif("${CURL_CA_PATH}" STREQUAL "none")
1080  unset(CURL_CA_PATH CACHE)
1081elseif("${CURL_CA_PATH}" STREQUAL "auto")
1082  unset(CURL_CA_PATH CACHE)
1083  if(NOT CMAKE_CROSSCOMPILING)
1084    set(CURL_CA_PATH_AUTODETECT TRUE)
1085  endif()
1086else()
1087  set(CURL_CA_PATH_SET TRUE)
1088endif()
1089
1090if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
1091  # Skip autodetection of unset CA path because CA bundle is set explicitly
1092elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
1093  # Skip autodetection of unset CA bundle because CA path is set explicitly
1094elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
1095  # first try autodetecting a CA bundle, then a CA path
1096
1097  if(CURL_CA_BUNDLE_AUTODETECT)
1098    set(SEARCH_CA_BUNDLE_PATHS
1099        /etc/ssl/certs/ca-certificates.crt
1100        /etc/pki/tls/certs/ca-bundle.crt
1101        /usr/share/ssl/certs/ca-bundle.crt
1102        /usr/local/share/certs/ca-root-nss.crt
1103        /etc/ssl/cert.pem)
1104
1105    foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
1106      if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
1107        message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
1108        set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}" CACHE STRING
1109            "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
1110        set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
1111        break()
1112      endif()
1113    endforeach()
1114  endif()
1115
1116  if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
1117    if(EXISTS "/etc/ssl/certs")
1118      set(CURL_CA_PATH "/etc/ssl/certs" CACHE STRING
1119          "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
1120      set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
1121    endif()
1122  endif()
1123endif()
1124
1125if(CURL_CA_PATH_SET AND
1126   NOT USE_OPENSSL AND
1127   NOT USE_WOLFSSL AND
1128   NOT USE_GNUTLS AND
1129   NOT USE_MBEDTLS)
1130  message(STATUS
1131          "CA path only supported by OpenSSL, wolfSSL, GnuTLS or mbedTLS. "
1132          "Set CURL_CA_PATH=none or enable one of those TLS backends.")
1133endif()
1134
1135# Check for header files
1136if(WIN32)
1137  set(CURL_INCLUDES ${CURL_INCLUDES} "winsock2.h")
1138  set(CURL_INCLUDES ${CURL_INCLUDES} "ws2tcpip.h")
1139  set(CURL_INCLUDES ${CURL_INCLUDES} "windows.h")
1140endif()
1141
1142if(WIN32)
1143  # detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
1144  curl_internal_test(HAVE_WIN32_WINNT)
1145  if(HAVE_WIN32_WINNT)
1146    string(REGEX MATCH ".*_WIN32_WINNT=0x[0-9a-fA-F]+" OUTPUT "${OUTPUT}")
1147    string(REGEX REPLACE ".*_WIN32_WINNT=" "" OUTPUT "${OUTPUT}")
1148    string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" OUTPUT "${OUTPUT}")  # pad to 4 digits
1149    string(TOLOWER "${OUTPUT}" HAVE_WIN32_WINNT)
1150    message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
1151  endif()
1152  # avoid storing HAVE_WIN32_WINNT in CMake cache
1153  unset(HAVE_WIN32_WINNT CACHE)
1154
1155  if(HAVE_WIN32_WINNT)
1156    if(HAVE_WIN32_WINNT STRLESS "0x0501")
1157      # Windows XP is required for freeaddrinfo, getaddrinfo
1158      message(FATAL_ERROR "Building for Windows XP or newer is required.")
1159    endif()
1160
1161    # pre-fill detection results based on target OS version
1162    if(MINGW OR MSVC)
1163      if(HAVE_WIN32_WINNT STRLESS "0x0600")
1164        set(HAVE_INET_NTOP 0)
1165        set(HAVE_INET_PTON 0)
1166      else()  # Windows Vista or newer
1167        set(HAVE_INET_NTOP 1)
1168        set(HAVE_INET_PTON 1)
1169      endif()
1170      unset(HAVE_INET_NTOP CACHE)
1171      unset(HAVE_INET_PTON CACHE)
1172    endif()
1173  endif()
1174endif()
1175
1176check_include_file_concat("sys/filio.h"      HAVE_SYS_FILIO_H)
1177check_include_file_concat("sys/wait.h"       HAVE_SYS_WAIT_H)
1178check_include_file_concat("sys/ioctl.h"      HAVE_SYS_IOCTL_H)
1179check_include_file_concat("sys/param.h"      HAVE_SYS_PARAM_H)
1180check_include_file_concat("sys/poll.h"       HAVE_SYS_POLL_H)
1181check_include_file_concat("sys/resource.h"   HAVE_SYS_RESOURCE_H)
1182check_include_file_concat("sys/select.h"     HAVE_SYS_SELECT_H)
1183check_include_file_concat("sys/socket.h"     HAVE_SYS_SOCKET_H)
1184check_include_file_concat("sys/sockio.h"     HAVE_SYS_SOCKIO_H)
1185check_include_file_concat("sys/stat.h"       HAVE_SYS_STAT_H)
1186check_include_file_concat("sys/time.h"       HAVE_SYS_TIME_H)
1187check_include_file_concat("sys/types.h"      HAVE_SYS_TYPES_H)
1188check_include_file_concat("sys/un.h"         HAVE_SYS_UN_H)
1189check_include_file_concat("sys/utime.h"      HAVE_SYS_UTIME_H)
1190check_include_file_concat("sys/xattr.h"      HAVE_SYS_XATTR_H)
1191check_include_file_concat("arpa/inet.h"      HAVE_ARPA_INET_H)
1192check_include_file_concat("dirent.h"         HAVE_DIRENT_H)
1193check_include_file_concat("fcntl.h"          HAVE_FCNTL_H)
1194check_include_file_concat("ifaddrs.h"        HAVE_IFADDRS_H)
1195check_include_file_concat("io.h"             HAVE_IO_H)
1196check_include_file_concat("libgen.h"         HAVE_LIBGEN_H)
1197check_include_file_concat("locale.h"         HAVE_LOCALE_H)
1198check_include_file_concat("net/if.h"         HAVE_NET_IF_H)
1199check_include_file_concat("netdb.h"          HAVE_NETDB_H)
1200check_include_file_concat("netinet/in.h"     HAVE_NETINET_IN_H)
1201check_include_file_concat("netinet/tcp.h"    HAVE_NETINET_TCP_H)
1202check_include_file_concat("netinet/udp.h"    HAVE_NETINET_UDP_H)
1203check_include_file("linux/tcp.h"      HAVE_LINUX_TCP_H)
1204
1205check_include_file_concat("poll.h"           HAVE_POLL_H)
1206check_include_file_concat("pwd.h"            HAVE_PWD_H)
1207check_include_file_concat("stdatomic.h"      HAVE_STDATOMIC_H)
1208check_include_file_concat("stdbool.h"        HAVE_STDBOOL_H)
1209check_include_file_concat("strings.h"        HAVE_STRINGS_H)
1210check_include_file_concat("stropts.h"        HAVE_STROPTS_H)
1211check_include_file_concat("termio.h"         HAVE_TERMIO_H)
1212check_include_file_concat("termios.h"        HAVE_TERMIOS_H)
1213check_include_file_concat("unistd.h"         HAVE_UNISTD_H)
1214check_include_file_concat("utime.h"          HAVE_UTIME_H)
1215
1216check_type_size(size_t  SIZEOF_SIZE_T)
1217check_type_size(ssize_t  SIZEOF_SSIZE_T)
1218check_type_size("long long"  SIZEOF_LONG_LONG)
1219check_type_size("long"  SIZEOF_LONG)
1220check_type_size("int"  SIZEOF_INT)
1221check_type_size("__int64"  SIZEOF___INT64)
1222check_type_size("time_t"  SIZEOF_TIME_T)
1223check_type_size("suseconds_t"  SIZEOF_SUSECONDS_T)
1224if(NOT HAVE_SIZEOF_SSIZE_T)
1225  if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
1226    set(ssize_t long)
1227  endif()
1228  if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
1229    set(ssize_t __int64)
1230  endif()
1231endif()
1232# off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
1233
1234if(SIZEOF_LONG_LONG)
1235  set(HAVE_LONGLONG 1)
1236endif()
1237if(SIZEOF_SUSECONDS_T)
1238  set(HAVE_SUSECONDS_T 1)
1239endif()
1240
1241if(NOT CMAKE_CROSSCOMPILING)
1242  find_file(RANDOM_FILE urandom /dev)
1243  mark_as_advanced(RANDOM_FILE)
1244endif()
1245
1246# Check for some functions that are used
1247if(WIN32)
1248  set(CMAKE_REQUIRED_LIBRARIES ws2_32)
1249elseif(HAVE_LIBSOCKET)
1250  set(CMAKE_REQUIRED_LIBRARIES socket)
1251endif()
1252
1253check_symbol_exists(fnmatch       "${CURL_INCLUDES};fnmatch.h" HAVE_FNMATCH)
1254check_symbol_exists(basename      "${CURL_INCLUDES};string.h" HAVE_BASENAME)
1255check_symbol_exists(opendir       "${CURL_INCLUDES};dirent.h" HAVE_OPENDIR)
1256check_symbol_exists(socket        "${CURL_INCLUDES}" HAVE_SOCKET)
1257check_symbol_exists(sched_yield   "${CURL_INCLUDES};sched.h" HAVE_SCHED_YIELD)
1258check_symbol_exists(socketpair    "${CURL_INCLUDES}" HAVE_SOCKETPAIR)
1259check_symbol_exists(recv          "${CURL_INCLUDES}" HAVE_RECV)
1260check_symbol_exists(send          "${CURL_INCLUDES}" HAVE_SEND)
1261check_symbol_exists(sendmsg       "${CURL_INCLUDES}" HAVE_SENDMSG)
1262check_symbol_exists(select        "${CURL_INCLUDES}" HAVE_SELECT)
1263check_symbol_exists(strdup        "${CURL_INCLUDES};string.h" HAVE_STRDUP)
1264check_symbol_exists(strtok_r      "${CURL_INCLUDES};string.h" HAVE_STRTOK_R)
1265check_symbol_exists(strcasecmp    "${CURL_INCLUDES};string.h" HAVE_STRCASECMP)
1266check_symbol_exists(stricmp       "${CURL_INCLUDES};string.h" HAVE_STRICMP)
1267check_symbol_exists(strcmpi       "${CURL_INCLUDES};string.h" HAVE_STRCMPI)
1268check_symbol_exists(memrchr       "${CURL_INCLUDES};string.h" HAVE_MEMRCHR)
1269check_symbol_exists(alarm         "${CURL_INCLUDES}" HAVE_ALARM)
1270check_symbol_exists(arc4random    "${CURL_INCLUDES};stdlib.h" HAVE_ARC4RANDOM)
1271check_symbol_exists(fcntl         "${CURL_INCLUDES}" HAVE_FCNTL)
1272check_symbol_exists(getppid       "${CURL_INCLUDES}" HAVE_GETPPID)
1273check_symbol_exists(utimes        "${CURL_INCLUDES}" HAVE_UTIMES)
1274
1275check_symbol_exists(gettimeofday  "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
1276check_symbol_exists(closesocket   "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
1277check_symbol_exists(sigsetjmp     "${CURL_INCLUDES};setjmp.h" HAVE_SIGSETJMP)
1278check_symbol_exists(getpass_r     "${CURL_INCLUDES}" HAVE_GETPASS_R)
1279check_symbol_exists(getpwuid      "${CURL_INCLUDES}" HAVE_GETPWUID)
1280check_symbol_exists(getpwuid_r    "${CURL_INCLUDES}" HAVE_GETPWUID_R)
1281check_symbol_exists(geteuid       "${CURL_INCLUDES}" HAVE_GETEUID)
1282check_symbol_exists(utime         "${CURL_INCLUDES}" HAVE_UTIME)
1283check_symbol_exists(gmtime_r      "${CURL_INCLUDES};stdlib.h;time.h" HAVE_GMTIME_R)
1284
1285check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
1286
1287check_symbol_exists(signal         "${CURL_INCLUDES};signal.h" HAVE_SIGNAL)
1288check_symbol_exists(strtoll        "${CURL_INCLUDES};stdlib.h" HAVE_STRTOLL)
1289check_symbol_exists(strerror_r     "${CURL_INCLUDES};stdlib.h;string.h" HAVE_STRERROR_R)
1290check_symbol_exists(sigaction      "signal.h" HAVE_SIGACTION)
1291check_symbol_exists(siginterrupt   "${CURL_INCLUDES};signal.h" HAVE_SIGINTERRUPT)
1292check_symbol_exists(getaddrinfo    "${CURL_INCLUDES};stdlib.h;string.h" HAVE_GETADDRINFO)
1293check_symbol_exists(getifaddrs     "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS)
1294check_symbol_exists(freeaddrinfo   "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
1295check_symbol_exists(pipe           "${CURL_INCLUDES}" HAVE_PIPE)
1296check_symbol_exists(ftruncate      "${CURL_INCLUDES}" HAVE_FTRUNCATE)
1297check_symbol_exists(_fseeki64      "${CURL_INCLUDES};stdio.h" HAVE__FSEEKI64)
1298check_symbol_exists(getpeername    "${CURL_INCLUDES}" HAVE_GETPEERNAME)
1299check_symbol_exists(getsockname    "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
1300check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
1301check_symbol_exists(getrlimit      "${CURL_INCLUDES}" HAVE_GETRLIMIT)
1302check_symbol_exists(setlocale      "${CURL_INCLUDES}" HAVE_SETLOCALE)
1303check_symbol_exists(setmode        "${CURL_INCLUDES}" HAVE_SETMODE)
1304check_symbol_exists(setrlimit      "${CURL_INCLUDES}" HAVE_SETRLIMIT)
1305
1306if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900))
1307  # earlier MSVC compilers had faulty snprintf implementations
1308  check_symbol_exists(snprintf       "stdio.h" HAVE_SNPRINTF)
1309endif()
1310check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
1311check_symbol_exists(inet_ntop      "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP)
1312if(MSVC AND (MSVC_VERSION LESS_EQUAL 1600))
1313  set(HAVE_INET_NTOP OFF)
1314endif()
1315check_symbol_exists(inet_pton      "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON)
1316
1317check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
1318if(HAVE_FSETXATTR)
1319  foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
1320    curl_internal_test(${CURL_TEST})
1321  endforeach()
1322endif()
1323
1324set(CMAKE_EXTRA_INCLUDE_FILES   "sys/socket.h")
1325check_type_size("sa_family_t"   SIZEOF_SA_FAMILY_T)
1326set(HAVE_SA_FAMILY_T            ${HAVE_SIZEOF_SA_FAMILY_T})
1327set(CMAKE_EXTRA_INCLUDE_FILES   "")
1328
1329if(WIN32)
1330  set(CMAKE_EXTRA_INCLUDE_FILES   "winsock2.h")
1331  check_type_size("ADDRESS_FAMILY"    SIZEOF_ADDRESS_FAMILY)
1332  set(HAVE_ADDRESS_FAMILY         ${HAVE_SIZEOF_ADDRESS_FAMILY})
1333  set(CMAKE_EXTRA_INCLUDE_FILES   "")
1334endif()
1335
1336# Do curl specific tests
1337foreach(CURL_TEST
1338    HAVE_FCNTL_O_NONBLOCK
1339    HAVE_IOCTLSOCKET
1340    HAVE_IOCTLSOCKET_CAMEL
1341    HAVE_IOCTLSOCKET_CAMEL_FIONBIO
1342    HAVE_IOCTLSOCKET_FIONBIO
1343    HAVE_IOCTL_FIONBIO
1344    HAVE_IOCTL_SIOCGIFADDR
1345    HAVE_SETSOCKOPT_SO_NONBLOCK
1346    HAVE_O_NONBLOCK
1347    HAVE_GETHOSTBYNAME_R_3
1348    HAVE_GETHOSTBYNAME_R_5
1349    HAVE_GETHOSTBYNAME_R_6
1350    HAVE_GETHOSTBYNAME_R_3_REENTRANT
1351    HAVE_GETHOSTBYNAME_R_5_REENTRANT
1352    HAVE_GETHOSTBYNAME_R_6_REENTRANT
1353    HAVE_IN_ADDR_T
1354    HAVE_BOOL_T
1355    STDC_HEADERS
1356    HAVE_FILE_OFFSET_BITS
1357    HAVE_ATOMIC
1358    )
1359  curl_internal_test(${CURL_TEST})
1360endforeach()
1361
1362if(HAVE_FILE_OFFSET_BITS)
1363  set(_FILE_OFFSET_BITS 64)
1364  set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
1365endif()
1366check_type_size("off_t"  SIZEOF_OFF_T)
1367
1368# fseeko may not exist with _FILE_OFFSET_BITS=64 but can exist with
1369# _FILE_OFFSET_BITS unset or 32 (e.g. Android ARMv7 with NDK 26b and API level < 24)
1370# so we need to test fseeko after testing for _FILE_OFFSET_BITS
1371check_symbol_exists(fseeko         "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
1372
1373if(HAVE_FSEEKO)
1374  set(HAVE_DECL_FSEEKO 1)
1375endif()
1376
1377# include this header to get the type
1378set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
1379set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
1380check_type_size("curl_off_t"  SIZEOF_CURL_OFF_T)
1381set(CMAKE_EXTRA_INCLUDE_FILES "curl/curl.h")
1382check_type_size("curl_socket_t"  SIZEOF_CURL_SOCKET_T)
1383set(CMAKE_EXTRA_INCLUDE_FILES "")
1384
1385if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
1386  # on not-Windows and not-crosscompiling, check for writable argv[]
1387  include(CheckCSourceRuns)
1388  check_c_source_runs("
1389    int main(int argc, char **argv)
1390    {
1391      (void)argc;
1392      argv[0][0] = ' ';
1393      return (argv[0][0] == ' ')?0:1;
1394    }" HAVE_WRITABLE_ARGV)
1395endif()
1396
1397set(CMAKE_REQUIRED_FLAGS)
1398
1399option(ENABLE_WEBSOCKETS "Set to ON to enable EXPERIMENTAL websockets" OFF)
1400
1401if(ENABLE_WEBSOCKETS)
1402  if(${SIZEOF_CURL_OFF_T} GREATER "4")
1403    set(USE_WEBSOCKETS ON)
1404  else()
1405    message(WARNING "curl_off_t is too small to enable WebSockets")
1406  endif()
1407endif()
1408
1409foreach(CURL_TEST
1410    HAVE_GLIBC_STRERROR_R
1411    HAVE_POSIX_STRERROR_R
1412    )
1413  curl_internal_test(${CURL_TEST})
1414endforeach()
1415
1416# Check for reentrant
1417foreach(CURL_TEST
1418    HAVE_GETHOSTBYNAME_R_3
1419    HAVE_GETHOSTBYNAME_R_5
1420    HAVE_GETHOSTBYNAME_R_6)
1421  if(NOT ${CURL_TEST})
1422    if(${CURL_TEST}_REENTRANT)
1423      set(NEED_REENTRANT 1)
1424    endif()
1425  endif()
1426endforeach()
1427
1428if(NEED_REENTRANT)
1429  foreach(CURL_TEST
1430      HAVE_GETHOSTBYNAME_R_3
1431      HAVE_GETHOSTBYNAME_R_5
1432      HAVE_GETHOSTBYNAME_R_6)
1433    set(${CURL_TEST} 0)
1434    if(${CURL_TEST}_REENTRANT)
1435      set(${CURL_TEST} 1)
1436    endif()
1437  endforeach()
1438endif()
1439
1440if(NOT WIN32)
1441  # Check clock_gettime(CLOCK_MONOTONIC, x) support
1442  curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
1443endif()
1444
1445# Check compiler support of __builtin_available()
1446curl_internal_test(HAVE_BUILTIN_AVAILABLE)
1447
1448# Some other minor tests
1449
1450if(NOT HAVE_IN_ADDR_T)
1451  set(in_addr_t "unsigned long")
1452endif()
1453
1454# Check for nonblocking
1455set(HAVE_DISABLED_NONBLOCKING 1)
1456if(HAVE_FIONBIO OR
1457    HAVE_IOCTLSOCKET OR
1458    HAVE_IOCTLSOCKET_CASE OR
1459    HAVE_O_NONBLOCK)
1460  set(HAVE_DISABLED_NONBLOCKING)
1461endif()
1462
1463if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1464  include(CheckCCompilerFlag)
1465  check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1466  if(HAVE_C_FLAG_Wno_long_double)
1467    # The Mac version of GCC warns about use of long double.  Disable it.
1468    get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1469    if(MPRINTF_COMPILE_FLAGS)
1470      set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1471    else()
1472      set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1473    endif()
1474    set_source_files_properties(mprintf.c PROPERTIES
1475      COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1476  endif()
1477endif()
1478
1479include(CMake/OtherTests.cmake)
1480
1481add_definitions(-DHAVE_CONFIG_H)
1482
1483# For Windows, all compilers used by CMake should support large files
1484if(WIN32)
1485  set(USE_WIN32_LARGE_FILES ON)
1486
1487  # Use the manifest embedded in the Windows Resource
1488  set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1489
1490  # We use crypto functions that are not available for UWP apps
1491  if(NOT WINDOWS_STORE)
1492    set(USE_WIN32_CRYPTO ON)
1493  endif()
1494
1495  # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL
1496  if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
1497    list(APPEND CURL_LIBS "advapi32" "crypt32")
1498  endif()
1499endif()
1500
1501if(MSVC)
1502  # Disable default manifest added by CMake
1503  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1504
1505  add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1506  if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1507    string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1508  else()
1509    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1510  endif()
1511
1512  # Use multithreaded compilation on VS 2008+
1513  if(MSVC_VERSION GREATER_EQUAL 1500)
1514    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
1515  endif()
1516endif()
1517
1518if(CURL_WERROR)
1519  if(MSVC_VERSION)
1520    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1521  else()
1522    # this assumes clang or gcc style options
1523    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1524  endif()
1525endif()
1526
1527if(CURL_LTO)
1528  if(CMAKE_VERSION VERSION_LESS 3.9)
1529    message(FATAL_ERROR "Requested LTO but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
1530  endif()
1531
1532  cmake_policy(SET CMP0069 NEW)
1533
1534  include(CheckIPOSupported)
1535  check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT CURL_LTO_ERROR LANGUAGES C)
1536  if(CURL_HAS_LTO)
1537    message(STATUS "LTO supported and enabled")
1538  else()
1539    message(FATAL_ERROR "LTO was requested - but compiler doesn't support it\n${CURL_LTO_ERROR}")
1540  endif()
1541endif()
1542
1543
1544# Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1545function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
1546  file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1547  string(REPLACE "$(top_srcdir)"   "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1548  string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1549
1550  string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1551  string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1552  string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1553
1554  string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace $() with ${}
1555  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.
1556  file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1557  set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}")
1558endfunction()
1559
1560include(GNUInstallDirs)
1561
1562set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
1563set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
1564set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
1565set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
1566set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
1567
1568if(HAVE_MANUAL_TOOLS)
1569  add_subdirectory(docs)
1570endif()
1571
1572add_subdirectory(lib)
1573
1574if(BUILD_CURL_EXE)
1575  add_subdirectory(src)
1576endif()
1577
1578cmake_dependent_option(BUILD_TESTING "Build tests"
1579  ON "PERL_FOUND;NOT CURL_DISABLE_TESTS"
1580  OFF)
1581if(BUILD_TESTING)
1582  add_subdirectory(tests)
1583endif()
1584
1585if(NOT CURL_DISABLE_INSTALL)
1586
1587  install(FILES "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl"
1588          DESTINATION ${CMAKE_INSTALL_BINDIR}
1589          PERMISSIONS
1590            OWNER_READ OWNER_WRITE OWNER_EXECUTE
1591            GROUP_READ GROUP_EXECUTE
1592            WORLD_READ WORLD_EXECUTE)
1593
1594  # Helper to populate a list (_items) with a label when conditions (the remaining
1595  # args) are satisfied
1596  macro(_add_if label)
1597    # needs to be a macro to allow this indirection
1598    if(${ARGN})
1599      set(_items ${_items} "${label}")
1600    endif()
1601  endmacro()
1602
1603  # NTLM support requires crypto function adaptions from various SSL libs
1604  if(NOT (CURL_DISABLE_NTLM) AND
1605      (USE_OPENSSL OR USE_MBEDTLS OR USE_DARWINSSL OR USE_WIN32_CRYPTO OR USE_GNUTLS))
1606    set(use_curl_ntlm_core ON)
1607  endif()
1608
1609  # Clear list and try to detect available features
1610  set(_items)
1611  _add_if("SSL"           SSL_ENABLED)
1612  _add_if("IPv6"          ENABLE_IPV6)
1613  _add_if("UnixSockets"   USE_UNIX_SOCKETS)
1614  _add_if("libz"          HAVE_LIBZ)
1615  _add_if("brotli"        HAVE_BROTLI)
1616  _add_if("zstd"          HAVE_ZSTD)
1617  _add_if("AsynchDNS"     USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1618  _add_if("IDN"           HAVE_LIBIDN2 OR USE_WIN32_IDN OR USE_APPLE_IDN)
1619  _add_if("Largefile"     (SIZEOF_CURL_OFF_T GREATER 4) AND
1620                          ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
1621  _add_if("SSPI"          USE_WINDOWS_SSPI)
1622  _add_if("GSS-API"       HAVE_GSSAPI)
1623  _add_if("alt-svc"       NOT CURL_DISABLE_ALTSVC)
1624  _add_if("HSTS"          NOT CURL_DISABLE_HSTS)
1625  _add_if("SPNEGO"        NOT CURL_DISABLE_NEGOTIATE_AUTH AND
1626                          (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1627  _add_if("Kerberos"      NOT CURL_DISABLE_KERBEROS_AUTH AND
1628                          (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1629  _add_if("NTLM"          NOT (CURL_DISABLE_NTLM) AND
1630                          (use_curl_ntlm_core OR USE_WINDOWS_SSPI))
1631  _add_if("TLS-SRP"       USE_TLS_SRP)
1632  _add_if("HTTP2"         USE_NGHTTP2)
1633  _add_if("HTTP3"         USE_NGTCP2 OR USE_QUICHE OR USE_OPENSSL_QUIC)
1634  _add_if("MultiSSL"      CURL_WITH_MULTI_SSL)
1635  # TODO wolfSSL only support this from v5.0.0 onwards
1636  _add_if("HTTPS-proxy"   SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS
1637                          OR USE_SCHANNEL OR USE_RUSTLS OR USE_BEARSSL OR
1638                          USE_MBEDTLS OR USE_SECTRANSP))
1639  _add_if("unicode"       ENABLE_UNICODE)
1640  _add_if("threadsafe"    HAVE_ATOMIC OR
1641                          (USE_THREADS_POSIX AND HAVE_PTHREAD_H) OR
1642                          (WIN32 AND HAVE_WIN32_WINNT GREATER_EQUAL 0x600))
1643  _add_if("PSL"           USE_LIBPSL)
1644  string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1645  message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1646
1647  # Clear list and try to detect available protocols
1648  set(_items)
1649  _add_if("HTTP"          NOT CURL_DISABLE_HTTP)
1650  _add_if("IPFS"          NOT CURL_DISABLE_HTTP)
1651  _add_if("IPNS"          NOT CURL_DISABLE_HTTP)
1652  _add_if("HTTPS"         NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1653  _add_if("ECH"           HAVE_ECH)
1654  _add_if("HTTPSRR"       HAVE_ECH)
1655  _add_if("FTP"           NOT CURL_DISABLE_FTP)
1656  _add_if("FTPS"          NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1657  _add_if("FILE"          NOT CURL_DISABLE_FILE)
1658  _add_if("TELNET"        NOT CURL_DISABLE_TELNET)
1659  _add_if("LDAP"          NOT CURL_DISABLE_LDAP)
1660  # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1661  _add_if("LDAPS"         NOT CURL_DISABLE_LDAPS AND
1662                          ((USE_OPENLDAP AND SSL_ENABLED) OR
1663                          (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1664  _add_if("DICT"          NOT CURL_DISABLE_DICT)
1665  _add_if("TFTP"          NOT CURL_DISABLE_TFTP)
1666  _add_if("GOPHER"        NOT CURL_DISABLE_GOPHER)
1667  _add_if("GOPHERS"       NOT CURL_DISABLE_GOPHER AND SSL_ENABLED)
1668  _add_if("POP3"          NOT CURL_DISABLE_POP3)
1669  _add_if("POP3S"         NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1670  _add_if("IMAP"          NOT CURL_DISABLE_IMAP)
1671  _add_if("IMAPS"         NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1672  _add_if("SMB"           NOT CURL_DISABLE_SMB AND
1673                          use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
1674  _add_if("SMBS"          NOT CURL_DISABLE_SMB AND SSL_ENABLED AND
1675                          use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
1676  _add_if("SMTP"          NOT CURL_DISABLE_SMTP)
1677  _add_if("SMTPS"         NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1678  _add_if("SCP"           USE_LIBSSH2 OR USE_LIBSSH)
1679  _add_if("SFTP"          USE_LIBSSH2 OR USE_LIBSSH)
1680  _add_if("RTSP"          NOT CURL_DISABLE_RTSP)
1681  _add_if("RTMP"          USE_LIBRTMP)
1682  _add_if("MQTT"          NOT CURL_DISABLE_MQTT)
1683  _add_if("WS"            USE_WEBSOCKETS)
1684  _add_if("WSS"           USE_WEBSOCKETS)
1685  if(_items)
1686    list(SORT _items)
1687  endif()
1688  string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1689  message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1690
1691  # Clear list and collect SSL backends
1692  set(_items)
1693  _add_if("Schannel"         SSL_ENABLED AND USE_SCHANNEL)
1694  _add_if("OpenSSL"          SSL_ENABLED AND USE_OPENSSL)
1695  _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
1696  _add_if("mbedTLS"          SSL_ENABLED AND USE_MBEDTLS)
1697  _add_if("BearSSL"          SSL_ENABLED AND USE_BEARSSL)
1698  _add_if("wolfSSL"          SSL_ENABLED AND USE_WOLFSSL)
1699  _add_if("GnuTLS"           SSL_ENABLED AND USE_GNUTLS)
1700
1701  if(_items)
1702    list(SORT _items)
1703  endif()
1704  string(REPLACE ";" " " SSL_BACKENDS "${_items}")
1705  message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
1706  if(CURL_DEFAULT_SSL_BACKEND)
1707    message(STATUS "Default SSL backend: ${CURL_DEFAULT_SSL_BACKEND}")
1708  endif()
1709
1710  # curl-config needs the following options to be set.
1711  set(CC                      "${CMAKE_C_COMPILER}")
1712  # TODO probably put a -D... options here?
1713  set(CONFIGURE_OPTIONS       "")
1714  set(CURLVERSION             "${CURL_VERSION}")
1715  set(exec_prefix             "\${prefix}")
1716  set(includedir              "\${prefix}/include")
1717  set(LDFLAGS                 "${CMAKE_SHARED_LINKER_FLAGS}")
1718  set(LIBCURL_LIBS            "")
1719  set(libdir                  "${CMAKE_INSTALL_PREFIX}/lib")
1720
1721  # For processing full path libraries into -L and -l ld options,
1722  # the directories that go with the -L option are cached, so they
1723  # only get added once per such directory.
1724  set(_libcurl_libs_dirs)
1725  # To avoid getting unnecessary -L options for known system directories,
1726  # _libcurl_libs_dirs is seeded with them.
1727  foreach(_libdir ${CMAKE_SYSTEM_PREFIX_PATH})
1728    if(_libdir MATCHES "/$")
1729      set(_libdir "${_libdir}lib")
1730    else()
1731      set(_libdir "${_libdir}/lib")
1732    endif()
1733    if(IS_DIRECTORY "${_libdir}")
1734      list(APPEND _libcurl_libs_dirs "${_libdir}")
1735    endif()
1736    if(DEFINED CMAKE_LIBRARY_ARCHITECTURE)
1737      set(_libdir "${_libdir}/${CMAKE_LIBRARY_ARCHITECTURE}")
1738      if(IS_DIRECTORY "${_libdir}")
1739        list(APPEND _libcurl_libs_dirs "${_libdir}")
1740      endif()
1741    endif()
1742  endforeach()
1743
1744  foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
1745    if(TARGET "${_lib}")
1746      set(_libname "${_lib}")
1747      get_target_property(_imported "${_libname}" IMPORTED)
1748      if(NOT _imported)
1749        # Reading the LOCATION property on non-imported target will error out.
1750        # Assume the user won't need this information in the .pc file.
1751        continue()
1752      endif()
1753      get_target_property(_lib "${_libname}" LOCATION)
1754      if(NOT _lib)
1755        message(WARNING "Bad lib in library list: ${_libname}")
1756        continue()
1757      endif()
1758    endif()
1759    if(_lib MATCHES "^-")
1760      set(LIBCURL_LIBS          "${LIBCURL_LIBS} ${_lib}")
1761    elseif(_lib MATCHES ".*/.*")
1762      # This gets a bit more complex, because we want to specify the
1763      # directory separately, and only once per directory
1764      string(REGEX REPLACE "^(.*)/[^/]*$" "\\1" _libdir "${_lib}")
1765      string(REGEX REPLACE "^.*/([^/.]*).*$" "\\1" _libname "${_lib}")
1766      if(_libname MATCHES "^lib")
1767        list(FIND _libcurl_libs_dirs "${_libdir}" _libdir_index)
1768        if(_libdir_index LESS 0)
1769          list(APPEND _libcurl_libs_dirs "${_libdir}")
1770          set(LIBCURL_LIBS          "${LIBCURL_LIBS} -L${_libdir}")
1771        endif()
1772        string(REGEX REPLACE "^lib" "" _libname "${_libname}")
1773        set(LIBCURL_LIBS          "${LIBCURL_LIBS} -l${_libname}")
1774      else()
1775        set(LIBCURL_LIBS          "${LIBCURL_LIBS} ${_lib}")
1776      endif()
1777    else()
1778      set(LIBCURL_LIBS          "${LIBCURL_LIBS} -l${_lib}")
1779    endif()
1780  endforeach()
1781  if(BUILD_SHARED_LIBS)
1782    set(ENABLE_SHARED         "yes")
1783    set(LIBCURL_NO_SHARED     "")
1784    set(CPPFLAG_CURL_STATICLIB "")
1785  else()
1786    set(ENABLE_SHARED         "no")
1787    set(LIBCURL_NO_SHARED     "${LIBCURL_LIBS}")
1788    set(CPPFLAG_CURL_STATICLIB "-DCURL_STATICLIB")
1789  endif()
1790  if(BUILD_STATIC_LIBS)
1791    set(ENABLE_STATIC         "yes")
1792  else()
1793    set(ENABLE_STATIC         "no")
1794  endif()
1795  # "a" (Linux) or "lib" (Windows)
1796  string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1797  set(prefix                  "${CMAKE_INSTALL_PREFIX}")
1798  # Set this to "yes" to append all libraries on which -lcurl is dependent
1799  set(REQUIRE_LIB_DEPS        "no")
1800  # SUPPORT_FEATURES
1801  # SUPPORT_PROTOCOLS
1802  set(VERSIONNUM              "${CURL_VERSION_NUM}")
1803
1804  # Finally generate a "curl-config" matching this config
1805  # Use:
1806  # * ENABLE_SHARED
1807  # * ENABLE_STATIC
1808  configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1809                "${CURL_BINARY_DIR}/curl-config" @ONLY)
1810  install(FILES "${CURL_BINARY_DIR}/curl-config"
1811          DESTINATION ${CMAKE_INSTALL_BINDIR}
1812          PERMISSIONS
1813            OWNER_READ OWNER_WRITE OWNER_EXECUTE
1814            GROUP_READ GROUP_EXECUTE
1815            WORLD_READ WORLD_EXECUTE)
1816
1817  # Finally generate a pkg-config file matching this config
1818  configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1819                "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
1820  install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
1821          DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1822
1823  # install headers
1824  install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1825      DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1826      FILES_MATCHING PATTERN "*.h")
1827
1828  include(CMakePackageConfigHelpers)
1829  write_basic_package_version_file(
1830      "${version_config}"
1831      VERSION ${CURL_VERSION}
1832      COMPATIBILITY SameMajorVersion
1833  )
1834  file(READ "${version_config}" generated_version_config)
1835  file(WRITE "${version_config}"
1836  "if(NOT PACKAGE_FIND_VERSION_RANGE AND PACKAGE_FIND_VERSION_MAJOR STREQUAL \"7\")
1837      # Version 8 satisfies version 7... requirements
1838      set(PACKAGE_FIND_VERSION_MAJOR 8)
1839      set(PACKAGE_FIND_VERSION_COUNT 1)
1840  endif()
1841  ${generated_version_config}"
1842  )
1843
1844  # Use:
1845  # * TARGETS_EXPORT_NAME
1846  # * PROJECT_NAME
1847  configure_package_config_file(CMake/curl-config.cmake.in
1848          "${project_config}"
1849          INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1850  )
1851
1852  if(CURL_ENABLE_EXPORT_TARGET)
1853    install(
1854            EXPORT "${TARGETS_EXPORT_NAME}"
1855            NAMESPACE "${PROJECT_NAME}::"
1856            DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1857    )
1858  endif()
1859
1860  install(
1861          FILES ${version_config} ${project_config}
1862          DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1863  )
1864
1865  # Workaround for MSVS10 to avoid the Dialog Hell
1866  # FIXME: This could be removed with future version of CMake.
1867  if(MSVC_VERSION EQUAL 1600)
1868    set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1869    if(EXISTS "${CURL_SLN_FILENAME}")
1870      file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1871    endif()
1872  endif()
1873
1874  if(NOT TARGET curl_uninstall)
1875    configure_file(
1876        ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1877        ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1878        IMMEDIATE @ONLY)
1879
1880    add_custom_target(curl_uninstall
1881        COMMAND ${CMAKE_COMMAND} -P
1882        ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
1883  endif()
1884endif()
1885