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