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