1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 ###########################################################################
22 # curl/libcurl CMake script
23 # by Tetetest and Sukender (Benoit Neil)
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).
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
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}")
45 include(CMakeDependentOption)
46 include(CheckCCompilerFlag)
50 message(WARNING "the curl cmake build system is poorly maintained. Be aware")
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})
61 # Setup package meta-data
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}\"")
72 include_directories(${CURL_SOURCE_DIR}/include)
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)
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)
84 cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
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)
91 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
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
96 check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
98 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
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)
111 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
114 # For debug libs and exes, add "-d" postfix
115 if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
116 set(CMAKE_DEBUG_POSTFIX "-d")
119 # initialize CURL_LIBS
124 find_package(CARES REQUIRED)
125 list(APPEND CURL_LIBS ${CARES_LIBRARY})
126 set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
129 include(CurlSymbolHiding)
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)
148 option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
149 mark_as_advanced(CURL_DISABLE_LDAPS)
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)
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)
179 option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
180 mark_as_advanced(CURL_DISABLE_COOKIES)
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...
198 CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
205 cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
206 ON "NROFF_USEFUL;PERL_FOUND"
210 message(STATUS "Perl not found, testing disabled.")
211 set(BUILD_TESTING OFF)
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})
222 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
223 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
226 # Disable warnings on Borland to avoid changing 3rd party code.
228 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
231 # If we are on AIX, do the _ALL_SOURCE magic
232 if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
236 # Include all the necessary files for macros
237 include(CMakePushCheckState)
238 include(CheckFunctionExists)
239 include(CheckIncludeFile)
240 include(CheckIncludeFiles)
241 include(CheckLibraryExists)
242 include(CheckSymbolExists)
243 include(CheckTypeSize)
244 include(CheckCSourceCompiles)
246 # On windows preload settings
248 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
249 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
252 if(ENABLE_THREADED_RESOLVER)
253 find_package(Threads REQUIRED)
255 set(USE_THREADS_WIN32 ON)
257 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
258 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
260 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
263 # Check for all needed libraries
264 check_library_exists_concat("${CMAKE_DL_LIBS}" dlopen HAVE_LIBDL)
265 check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
266 check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
268 # Yellowtab Zeta needs different libraries than BeOS 5.
270 set(NOT_NEED_LIBNSL 1)
271 check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
272 check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
275 if(NOT NOT_NEED_LIBNSL)
276 check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
279 check_function_exists(gethostname HAVE_GETHOSTNAME)
282 check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
283 check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
284 list(APPEND CURL_LIBS "advapi32")
287 # check SSL libraries
288 # TODO support GNUTLS, POLARSSL, CYASSL
291 option(CMAKE_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF)
294 option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
295 cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
296 CMAKE_USE_WINSSL OFF)
298 option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
299 option(CMAKE_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF)
300 option(CMAKE_USE_NSS "Enable NSS for SSL/TLS" OFF)
302 set(openssl_default ON)
303 if(WIN32 OR CMAKE_USE_SECTRANSP OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS OR CMAKE_USE_NSS)
304 set(openssl_default OFF)
306 option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default})
308 count_true(enabled_ssl_options_count
316 if(enabled_ssl_options_count GREATER "1")
317 set(CURL_WITH_MULTI_SSL ON)
322 set(USE_SCHANNEL ON) # Windows native SSL/TLS support
323 set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
324 list(APPEND CURL_LIBS "crypt32")
326 if(CURL_WINDOWS_SSPI)
327 set(USE_WINDOWS_SSPI ON)
328 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
331 if(CMAKE_USE_DARWINSSL)
332 message(FATAL_ERROR "The cmake option CMAKE_USE_DARWINSSL was renamed to CMAKE_USE_SECTRANSP.")
335 if(CMAKE_USE_SECTRANSP)
336 find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
337 if(NOT COREFOUNDATION_FRAMEWORK)
338 message(FATAL_ERROR "CoreFoundation framework not found")
341 find_library(SECURITY_FRAMEWORK "Security")
342 if(NOT SECURITY_FRAMEWORK)
343 message(FATAL_ERROR "Security framework not found")
347 set(USE_SECTRANSP ON)
348 list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
351 if(CMAKE_USE_OPENSSL)
352 find_package(OpenSSL REQUIRED)
356 # Depend on OpenSSL via imported targets if supported by the running
357 # version of CMake. This allows our dependents to get our dependencies
359 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
360 list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
362 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
363 include_directories(${OPENSSL_INCLUDE_DIR})
366 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
367 check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
368 check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
369 check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
370 check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
371 check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
372 check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
373 check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
374 check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
375 check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
376 check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
379 if(CMAKE_USE_MBEDTLS)
380 find_package(MbedTLS REQUIRED)
383 list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
384 include_directories(${MBEDTLS_INCLUDE_DIRS})
387 if(CMAKE_USE_BEARSSL)
388 find_package(BearSSL REQUIRED)
391 list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
392 include_directories(${BEARSSL_INCLUDE_DIRS})
396 find_package(NSS REQUIRED)
397 include_directories(${NSS_INCLUDE_DIRS})
398 list(APPEND CURL_LIBS ${NSS_LIBRARIES})
401 cmake_push_check_state()
402 set(CMAKE_REQUIRED_INCLUDES ${NSS_INCLUDE_DIRS})
403 set(CMAKE_REQUIRED_LIBRARIES ${NSS_LIBRARIES})
404 check_symbol_exists(PK11_CreateManagedGenericObject "pk11pub.h" HAVE_PK11_CREATEMANAGEDGENERICOBJECT)
405 cmake_pop_check_state()
408 option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
410 find_package(NGHTTP2 REQUIRED)
411 include_directories(${NGHTTP2_INCLUDE_DIRS})
412 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
415 if(NOT CURL_DISABLE_LDAP)
417 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
419 check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
421 set(USE_WIN32_LDAP OFF)
426 option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
427 mark_as_advanced(CMAKE_USE_OPENLDAP)
428 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
429 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
431 if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
432 message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
435 # Now that we know, we're not using windows LDAP...
437 check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
438 check_include_file_concat("winber.h" HAVE_WINBER_H)
441 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
442 check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
443 check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
445 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
446 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
447 if(CMAKE_LDAP_INCLUDE_DIR)
448 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
450 check_include_file_concat("ldap.h" HAVE_LDAP_H)
451 check_include_file_concat("lber.h" HAVE_LBER_H)
454 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
455 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
456 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
457 elseif(NOT HAVE_LIBLDAP)
458 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
459 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
460 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
462 if(CMAKE_USE_OPENLDAP)
465 if(CMAKE_LDAP_INCLUDE_DIR)
466 include_directories(${CMAKE_LDAP_INCLUDE_DIR})
471 list(APPEND _HEADER_LIST "windows.h")
474 list(APPEND _HEADER_LIST "sys/types.h")
476 list(APPEND _HEADER_LIST "ldap.h")
479 foreach(_HEADER ${_HEADER_LIST})
480 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
486 int main(int argc, char ** argv)
488 BerValue *bvp = NULL;
489 BerElement *bep = ber_init(bvp);
494 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
495 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
497 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
499 check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
500 unset(CMAKE_REQUIRED_LIBRARIES)
505 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
512 if(CURL_DISABLE_LDAP)
513 if(NOT CURL_DISABLE_LDAPS)
514 message(STATUS "LDAP needs to be enabled to support LDAPS")
515 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
519 if(NOT CURL_DISABLE_LDAPS)
520 check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
521 check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
525 check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
527 # Check for symbol dlopen (same as HAVE_LIBDL)
528 check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
530 option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
535 find_package(ZLIB QUIET)
541 # Depend on ZLIB via imported targets if supported by the running
542 # version of CMake. This allows our dependents to get our dependencies
544 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
545 list(APPEND CURL_LIBS ZLIB::ZLIB)
547 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
548 include_directories(${ZLIB_INCLUDE_DIRS})
550 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
554 option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
557 find_package(Brotli QUIET)
560 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
561 include_directories(${BROTLI_INCLUDE_DIRS})
562 list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
567 option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
568 mark_as_advanced(CMAKE_USE_LIBSSH2)
570 set(HAVE_LIBSSH2 OFF)
571 set(HAVE_LIBSSH2_H OFF)
573 if(CMAKE_USE_LIBSSH2)
574 find_package(LibSSH2)
576 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
577 set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
578 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
579 include_directories("${LIBSSH2_INCLUDE_DIR}")
583 # find_package has already found the headers
584 set(HAVE_LIBSSH2_H ON)
585 set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
586 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
588 # now check for specific libssh2 symbols as they were added in different versions
589 set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
590 check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
591 check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
592 check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
593 check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
594 check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
595 set(CMAKE_EXTRA_INCLUDE_FILES "")
596 unset(CMAKE_REQUIRED_LIBRARIES)
600 option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
601 mark_as_advanced(CMAKE_USE_GSSAPI)
606 set(HAVE_GSSAPI ${GSS_FOUND})
609 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
611 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
612 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
613 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
614 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
616 if(GSS_FLAVOUR STREQUAL "Heimdal")
617 set(HAVE_GSSHEIMDAL ON)
620 set(_INCLUDE_LIST "")
621 if(HAVE_GSSAPI_GSSAPI_H)
622 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
624 if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
625 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
627 if(HAVE_GSSAPI_GSSAPI_KRB5_H)
628 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
631 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
632 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
634 foreach(_dir ${GSS_LINK_DIRECTORIES})
635 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
638 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
639 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
640 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
641 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
642 set(HAVE_OLD_GSSMIT ON)
644 unset(CMAKE_REQUIRED_LIBRARIES)
648 include_directories(${GSS_INCLUDE_DIR})
649 link_directories(${GSS_LINK_DIRECTORIES})
650 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
651 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
652 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
653 list(APPEND CURL_LIBS ${GSS_LIBRARIES})
656 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
660 option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
661 if(ENABLE_UNIX_SOCKETS)
662 include(CheckStructHasMember)
663 check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
665 unset(USE_UNIX_SOCKETS CACHE)
671 set(CURL_CA_BUNDLE "auto" CACHE STRING
672 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
673 set(CURL_CA_FALLBACK OFF CACHE BOOL
674 "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
675 set(CURL_CA_PATH "auto" CACHE STRING
676 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
678 if("${CURL_CA_BUNDLE}" STREQUAL "")
679 message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
680 elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
681 unset(CURL_CA_BUNDLE CACHE)
682 elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
683 unset(CURL_CA_BUNDLE CACHE)
684 set(CURL_CA_BUNDLE_AUTODETECT TRUE)
686 set(CURL_CA_BUNDLE_SET TRUE)
689 if("${CURL_CA_PATH}" STREQUAL "")
690 message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
691 elseif("${CURL_CA_PATH}" STREQUAL "none")
692 unset(CURL_CA_PATH CACHE)
693 elseif("${CURL_CA_PATH}" STREQUAL "auto")
694 unset(CURL_CA_PATH CACHE)
696 set(CURL_CA_PATH_AUTODETECT TRUE)
699 set(CURL_CA_PATH_SET TRUE)
702 if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
703 # Skip autodetection of unset CA path because CA bundle is set explicitly
704 elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
705 # Skip autodetection of unset CA bundle because CA path is set explicitly
706 elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
707 # first try autodetecting a CA bundle, then a CA path
709 if(CURL_CA_BUNDLE_AUTODETECT)
710 set(SEARCH_CA_BUNDLE_PATHS
711 /etc/ssl/certs/ca-certificates.crt
712 /etc/pki/tls/certs/ca-bundle.crt
713 /usr/share/ssl/certs/ca-bundle.crt
714 /usr/local/share/certs/ca-root-nss.crt
717 foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
718 if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
719 message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
720 set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
721 set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
727 if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
728 if(EXISTS "/etc/ssl/certs")
729 set(CURL_CA_PATH "/etc/ssl/certs")
730 set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
735 if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
737 "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
738 "Set CURL_CA_PATH=none or enable one of those TLS backends.")
741 # Check for header files
743 check_include_file_concat("windows.h" HAVE_WINDOWS_H)
744 check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
745 check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
746 check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
747 if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL)
748 set(CURL_LIBS ${CURL_LIBS} "crypt32")
752 check_include_file_concat("stdio.h" HAVE_STDIO_H)
753 check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
754 check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
755 check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
756 check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
757 check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
758 check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
759 check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
760 check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
761 check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
762 check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
763 check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
764 check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
765 check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
766 check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
767 check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
768 check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
769 check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
770 check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
771 check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
772 check_include_file_concat("assert.h" HAVE_ASSERT_H)
773 check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
774 check_include_file_concat("des.h" HAVE_DES_H)
775 check_include_file_concat("err.h" HAVE_ERR_H)
776 check_include_file_concat("errno.h" HAVE_ERRNO_H)
777 check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
778 check_include_file_concat("idn2.h" HAVE_IDN2_H)
779 check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
780 check_include_file_concat("io.h" HAVE_IO_H)
781 check_include_file_concat("krb.h" HAVE_KRB_H)
782 check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
783 check_include_file_concat("locale.h" HAVE_LOCALE_H)
784 check_include_file_concat("net/if.h" HAVE_NET_IF_H)
785 check_include_file_concat("netdb.h" HAVE_NETDB_H)
786 check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
787 check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
789 check_include_file_concat("pem.h" HAVE_PEM_H)
790 check_include_file_concat("poll.h" HAVE_POLL_H)
791 check_include_file_concat("pwd.h" HAVE_PWD_H)
792 check_include_file_concat("rsa.h" HAVE_RSA_H)
793 check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
794 check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
795 check_include_file_concat("signal.h" HAVE_SIGNAL_H)
796 check_include_file_concat("ssl.h" HAVE_SSL_H)
797 check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
798 check_include_file_concat("stdint.h" HAVE_STDINT_H)
799 check_include_file_concat("stdio.h" HAVE_STDIO_H)
800 check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
801 check_include_file_concat("string.h" HAVE_STRING_H)
802 check_include_file_concat("strings.h" HAVE_STRINGS_H)
803 check_include_file_concat("stropts.h" HAVE_STROPTS_H)
804 check_include_file_concat("termio.h" HAVE_TERMIO_H)
805 check_include_file_concat("termios.h" HAVE_TERMIOS_H)
806 check_include_file_concat("time.h" HAVE_TIME_H)
807 check_include_file_concat("unistd.h" HAVE_UNISTD_H)
808 check_include_file_concat("utime.h" HAVE_UTIME_H)
809 check_include_file_concat("x509.h" HAVE_X509_H)
811 check_include_file_concat("process.h" HAVE_PROCESS_H)
812 check_include_file_concat("stddef.h" HAVE_STDDEF_H)
813 check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
814 check_include_file_concat("malloc.h" HAVE_MALLOC_H)
815 check_include_file_concat("memory.h" HAVE_MEMORY_H)
816 check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
817 check_include_file_concat("stdint.h" HAVE_STDINT_H)
818 check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
819 check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
821 check_type_size(size_t SIZEOF_SIZE_T)
822 check_type_size(ssize_t SIZEOF_SSIZE_T)
823 check_type_size("long long" SIZEOF_LONG_LONG)
824 check_type_size("long" SIZEOF_LONG)
825 check_type_size("short" SIZEOF_SHORT)
826 check_type_size("int" SIZEOF_INT)
827 check_type_size("__int64" SIZEOF___INT64)
828 check_type_size("long double" SIZEOF_LONG_DOUBLE)
829 check_type_size("time_t" SIZEOF_TIME_T)
830 if(NOT HAVE_SIZEOF_SSIZE_T)
831 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
834 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
838 # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
840 if(HAVE_SIZEOF_LONG_LONG)
845 find_file(RANDOM_FILE urandom /dev)
846 mark_as_advanced(RANDOM_FILE)
848 # Check for some functions that are used
850 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
851 elseif(HAVE_LIBSOCKET)
852 set(CMAKE_REQUIRED_LIBRARIES socket)
855 check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
856 check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
857 check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
858 check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
859 check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
860 check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
861 check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
862 check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
863 check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
864 check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
865 check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
866 check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
867 check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
868 check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
869 if(NOT HAVE_STRNCMPI)
872 check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
873 check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
874 check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
875 check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
876 check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
877 check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
878 check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
879 check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
880 check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
881 check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
882 check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
883 check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
884 check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
885 check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
886 check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
887 check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
888 check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
889 check_symbol_exists(usleep "${CURL_INCLUDES}" HAVE_USLEEP)
890 check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
891 check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
892 check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
894 check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
895 check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
897 check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
898 check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
899 if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
902 check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
903 check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
904 check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
905 check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
906 check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
907 check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
908 check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
909 check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
910 check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
911 check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
912 check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
913 check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
914 check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
915 check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
916 check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
917 check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
918 check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
919 check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
920 check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
921 check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
922 check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
923 check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
924 check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
925 check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
927 # symbol exists in win32, but function does not.
930 check_function_exists(inet_pton HAVE_INET_PTON)
931 # _WIN32_WINNT_VISTA (0x0600)
932 add_definitions(-D_WIN32_WINNT=0x0600)
934 # _WIN32_WINNT_WINXP (0x0501)
935 add_definitions(-D_WIN32_WINNT=0x0501)
938 check_function_exists(inet_pton HAVE_INET_PTON)
941 check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
943 foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
944 curl_internal_test(${CURL_TEST})
948 # sigaction and sigsetjmp are special. Use special mechanism for
949 # detecting those, but only if previous attempt failed.
951 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
954 if(NOT HAVE_SIGSETJMP)
956 check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
957 if(HAVE_MACRO_SIGSETJMP)
958 set(HAVE_SIGSETJMP 1)
963 # If there is no stricmp(), do not allow LDAP to parse URLs
965 set(HAVE_LDAP_URL_PARSE 1)
968 # Do curl specific tests
970 HAVE_FCNTL_O_NONBLOCK
972 HAVE_IOCTLSOCKET_CAMEL
973 HAVE_IOCTLSOCKET_CAMEL_FIONBIO
974 HAVE_IOCTLSOCKET_FIONBIO
976 HAVE_IOCTL_SIOCGIFADDR
977 HAVE_SETSOCKOPT_SO_NONBLOCK
978 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
981 HAVE_GETHOSTBYADDR_R_5
982 HAVE_GETHOSTBYADDR_R_7
983 HAVE_GETHOSTBYADDR_R_8
984 HAVE_GETHOSTBYADDR_R_5_REENTRANT
985 HAVE_GETHOSTBYADDR_R_7_REENTRANT
986 HAVE_GETHOSTBYADDR_R_8_REENTRANT
987 HAVE_GETHOSTBYNAME_R_3
988 HAVE_GETHOSTBYNAME_R_5
989 HAVE_GETHOSTBYNAME_R_6
990 HAVE_GETHOSTBYNAME_R_3_REENTRANT
991 HAVE_GETHOSTBYNAME_R_5_REENTRANT
992 HAVE_GETHOSTBYNAME_R_6_REENTRANT
997 HAVE_INET_NTOA_R_DECL
998 HAVE_INET_NTOA_R_DECL_REENTRANT
1000 HAVE_FILE_OFFSET_BITS
1001 HAVE_VARIADIC_MACROS_C99
1002 HAVE_VARIADIC_MACROS_GCC
1004 curl_internal_test(${CURL_TEST})
1007 if(HAVE_FILE_OFFSET_BITS)
1008 set(_FILE_OFFSET_BITS 64)
1009 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
1011 check_type_size("off_t" SIZEOF_OFF_T)
1013 # include this header to get the type
1014 set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
1015 set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
1016 check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
1017 set(CMAKE_EXTRA_INCLUDE_FILES "")
1019 set(CMAKE_REQUIRED_FLAGS)
1022 HAVE_GLIBC_STRERROR_R
1023 HAVE_POSIX_STRERROR_R
1025 curl_internal_test(${CURL_TEST})
1028 # Check for reentrant
1030 HAVE_GETHOSTBYADDR_R_5
1031 HAVE_GETHOSTBYADDR_R_7
1032 HAVE_GETHOSTBYADDR_R_8
1033 HAVE_GETHOSTBYNAME_R_3
1034 HAVE_GETHOSTBYNAME_R_5
1035 HAVE_GETHOSTBYNAME_R_6
1036 HAVE_INET_NTOA_R_DECL_REENTRANT)
1037 if(NOT ${CURL_TEST})
1038 if(${CURL_TEST}_REENTRANT)
1039 set(NEED_REENTRANT 1)
1046 HAVE_GETHOSTBYADDR_R_5
1047 HAVE_GETHOSTBYADDR_R_7
1048 HAVE_GETHOSTBYADDR_R_8
1049 HAVE_GETHOSTBYNAME_R_3
1050 HAVE_GETHOSTBYNAME_R_5
1051 HAVE_GETHOSTBYNAME_R_6)
1053 if(${CURL_TEST}_REENTRANT)
1059 if(HAVE_INET_NTOA_R_DECL_REENTRANT)
1060 set(HAVE_INET_NTOA_R_DECL 1)
1061 set(NEED_REENTRANT 1)
1064 # Check clock_gettime(CLOCK_MONOTONIC, x) support
1065 curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
1067 # Check compiler support of __builtin_available()
1068 curl_internal_test(HAVE_BUILTIN_AVAILABLE)
1070 # Some other minor tests
1072 if(NOT HAVE_IN_ADDR_T)
1073 set(in_addr_t "unsigned long")
1078 if(NOT CURL_SPECIAL_LIBZ)
1088 # Check for nonblocking
1089 set(HAVE_DISABLED_NONBLOCKING 1)
1092 HAVE_IOCTLSOCKET_CASE OR
1094 set(HAVE_DISABLED_NONBLOCKING)
1098 set(RETSIGTYPE void)
1103 if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1104 include(CheckCCompilerFlag)
1105 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1106 if(HAVE_C_FLAG_Wno_long_double)
1107 # The Mac version of GCC warns about use of long double. Disable it.
1108 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1109 if(MPRINTF_COMPILE_FLAGS)
1110 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1112 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1114 set_source_files_properties(mprintf.c PROPERTIES
1115 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1119 # TODO test which of these headers are required
1121 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
1123 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
1124 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
1125 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
1127 set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
1128 set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
1130 include(CMake/OtherTests.cmake)
1132 add_definitions(-DHAVE_CONFIG_H)
1134 # For Windows, all compilers used by CMake should support large files
1136 set(USE_WIN32_LARGE_FILES ON)
1138 # Use the manifest embedded in the Windows Resource
1139 set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1143 # Disable default manifest added by CMake
1144 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1146 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1147 if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1148 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1150 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1156 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1158 # this assumes clang or gcc style options
1159 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1163 # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1164 function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
1165 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1166 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1167 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1169 string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1170 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1171 string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1173 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
1174 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.
1175 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1179 include(GNUInstallDirs)
1181 set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
1182 set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
1183 set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
1184 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
1185 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
1188 add_subdirectory(docs)
1191 add_subdirectory(lib)
1194 add_subdirectory(src)
1199 add_subdirectory(tests)
1202 # Helper to populate a list (_items) with a label when conditions (the remaining
1203 # args) are satisfied
1204 function(_add_if label)
1205 # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
1207 set(_items ${_items} "${label}" PARENT_SCOPE)
1211 # Clear list and try to detect available features
1213 _add_if("SSL" SSL_ENABLED)
1214 _add_if("IPv6" ENABLE_IPV6)
1215 _add_if("unix-sockets" USE_UNIX_SOCKETS)
1216 _add_if("libz" HAVE_LIBZ)
1217 _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1218 _add_if("IDN" HAVE_LIBIDN2)
1219 _add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
1220 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
1221 # TODO SSP1 (WinSSL) check is missing
1222 _add_if("SSPI" USE_WINDOWS_SSPI)
1223 _add_if("GSS-API" HAVE_GSSAPI)
1224 # TODO SSP1 missing for SPNEGO
1225 _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
1226 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1227 _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
1228 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1229 # NTLM support requires crypto function adaptions from various SSL libs
1230 # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
1231 if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_SECTRANSP OR USE_MBEDTLS OR USE_NSS))
1233 # TODO missing option (autoconf: --enable-ntlm-wb)
1234 _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
1236 # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
1237 _add_if("TLS-SRP" USE_TLS_SRP)
1238 # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
1239 _add_if("HTTP2" USE_NGHTTP2)
1240 string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1241 message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1243 # Clear list and try to detect available protocols
1245 _add_if("HTTP" NOT CURL_DISABLE_HTTP)
1246 _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1247 _add_if("FTP" NOT CURL_DISABLE_FTP)
1248 _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1249 _add_if("FILE" NOT CURL_DISABLE_FILE)
1250 _add_if("TELNET" NOT CURL_DISABLE_TELNET)
1251 _add_if("LDAP" NOT CURL_DISABLE_LDAP)
1252 # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1253 # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
1254 _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
1255 ((USE_OPENLDAP AND SSL_ENABLED) OR
1256 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1257 _add_if("DICT" NOT CURL_DISABLE_DICT)
1258 _add_if("TFTP" NOT CURL_DISABLE_TFTP)
1259 _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
1260 _add_if("POP3" NOT CURL_DISABLE_POP3)
1261 _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1262 _add_if("IMAP" NOT CURL_DISABLE_IMAP)
1263 _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1264 _add_if("SMTP" NOT CURL_DISABLE_SMTP)
1265 _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1266 _add_if("SCP" USE_LIBSSH2)
1267 _add_if("SFTP" USE_LIBSSH2)
1268 _add_if("RTSP" NOT CURL_DISABLE_RTSP)
1269 _add_if("RTMP" USE_LIBRTMP)
1273 string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1274 message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1276 # Clear list and collect SSL backends
1278 _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
1279 _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
1280 _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
1281 _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
1282 _add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL)
1283 _add_if("NSS" SSL_ENABLED AND USE_NSS)
1287 string(REPLACE ";" " " SSL_BACKENDS "${_items}")
1288 message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
1290 # curl-config needs the following options to be set.
1291 set(CC "${CMAKE_C_COMPILER}")
1292 # TODO probably put a -D... options here?
1293 set(CONFIGURE_OPTIONS "")
1294 # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
1295 set(CPPFLAG_CURL_STATICLIB "")
1296 set(CURLVERSION "${CURL_VERSION}")
1297 if(BUILD_SHARED_LIBS)
1298 set(ENABLE_SHARED "yes")
1299 set(ENABLE_STATIC "no")
1301 set(ENABLE_SHARED "no")
1302 set(ENABLE_STATIC "yes")
1304 set(exec_prefix "\${prefix}")
1305 set(includedir "\${prefix}/include")
1306 set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
1307 set(LIBCURL_LIBS "")
1308 set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
1309 foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
1310 if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
1311 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
1313 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
1316 # "a" (Linux) or "lib" (Windows)
1317 string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1318 set(prefix "${CMAKE_INSTALL_PREFIX}")
1319 # Set this to "yes" to append all libraries on which -lcurl is dependent
1320 set(REQUIRE_LIB_DEPS "no")
1323 set(VERSIONNUM "${CURL_VERSION_NUM}")
1325 # Finally generate a "curl-config" matching this config
1329 configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1330 "${CURL_BINARY_DIR}/curl-config" @ONLY)
1331 install(FILES "${CURL_BINARY_DIR}/curl-config"
1332 DESTINATION ${CMAKE_INSTALL_BINDIR}
1334 OWNER_READ OWNER_WRITE OWNER_EXECUTE
1335 GROUP_READ GROUP_EXECUTE
1336 WORLD_READ WORLD_EXECUTE)
1338 # Finally generate a pkg-config file matching this config
1339 configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1340 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
1341 install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
1342 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1345 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1346 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1347 FILES_MATCHING PATTERN "*.h")
1349 include(CMakePackageConfigHelpers)
1350 write_basic_package_version_file(
1352 VERSION ${CURL_VERSION}
1353 COMPATIBILITY SameMajorVersion
1357 # * TARGETS_EXPORT_NAME
1359 configure_package_config_file(CMake/curl-config.cmake.in
1361 INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1365 EXPORT "${TARGETS_EXPORT_NAME}"
1366 NAMESPACE "${PROJECT_NAME}::"
1367 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1371 FILES ${version_config} ${project_config}
1372 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1375 # Workaround for MSVS10 to avoid the Dialog Hell
1376 # FIXME: This could be removed with future version of CMake.
1377 if(MSVC_VERSION EQUAL 1600)
1378 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1379 if(EXISTS "${CURL_SLN_FILENAME}")
1380 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1384 if(NOT TARGET uninstall)
1386 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1387 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1390 add_custom_target(uninstall
1391 COMMAND ${CMAKE_COMMAND} -P
1392 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)