comparison mupdf-source/thirdparty/curl/CMakeLists.txt @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 #***************************************************************************
2 # _ _ ____ _
3 # Project ___| | | | _ \| |
4 # / __| | | | |_) | |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at https://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 ###########################################################################
22 # curl/libcurl CMake script
23 # by Tetetest and Sukender (Benoit Neil)
24
25 # TODO:
26 # The output .so file lacks the soname number which we currently have within the lib/Makefile.am file
27 # Add full (4 or 5 libs) SSL support
28 # Add INSTALL target (EXTRA_DIST variables in Makefile.am may be moved to Makefile.inc so that CMake/CPack is aware of what's to include).
29 # Add CTests(?)
30 # Check on all possible platforms
31 # Test with as many configurations possible (With or without any option)
32 # Create scripts that help keeping the CMake build system up to date (to reduce maintenance). According to Tetetest:
33 # - lists of headers that 'configure' checks for;
34 # - curl-specific tests (the ones that are in m4/curl-*.m4 files);
35 # - (most obvious thing:) curl version numbers.
36 # Add documentation subproject
37 #
38 # To check:
39 # (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
40 # (From Daniel Stenberg) The gcc command line use neither -g nor any -O options. As a developer, I also treasure our configure scripts's --enable-debug option that sets a long range of "picky" compiler options.
41 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
42 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
43 include(Utilities)
44 include(Macros)
45 include(CMakeDependentOption)
46 include(CheckCCompilerFlag)
47
48 project(CURL C)
49
50 message(WARNING "the curl cmake build system is poorly maintained. Be aware")
51
52 file(READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
53 string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
54 CURL_VERSION ${CURL_VERSION_H_CONTENTS})
55 string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
56 string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
57 CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
58 string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
59
60
61 # Setup package meta-data
62 # SET(PACKAGE "curl")
63 message(STATUS "curl version=[${CURL_VERSION}]")
64 # SET(PACKAGE_TARNAME "curl")
65 # SET(PACKAGE_NAME "curl")
66 # SET(PACKAGE_VERSION "-")
67 # SET(PACKAGE_STRING "curl-")
68 # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/")
69 set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
70 set(OS "\"${CMAKE_SYSTEM_NAME}\"")
71
72 include_directories(${CURL_SOURCE_DIR}/include)
73
74 option(CURL_WERROR "Turn compiler warnings into errors" OFF)
75 option(PICKY_COMPILER "Enable picky compiler options" ON)
76 option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
77 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
78 option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
79 if(WIN32)
80 option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
81 option(ENABLE_INET_PTON "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." ON)
82 endif()
83
84 cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
85 ON "NOT ENABLE_ARES"
86 OFF)
87
88 option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
89 option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
90
91 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
92 if(PICKY_COMPILER)
93 foreach(_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wundef -Wno-format-nonliteral -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wno-sign-conversion -Wvla -Wdouble-promotion -Wno-system-headers -Wno-pedantic-ms-format)
94 # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
95 # test result in.
96 check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
97 if(OPT${_CCOPT})
98 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
99 endif()
100 endforeach()
101 endif()
102 endif()
103
104 if(ENABLE_DEBUG)
105 # DEBUGBUILD will be defined only for Debug builds
106 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
107 set(ENABLE_CURLDEBUG ON)
108 endif()
109
110 if(ENABLE_CURLDEBUG)
111 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
112 endif()
113
114 # For debug libs and exes, add "-d" postfix
115 if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
116 set(CMAKE_DEBUG_POSTFIX "-d")
117 endif()
118
119 # initialize CURL_LIBS
120 set(CURL_LIBS "")
121
122 if(ENABLE_ARES)
123 set(USE_ARES 1)
124 find_package(CARES REQUIRED)
125 list(APPEND CURL_LIBS ${CARES_LIBRARY})
126 set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
127 endif()
128
129 include(CurlSymbolHiding)
130
131 option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
132 mark_as_advanced(HTTP_ONLY)
133 option(CURL_DISABLE_FTP "disables FTP" OFF)
134 mark_as_advanced(CURL_DISABLE_FTP)
135 option(CURL_DISABLE_LDAP "disables LDAP" OFF)
136 mark_as_advanced(CURL_DISABLE_LDAP)
137 option(CURL_DISABLE_TELNET "disables Telnet" OFF)
138 mark_as_advanced(CURL_DISABLE_TELNET)
139 option(CURL_DISABLE_DICT "disables DICT" OFF)
140 mark_as_advanced(CURL_DISABLE_DICT)
141 option(CURL_DISABLE_FILE "disables FILE" OFF)
142 mark_as_advanced(CURL_DISABLE_FILE)
143 option(CURL_DISABLE_TFTP "disables TFTP" OFF)
144 mark_as_advanced(CURL_DISABLE_TFTP)
145 option(CURL_DISABLE_HTTP "disables HTTP" OFF)
146 mark_as_advanced(CURL_DISABLE_HTTP)
147
148 option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
149 mark_as_advanced(CURL_DISABLE_LDAPS)
150
151 option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
152 mark_as_advanced(CURL_DISABLE_RTSP)
153 option(CURL_DISABLE_PROXY "to disable proxy" OFF)
154 mark_as_advanced(CURL_DISABLE_PROXY)
155 option(CURL_DISABLE_POP3 "to disable POP3" OFF)
156 mark_as_advanced(CURL_DISABLE_POP3)
157 option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
158 mark_as_advanced(CURL_DISABLE_IMAP)
159 option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
160 mark_as_advanced(CURL_DISABLE_SMTP)
161 option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
162 mark_as_advanced(CURL_DISABLE_GOPHER)
163
164 if(HTTP_ONLY)
165 set(CURL_DISABLE_FTP ON)
166 set(CURL_DISABLE_LDAP ON)
167 set(CURL_DISABLE_LDAPS ON)
168 set(CURL_DISABLE_TELNET ON)
169 set(CURL_DISABLE_DICT ON)
170 set(CURL_DISABLE_FILE ON)
171 set(CURL_DISABLE_TFTP ON)
172 set(CURL_DISABLE_RTSP ON)
173 set(CURL_DISABLE_POP3 ON)
174 set(CURL_DISABLE_IMAP ON)
175 set(CURL_DISABLE_SMTP ON)
176 set(CURL_DISABLE_GOPHER ON)
177 endif()
178
179 option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
180 mark_as_advanced(CURL_DISABLE_COOKIES)
181
182 option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
183 mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
184 option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
185 mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
186 option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
187 mark_as_advanced(ENABLE_IPV6)
188 if(ENABLE_IPV6 AND NOT WIN32)
189 include(CheckStructHasMember)
190 check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
191 HAVE_SOCKADDR_IN6_SIN6_ADDR)
192 check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
193 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
194 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
195 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
196 # Force the feature off as this name is used as guard macro...
197 set(ENABLE_IPV6 OFF
198 CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
199 endif()
200 endif()
201
202 curl_nroff_check()
203 find_package(Perl)
204
205 cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
206 ON "NROFF_USEFUL;PERL_FOUND"
207 OFF)
208
209 if(NOT PERL_FOUND)
210 message(STATUS "Perl not found, testing disabled.")
211 set(BUILD_TESTING OFF)
212 endif()
213 if(ENABLE_MANUAL)
214 set(USE_MANUAL ON)
215 endif()
216
217 # We need ansi c-flags, especially on HP
218 set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
219 set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
220
221 if(CURL_STATIC_CRT)
222 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
223 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
224 endif()
225
226 # Disable warnings on Borland to avoid changing 3rd party code.
227 if(BORLAND)
228 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
229 endif()
230
231 # If we are on AIX, do the _ALL_SOURCE magic
232 if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
233 set(_ALL_SOURCE 1)
234 endif()
235
236 # Include all the necessary files for macros
237 include(CheckFunctionExists)
238 include(CheckIncludeFile)
239 include(CheckIncludeFiles)
240 include(CheckLibraryExists)
241 include(CheckSymbolExists)
242 include(CheckTypeSize)
243 include(CheckCSourceCompiles)
244
245 # On windows preload settings
246 if(WIN32)
247 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
248 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
249 endif()
250
251 if(ENABLE_THREADED_RESOLVER)
252 find_package(Threads REQUIRED)
253 if(WIN32)
254 set(USE_THREADS_WIN32 ON)
255 else()
256 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
257 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
258 endif()
259 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
260 endif()
261
262 # Check for all needed libraries
263 check_library_exists_concat("${CMAKE_DL_LIBS}" dlopen HAVE_LIBDL)
264 check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
265 check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
266
267 # Yellowtab Zeta needs different libraries than BeOS 5.
268 if(BEOS)
269 set(NOT_NEED_LIBNSL 1)
270 check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
271 check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
272 endif()
273
274 if(NOT NOT_NEED_LIBNSL)
275 check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
276 endif()
277
278 check_function_exists(gethostname HAVE_GETHOSTNAME)
279
280 if(WIN32)
281 check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
282 check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
283 list(APPEND CURL_LIBS "advapi32")
284 endif()
285
286 # check SSL libraries
287 # TODO support GNUTLS, NSS, POLARSSL, CYASSL
288
289 if(APPLE)
290 option(CMAKE_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF)
291 endif()
292 if(WIN32)
293 option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
294 cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
295 CMAKE_USE_WINSSL OFF)
296 endif()
297 option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
298
299 set(openssl_default ON)
300 if(WIN32 OR CMAKE_USE_SECTRANSP OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
301 set(openssl_default OFF)
302 endif()
303 option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default})
304
305 count_true(enabled_ssl_options_count
306 CMAKE_USE_WINSSL
307 CMAKE_USE_SECTRANSP
308 CMAKE_USE_OPENSSL
309 CMAKE_USE_MBEDTLS
310 )
311 if(enabled_ssl_options_count GREATER "1")
312 set(CURL_WITH_MULTI_SSL ON)
313 endif()
314
315 if(CMAKE_USE_WINSSL)
316 set(SSL_ENABLED ON)
317 set(USE_SCHANNEL ON) # Windows native SSL/TLS support
318 set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
319 list(APPEND CURL_LIBS "crypt32")
320 endif()
321 if(CURL_WINDOWS_SSPI)
322 set(USE_WINDOWS_SSPI ON)
323 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
324 endif()
325
326 if(CMAKE_USE_DARWINSSL)
327 message(FATAL_ERROR "The cmake option CMAKE_USE_DARWINSSL was renamed to CMAKE_USE_SECTRANSP.")
328 endif()
329
330 if(CMAKE_USE_SECTRANSP)
331 find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
332 if(NOT COREFOUNDATION_FRAMEWORK)
333 message(FATAL_ERROR "CoreFoundation framework not found")
334 endif()
335
336 find_library(SECURITY_FRAMEWORK "Security")
337 if(NOT SECURITY_FRAMEWORK)
338 message(FATAL_ERROR "Security framework not found")
339 endif()
340
341 set(SSL_ENABLED ON)
342 set(USE_SECTRANSP ON)
343 list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
344 endif()
345
346 if(CMAKE_USE_OPENSSL)
347 find_package(OpenSSL REQUIRED)
348 set(SSL_ENABLED ON)
349 set(USE_OPENSSL ON)
350 set(HAVE_LIBCRYPTO ON)
351 set(HAVE_LIBSSL ON)
352
353 # Depend on OpenSSL via imported targets if supported by the running
354 # version of CMake. This allows our dependents to get our dependencies
355 # transitively.
356 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
357 list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
358 else()
359 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
360 include_directories(${OPENSSL_INCLUDE_DIR})
361 endif()
362
363 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
364 check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
365 check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
366 check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
367 check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
368 check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
369 check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
370 check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
371 check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
372 check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
373 check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
374 endif()
375
376 if(CMAKE_USE_MBEDTLS)
377 find_package(MbedTLS REQUIRED)
378 set(SSL_ENABLED ON)
379 set(USE_MBEDTLS ON)
380 list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
381 include_directories(${MBEDTLS_INCLUDE_DIRS})
382 endif()
383
384 option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
385 if(USE_NGHTTP2)
386 find_package(NGHTTP2 REQUIRED)
387 include_directories(${NGHTTP2_INCLUDE_DIRS})
388 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
389 endif()
390
391 if(NOT CURL_DISABLE_LDAP)
392 if(WIN32)
393 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
394 if(USE_WIN32_LDAP)
395 check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
396 if(NOT HAVE_WLDAP32)
397 set(USE_WIN32_LDAP OFF)
398 endif()
399 endif()
400 endif()
401
402 option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
403 mark_as_advanced(CMAKE_USE_OPENLDAP)
404 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
405 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
406
407 if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
408 message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
409 endif()
410
411 # Now that we know, we're not using windows LDAP...
412 if(USE_WIN32_LDAP)
413 check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
414 check_include_file_concat("winber.h" HAVE_WINBER_H)
415 else()
416 # Check for LDAP
417 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
418 check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
419 check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
420
421 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
422 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
423 if(CMAKE_LDAP_INCLUDE_DIR)
424 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
425 endif()
426 check_include_file_concat("ldap.h" HAVE_LDAP_H)
427 check_include_file_concat("lber.h" HAVE_LBER_H)
428
429 if(NOT HAVE_LDAP_H)
430 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
431 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
432 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
433 elseif(NOT HAVE_LIBLDAP)
434 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
435 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
436 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
437 else()
438 if(CMAKE_USE_OPENLDAP)
439 set(USE_OPENLDAP ON)
440 endif()
441 if(CMAKE_LDAP_INCLUDE_DIR)
442 include_directories(${CMAKE_LDAP_INCLUDE_DIR})
443 endif()
444 set(NEED_LBER_H ON)
445 set(_HEADER_LIST)
446 if(HAVE_WINDOWS_H)
447 list(APPEND _HEADER_LIST "windows.h")
448 endif()
449 if(HAVE_SYS_TYPES_H)
450 list(APPEND _HEADER_LIST "sys/types.h")
451 endif()
452 list(APPEND _HEADER_LIST "ldap.h")
453
454 set(_SRC_STRING "")
455 foreach(_HEADER ${_HEADER_LIST})
456 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
457 endforeach()
458
459 set(_SRC_STRING
460 "
461 ${_INCLUDE_STRING}
462 int main(int argc, char ** argv)
463 {
464 BerValue *bvp = NULL;
465 BerElement *bep = ber_init(bvp);
466 ber_free(bep, 1);
467 return 0;
468 }"
469 )
470 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
471 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
472 if(HAVE_LIBLBER)
473 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
474 endif()
475 check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
476 unset(CMAKE_REQUIRED_LIBRARIES)
477
478 if(NOT_NEED_LBER_H)
479 set(NEED_LBER_H OFF)
480 else()
481 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
482 endif()
483 endif()
484 endif()
485 endif()
486
487 # No ldap, no ldaps.
488 if(CURL_DISABLE_LDAP)
489 if(NOT CURL_DISABLE_LDAPS)
490 message(STATUS "LDAP needs to be enabled to support LDAPS")
491 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
492 endif()
493 endif()
494
495 if(NOT CURL_DISABLE_LDAPS)
496 check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
497 check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
498 endif()
499
500 # Check for idn
501 check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
502
503 # Check for symbol dlopen (same as HAVE_LIBDL)
504 check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
505
506 option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
507 set(HAVE_LIBZ OFF)
508 set(HAVE_ZLIB_H OFF)
509 set(USE_ZLIB OFF)
510 if(CURL_ZLIB)
511 find_package(ZLIB QUIET)
512 if(ZLIB_FOUND)
513 set(HAVE_ZLIB_H ON)
514 set(HAVE_LIBZ ON)
515 set(USE_ZLIB ON)
516
517 # Depend on ZLIB via imported targets if supported by the running
518 # version of CMake. This allows our dependents to get our dependencies
519 # transitively.
520 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
521 list(APPEND CURL_LIBS ZLIB::ZLIB)
522 else()
523 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
524 include_directories(${ZLIB_INCLUDE_DIRS})
525 endif()
526 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
527 endif()
528 endif()
529
530 option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
531 set(HAVE_BROTLI OFF)
532 if(CURL_BROTLI)
533 find_package(Brotli QUIET)
534 if(BROTLI_FOUND)
535 set(HAVE_BROTLI ON)
536 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
537 include_directories(${BROTLI_INCLUDE_DIRS})
538 list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
539 endif()
540 endif()
541
542 #libSSH2
543 option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
544 mark_as_advanced(CMAKE_USE_LIBSSH2)
545 set(USE_LIBSSH2 OFF)
546 set(HAVE_LIBSSH2 OFF)
547 set(HAVE_LIBSSH2_H OFF)
548
549 if(CMAKE_USE_LIBSSH2)
550 find_package(LibSSH2)
551 if(LIBSSH2_FOUND)
552 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
553 set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
554 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
555 include_directories("${LIBSSH2_INCLUDE_DIR}")
556 set(HAVE_LIBSSH2 ON)
557 set(USE_LIBSSH2 ON)
558
559 # find_package has already found the headers
560 set(HAVE_LIBSSH2_H ON)
561 set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
562 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
563
564 # now check for specific libssh2 symbols as they were added in different versions
565 set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
566 check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
567 check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
568 check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
569 check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
570 check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
571 set(CMAKE_EXTRA_INCLUDE_FILES "")
572 unset(CMAKE_REQUIRED_LIBRARIES)
573 endif()
574 endif()
575
576 option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
577 mark_as_advanced(CMAKE_USE_GSSAPI)
578
579 if(CMAKE_USE_GSSAPI)
580 find_package(GSS)
581
582 set(HAVE_GSSAPI ${GSS_FOUND})
583 if(GSS_FOUND)
584
585 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
586
587 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
588 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
589 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
590 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
591
592 if(GSS_FLAVOUR STREQUAL "Heimdal")
593 set(HAVE_GSSHEIMDAL ON)
594 else() # MIT
595 set(HAVE_GSSMIT ON)
596 set(_INCLUDE_LIST "")
597 if(HAVE_GSSAPI_GSSAPI_H)
598 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
599 endif()
600 if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
601 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
602 endif()
603 if(HAVE_GSSAPI_GSSAPI_KRB5_H)
604 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
605 endif()
606
607 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
608 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
609
610 foreach(_dir ${GSS_LINK_DIRECTORIES})
611 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
612 endforeach()
613
614 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
615 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
616 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
617 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
618 set(HAVE_OLD_GSSMIT ON)
619 endif()
620 unset(CMAKE_REQUIRED_LIBRARIES)
621
622 endif()
623
624 include_directories(${GSS_INCLUDE_DIR})
625 link_directories(${GSS_LINK_DIRECTORIES})
626 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
627 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
628 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
629 list(APPEND CURL_LIBS ${GSS_LIBRARIES})
630
631 else()
632 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
633 endif()
634 endif()
635
636 option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
637 if(ENABLE_UNIX_SOCKETS)
638 include(CheckStructHasMember)
639 check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
640 else()
641 unset(USE_UNIX_SOCKETS CACHE)
642 endif()
643
644 #
645 # CA handling
646 #
647 set(CURL_CA_BUNDLE "auto" CACHE STRING
648 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
649 set(CURL_CA_FALLBACK OFF CACHE BOOL
650 "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
651 set(CURL_CA_PATH "auto" CACHE STRING
652 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
653
654 if("${CURL_CA_BUNDLE}" STREQUAL "")
655 message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
656 elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
657 unset(CURL_CA_BUNDLE CACHE)
658 elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
659 unset(CURL_CA_BUNDLE CACHE)
660 set(CURL_CA_BUNDLE_AUTODETECT TRUE)
661 else()
662 set(CURL_CA_BUNDLE_SET TRUE)
663 endif()
664
665 if("${CURL_CA_PATH}" STREQUAL "")
666 message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
667 elseif("${CURL_CA_PATH}" STREQUAL "none")
668 unset(CURL_CA_PATH CACHE)
669 elseif("${CURL_CA_PATH}" STREQUAL "auto")
670 unset(CURL_CA_PATH CACHE)
671 set(CURL_CA_PATH_AUTODETECT TRUE)
672 else()
673 set(CURL_CA_PATH_SET TRUE)
674 endif()
675
676 if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
677 # Skip autodetection of unset CA path because CA bundle is set explicitly
678 elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
679 # Skip autodetection of unset CA bundle because CA path is set explicitly
680 elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
681 # first try autodetecting a CA bundle, then a CA path
682
683 if(CURL_CA_BUNDLE_AUTODETECT)
684 set(SEARCH_CA_BUNDLE_PATHS
685 /etc/ssl/certs/ca-certificates.crt
686 /etc/pki/tls/certs/ca-bundle.crt
687 /usr/share/ssl/certs/ca-bundle.crt
688 /usr/local/share/certs/ca-root-nss.crt
689 /etc/ssl/cert.pem)
690
691 foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
692 if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
693 message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
694 set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
695 set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
696 break()
697 endif()
698 endforeach()
699 endif()
700
701 if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
702 if(EXISTS "/etc/ssl/certs")
703 set(CURL_CA_PATH "/etc/ssl/certs")
704 set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
705 endif()
706 endif()
707 endif()
708
709 if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
710 message(FATAL_ERROR
711 "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
712 "Set CURL_CA_PATH=none or enable one of those TLS backends.")
713 endif()
714
715 # Check for header files
716 if(NOT UNIX)
717 check_include_file_concat("windows.h" HAVE_WINDOWS_H)
718 check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
719 check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
720 check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
721 if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL)
722 set(CURL_LIBS ${CURL_LIBS} "crypt32")
723 endif()
724 endif()
725
726 check_include_file_concat("stdio.h" HAVE_STDIO_H)
727 check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
728 check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
729 check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
730 check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
731 check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
732 check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
733 check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
734 check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
735 check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
736 check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
737 check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
738 check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
739 check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
740 check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
741 check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
742 check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
743 check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
744 check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
745 check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
746 check_include_file_concat("assert.h" HAVE_ASSERT_H)
747 check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
748 check_include_file_concat("des.h" HAVE_DES_H)
749 check_include_file_concat("err.h" HAVE_ERR_H)
750 check_include_file_concat("errno.h" HAVE_ERRNO_H)
751 check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
752 check_include_file_concat("idn2.h" HAVE_IDN2_H)
753 check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
754 check_include_file_concat("io.h" HAVE_IO_H)
755 check_include_file_concat("krb.h" HAVE_KRB_H)
756 check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
757 check_include_file_concat("locale.h" HAVE_LOCALE_H)
758 check_include_file_concat("net/if.h" HAVE_NET_IF_H)
759 check_include_file_concat("netdb.h" HAVE_NETDB_H)
760 check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
761 check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
762
763 check_include_file_concat("pem.h" HAVE_PEM_H)
764 check_include_file_concat("poll.h" HAVE_POLL_H)
765 check_include_file_concat("pwd.h" HAVE_PWD_H)
766 check_include_file_concat("rsa.h" HAVE_RSA_H)
767 check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
768 check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
769 check_include_file_concat("signal.h" HAVE_SIGNAL_H)
770 check_include_file_concat("ssl.h" HAVE_SSL_H)
771 check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
772 check_include_file_concat("stdint.h" HAVE_STDINT_H)
773 check_include_file_concat("stdio.h" HAVE_STDIO_H)
774 check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
775 check_include_file_concat("string.h" HAVE_STRING_H)
776 check_include_file_concat("strings.h" HAVE_STRINGS_H)
777 check_include_file_concat("stropts.h" HAVE_STROPTS_H)
778 check_include_file_concat("termio.h" HAVE_TERMIO_H)
779 check_include_file_concat("termios.h" HAVE_TERMIOS_H)
780 check_include_file_concat("time.h" HAVE_TIME_H)
781 check_include_file_concat("unistd.h" HAVE_UNISTD_H)
782 check_include_file_concat("utime.h" HAVE_UTIME_H)
783 check_include_file_concat("x509.h" HAVE_X509_H)
784
785 check_include_file_concat("process.h" HAVE_PROCESS_H)
786 check_include_file_concat("stddef.h" HAVE_STDDEF_H)
787 check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
788 check_include_file_concat("malloc.h" HAVE_MALLOC_H)
789 check_include_file_concat("memory.h" HAVE_MEMORY_H)
790 check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
791 check_include_file_concat("stdint.h" HAVE_STDINT_H)
792 check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
793 check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
794
795 check_type_size(size_t SIZEOF_SIZE_T)
796 check_type_size(ssize_t SIZEOF_SSIZE_T)
797 check_type_size("long long" SIZEOF_LONG_LONG)
798 check_type_size("long" SIZEOF_LONG)
799 check_type_size("short" SIZEOF_SHORT)
800 check_type_size("int" SIZEOF_INT)
801 check_type_size("__int64" SIZEOF___INT64)
802 check_type_size("long double" SIZEOF_LONG_DOUBLE)
803 check_type_size("time_t" SIZEOF_TIME_T)
804 if(NOT HAVE_SIZEOF_SSIZE_T)
805 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
806 set(ssize_t long)
807 endif()
808 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
809 set(ssize_t __int64)
810 endif()
811 endif()
812 # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
813
814 if(HAVE_SIZEOF_LONG_LONG)
815 set(HAVE_LONGLONG 1)
816 set(HAVE_LL 1)
817 endif()
818
819 find_file(RANDOM_FILE urandom /dev)
820 mark_as_advanced(RANDOM_FILE)
821
822 # Check for some functions that are used
823 if(HAVE_LIBWS2_32)
824 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
825 elseif(HAVE_LIBSOCKET)
826 set(CMAKE_REQUIRED_LIBRARIES socket)
827 endif()
828
829 check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
830 check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
831 check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
832 check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
833 check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
834 check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
835 check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
836 check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
837 check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
838 check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
839 check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
840 check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
841 check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
842 check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
843 if(NOT HAVE_STRNCMPI)
844 set(HAVE_STRCMPI)
845 endif()
846 check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
847 check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
848 check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
849 check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
850 check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
851 check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
852 check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
853 check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
854 check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
855 check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
856 check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
857 check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
858 check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
859 check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
860 check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
861 check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
862 check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
863 check_symbol_exists(usleep "${CURL_INCLUDES}" HAVE_USLEEP)
864 check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
865 check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
866 check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
867
868 check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
869 check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
870
871 check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
872 check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
873 if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
874 set(HAVE_SIGNAL 1)
875 endif()
876 check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
877 check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
878 check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
879 check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
880 check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
881 check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
882 check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
883 check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
884 check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
885 check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
886 check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
887 check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
888 check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
889 check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
890 check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
891 check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
892 check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
893 check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
894 check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
895 check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
896 check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
897 check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
898 check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
899 check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
900
901 # symbol exists in win32, but function does not.
902 if(WIN32)
903 if(ENABLE_INET_PTON)
904 check_function_exists(inet_pton HAVE_INET_PTON)
905 # _WIN32_WINNT_VISTA (0x0600)
906 add_definitions(-D_WIN32_WINNT=0x0600)
907 else()
908 # _WIN32_WINNT_WINXP (0x0501)
909 add_definitions(-D_WIN32_WINNT=0x0501)
910 endif()
911 else()
912 check_function_exists(inet_pton HAVE_INET_PTON)
913 endif()
914
915 check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
916 if(HAVE_FSETXATTR)
917 foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
918 curl_internal_test(${CURL_TEST})
919 endforeach()
920 endif()
921
922 # sigaction and sigsetjmp are special. Use special mechanism for
923 # detecting those, but only if previous attempt failed.
924 if(HAVE_SIGNAL_H)
925 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
926 endif()
927
928 if(NOT HAVE_SIGSETJMP)
929 if(HAVE_SETJMP_H)
930 check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
931 if(HAVE_MACRO_SIGSETJMP)
932 set(HAVE_SIGSETJMP 1)
933 endif()
934 endif()
935 endif()
936
937 # If there is no stricmp(), do not allow LDAP to parse URLs
938 if(NOT HAVE_STRICMP)
939 set(HAVE_LDAP_URL_PARSE 1)
940 endif()
941
942 # Do curl specific tests
943 foreach(CURL_TEST
944 HAVE_FCNTL_O_NONBLOCK
945 HAVE_IOCTLSOCKET
946 HAVE_IOCTLSOCKET_CAMEL
947 HAVE_IOCTLSOCKET_CAMEL_FIONBIO
948 HAVE_IOCTLSOCKET_FIONBIO
949 HAVE_IOCTL_FIONBIO
950 HAVE_IOCTL_SIOCGIFADDR
951 HAVE_SETSOCKOPT_SO_NONBLOCK
952 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
953 TIME_WITH_SYS_TIME
954 HAVE_O_NONBLOCK
955 HAVE_GETHOSTBYADDR_R_5
956 HAVE_GETHOSTBYADDR_R_7
957 HAVE_GETHOSTBYADDR_R_8
958 HAVE_GETHOSTBYADDR_R_5_REENTRANT
959 HAVE_GETHOSTBYADDR_R_7_REENTRANT
960 HAVE_GETHOSTBYADDR_R_8_REENTRANT
961 HAVE_GETHOSTBYNAME_R_3
962 HAVE_GETHOSTBYNAME_R_5
963 HAVE_GETHOSTBYNAME_R_6
964 HAVE_GETHOSTBYNAME_R_3_REENTRANT
965 HAVE_GETHOSTBYNAME_R_5_REENTRANT
966 HAVE_GETHOSTBYNAME_R_6_REENTRANT
967 HAVE_IN_ADDR_T
968 HAVE_BOOL_T
969 STDC_HEADERS
970 RETSIGTYPE_TEST
971 HAVE_INET_NTOA_R_DECL
972 HAVE_INET_NTOA_R_DECL_REENTRANT
973 HAVE_GETADDRINFO
974 HAVE_FILE_OFFSET_BITS
975 HAVE_VARIADIC_MACROS_C99
976 HAVE_VARIADIC_MACROS_GCC
977 )
978 curl_internal_test(${CURL_TEST})
979 endforeach()
980
981 if(HAVE_FILE_OFFSET_BITS)
982 set(_FILE_OFFSET_BITS 64)
983 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
984 endif()
985 check_type_size("off_t" SIZEOF_OFF_T)
986
987 # include this header to get the type
988 set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
989 set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
990 check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
991 set(CMAKE_EXTRA_INCLUDE_FILES "")
992
993 set(CMAKE_REQUIRED_FLAGS)
994
995 foreach(CURL_TEST
996 HAVE_GLIBC_STRERROR_R
997 HAVE_POSIX_STRERROR_R
998 )
999 curl_internal_test(${CURL_TEST})
1000 endforeach()
1001
1002 # Check for reentrant
1003 foreach(CURL_TEST
1004 HAVE_GETHOSTBYADDR_R_5
1005 HAVE_GETHOSTBYADDR_R_7
1006 HAVE_GETHOSTBYADDR_R_8
1007 HAVE_GETHOSTBYNAME_R_3
1008 HAVE_GETHOSTBYNAME_R_5
1009 HAVE_GETHOSTBYNAME_R_6
1010 HAVE_INET_NTOA_R_DECL_REENTRANT)
1011 if(NOT ${CURL_TEST})
1012 if(${CURL_TEST}_REENTRANT)
1013 set(NEED_REENTRANT 1)
1014 endif()
1015 endif()
1016 endforeach()
1017
1018 if(NEED_REENTRANT)
1019 foreach(CURL_TEST
1020 HAVE_GETHOSTBYADDR_R_5
1021 HAVE_GETHOSTBYADDR_R_7
1022 HAVE_GETHOSTBYADDR_R_8
1023 HAVE_GETHOSTBYNAME_R_3
1024 HAVE_GETHOSTBYNAME_R_5
1025 HAVE_GETHOSTBYNAME_R_6)
1026 set(${CURL_TEST} 0)
1027 if(${CURL_TEST}_REENTRANT)
1028 set(${CURL_TEST} 1)
1029 endif()
1030 endforeach()
1031 endif()
1032
1033 if(HAVE_INET_NTOA_R_DECL_REENTRANT)
1034 set(HAVE_INET_NTOA_R_DECL 1)
1035 set(NEED_REENTRANT 1)
1036 endif()
1037
1038 # Check clock_gettime(CLOCK_MONOTONIC, x) support
1039 curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
1040
1041 # Check compiler support of __builtin_available()
1042 curl_internal_test(HAVE_BUILTIN_AVAILABLE)
1043
1044 # Some other minor tests
1045
1046 if(NOT HAVE_IN_ADDR_T)
1047 set(in_addr_t "unsigned long")
1048 endif()
1049
1050 # Fix libz / zlib.h
1051
1052 if(NOT CURL_SPECIAL_LIBZ)
1053 if(NOT HAVE_LIBZ)
1054 set(HAVE_ZLIB_H 0)
1055 endif()
1056
1057 if(NOT HAVE_ZLIB_H)
1058 set(HAVE_LIBZ 0)
1059 endif()
1060 endif()
1061
1062 # Check for nonblocking
1063 set(HAVE_DISABLED_NONBLOCKING 1)
1064 if(HAVE_FIONBIO OR
1065 HAVE_IOCTLSOCKET OR
1066 HAVE_IOCTLSOCKET_CASE OR
1067 HAVE_O_NONBLOCK)
1068 set(HAVE_DISABLED_NONBLOCKING)
1069 endif()
1070
1071 if(RETSIGTYPE_TEST)
1072 set(RETSIGTYPE void)
1073 else()
1074 set(RETSIGTYPE int)
1075 endif()
1076
1077 if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1078 include(CheckCCompilerFlag)
1079 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1080 if(HAVE_C_FLAG_Wno_long_double)
1081 # The Mac version of GCC warns about use of long double. Disable it.
1082 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1083 if(MPRINTF_COMPILE_FLAGS)
1084 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1085 else()
1086 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1087 endif()
1088 set_source_files_properties(mprintf.c PROPERTIES
1089 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1090 endif()
1091 endif()
1092
1093 # TODO test which of these headers are required
1094 if(WIN32)
1095 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
1096 else()
1097 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
1098 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
1099 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
1100 endif()
1101 set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
1102 set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
1103
1104 include(CMake/OtherTests.cmake)
1105
1106 add_definitions(-DHAVE_CONFIG_H)
1107
1108 # For Windows, all compilers used by CMake should support large files
1109 if(WIN32)
1110 set(USE_WIN32_LARGE_FILES ON)
1111
1112 # Use the manifest embedded in the Windows Resource
1113 set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1114 endif()
1115
1116 if(MSVC)
1117 # Disable default manifest added by CMake
1118 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1119
1120 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1121 if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1122 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1123 else()
1124 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1125 endif()
1126 endif()
1127
1128 if(CURL_WERROR)
1129 if(MSVC_VERSION)
1130 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1131 else()
1132 # this assumes clang or gcc style options
1133 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1134 endif()
1135 endif()
1136
1137 # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1138 function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
1139 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1140 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1141 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1142
1143 string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1144 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1145 string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1146
1147 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
1148 string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace @@ with ${}, even if that may not be read by CMake scripts.
1149 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1150
1151 endfunction()
1152
1153 include(GNUInstallDirs)
1154
1155 set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
1156 set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
1157 set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
1158 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
1159 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
1160
1161 if(USE_MANUAL)
1162 add_subdirectory(docs)
1163 endif()
1164
1165 add_subdirectory(lib)
1166
1167 if(BUILD_CURL_EXE)
1168 add_subdirectory(src)
1169 endif()
1170
1171 include(CTest)
1172 if(BUILD_TESTING)
1173 add_subdirectory(tests)
1174 endif()
1175
1176 # Helper to populate a list (_items) with a label when conditions (the remaining
1177 # args) are satisfied
1178 function(_add_if label)
1179 # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
1180 if(${ARGN})
1181 set(_items ${_items} "${label}" PARENT_SCOPE)
1182 endif()
1183 endfunction()
1184
1185 # Clear list and try to detect available features
1186 set(_items)
1187 _add_if("SSL" SSL_ENABLED)
1188 _add_if("IPv6" ENABLE_IPV6)
1189 _add_if("unix-sockets" USE_UNIX_SOCKETS)
1190 _add_if("libz" HAVE_LIBZ)
1191 _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1192 _add_if("IDN" HAVE_LIBIDN2)
1193 _add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
1194 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
1195 # TODO SSP1 (WinSSL) check is missing
1196 _add_if("SSPI" USE_WINDOWS_SSPI)
1197 _add_if("GSS-API" HAVE_GSSAPI)
1198 # TODO SSP1 missing for SPNEGO
1199 _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
1200 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1201 _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
1202 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1203 # NTLM support requires crypto function adaptions from various SSL libs
1204 # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
1205 if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_SECTRANSP OR USE_MBEDTLS))
1206 _add_if("NTLM" 1)
1207 # TODO missing option (autoconf: --enable-ntlm-wb)
1208 _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
1209 endif()
1210 # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
1211 _add_if("TLS-SRP" USE_TLS_SRP)
1212 # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
1213 _add_if("HTTP2" USE_NGHTTP2)
1214 string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1215 message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1216
1217 # Clear list and try to detect available protocols
1218 set(_items)
1219 _add_if("HTTP" NOT CURL_DISABLE_HTTP)
1220 _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1221 _add_if("FTP" NOT CURL_DISABLE_FTP)
1222 _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1223 _add_if("FILE" NOT CURL_DISABLE_FILE)
1224 _add_if("TELNET" NOT CURL_DISABLE_TELNET)
1225 _add_if("LDAP" NOT CURL_DISABLE_LDAP)
1226 # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1227 # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
1228 _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
1229 ((USE_OPENLDAP AND SSL_ENABLED) OR
1230 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1231 _add_if("DICT" NOT CURL_DISABLE_DICT)
1232 _add_if("TFTP" NOT CURL_DISABLE_TFTP)
1233 _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
1234 _add_if("POP3" NOT CURL_DISABLE_POP3)
1235 _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1236 _add_if("IMAP" NOT CURL_DISABLE_IMAP)
1237 _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1238 _add_if("SMTP" NOT CURL_DISABLE_SMTP)
1239 _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1240 _add_if("SCP" USE_LIBSSH2)
1241 _add_if("SFTP" USE_LIBSSH2)
1242 _add_if("RTSP" NOT CURL_DISABLE_RTSP)
1243 _add_if("RTMP" USE_LIBRTMP)
1244 if(_items)
1245 list(SORT _items)
1246 endif()
1247 string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1248 message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1249
1250 # Clear list and collect SSL backends
1251 set(_items)
1252 _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
1253 _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
1254 _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
1255 _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
1256 if(_items)
1257 list(SORT _items)
1258 endif()
1259 string(REPLACE ";" " " SSL_BACKENDS "${_items}")
1260 message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
1261
1262 # curl-config needs the following options to be set.
1263 set(CC "${CMAKE_C_COMPILER}")
1264 # TODO probably put a -D... options here?
1265 set(CONFIGURE_OPTIONS "")
1266 # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
1267 set(CPPFLAG_CURL_STATICLIB "")
1268 set(CURLVERSION "${CURL_VERSION}")
1269 if(BUILD_SHARED_LIBS)
1270 set(ENABLE_SHARED "yes")
1271 set(ENABLE_STATIC "no")
1272 else()
1273 set(ENABLE_SHARED "no")
1274 set(ENABLE_STATIC "yes")
1275 endif()
1276 set(exec_prefix "\${prefix}")
1277 set(includedir "\${prefix}/include")
1278 set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
1279 set(LIBCURL_LIBS "")
1280 set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
1281 foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
1282 if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
1283 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
1284 else()
1285 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
1286 endif()
1287 endforeach()
1288 # "a" (Linux) or "lib" (Windows)
1289 string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1290 set(prefix "${CMAKE_INSTALL_PREFIX}")
1291 # Set this to "yes" to append all libraries on which -lcurl is dependent
1292 set(REQUIRE_LIB_DEPS "no")
1293 # SUPPORT_FEATURES
1294 # SUPPORT_PROTOCOLS
1295 set(VERSIONNUM "${CURL_VERSION_NUM}")
1296
1297 # Finally generate a "curl-config" matching this config
1298 # Use:
1299 # * ENABLE_SHARED
1300 # * ENABLE_STATIC
1301 configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1302 "${CURL_BINARY_DIR}/curl-config" @ONLY)
1303 install(FILES "${CURL_BINARY_DIR}/curl-config"
1304 DESTINATION ${CMAKE_INSTALL_BINDIR}
1305 PERMISSIONS
1306 OWNER_READ OWNER_WRITE OWNER_EXECUTE
1307 GROUP_READ GROUP_EXECUTE
1308 WORLD_READ WORLD_EXECUTE)
1309
1310 # Finally generate a pkg-config file matching this config
1311 configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1312 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
1313 install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
1314 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1315
1316 # install headers
1317 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1318 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1319 FILES_MATCHING PATTERN "*.h")
1320
1321 include(CMakePackageConfigHelpers)
1322 write_basic_package_version_file(
1323 "${version_config}"
1324 VERSION ${CURL_VERSION}
1325 COMPATIBILITY SameMajorVersion
1326 )
1327
1328 # Use:
1329 # * TARGETS_EXPORT_NAME
1330 # * PROJECT_NAME
1331 configure_package_config_file(CMake/curl-config.cmake.in
1332 "${project_config}"
1333 INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1334 )
1335
1336 install(
1337 EXPORT "${TARGETS_EXPORT_NAME}"
1338 NAMESPACE "${PROJECT_NAME}::"
1339 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1340 )
1341
1342 install(
1343 FILES ${version_config} ${project_config}
1344 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1345 )
1346
1347 # Workaround for MSVS10 to avoid the Dialog Hell
1348 # FIXME: This could be removed with future version of CMake.
1349 if(MSVC_VERSION EQUAL 1600)
1350 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1351 if(EXISTS "${CURL_SLN_FILENAME}")
1352 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1353 endif()
1354 endif()
1355
1356 if(NOT TARGET uninstall)
1357 configure_file(
1358 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1359 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1360 IMMEDIATE @ONLY)
1361
1362 add_custom_target(uninstall
1363 COMMAND ${CMAKE_COMMAND} -P
1364 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
1365 endif()