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