1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2018, 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})
60 include_regular_expression("^.*$") # Sukender: Is it necessary?
62 # Setup package meta-data
64 message(STATUS "curl version=[${CURL_VERSION}]")
65 # SET(PACKAGE_TARNAME "curl")
66 # SET(PACKAGE_NAME "curl")
67 # SET(PACKAGE_VERSION "-")
68 # SET(PACKAGE_STRING "curl-")
69 # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/")
70 set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
71 set(OS "\"${CMAKE_SYSTEM_NAME}\"")
73 include_directories(${PROJECT_BINARY_DIR}/include/curl)
74 include_directories(${CURL_SOURCE_DIR}/include)
76 option(CURL_WERROR "Turn compiler warnings into errors" OFF)
77 option(PICKY_COMPILER "Enable picky compiler options" ON)
78 option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
79 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
80 option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
82 option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
83 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)
86 cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
90 option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
91 option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
93 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
95 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)
96 # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
98 check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
100 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
107 # DEBUGBUILD will be defined only for Debug builds
108 if(NOT CMAKE_VERSION VERSION_LESS 3.0)
109 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
111 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUGBUILD)
113 set(ENABLE_CURLDEBUG ON)
117 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
120 # For debug libs and exes, add "-d" postfix
121 if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
122 set(CMAKE_DEBUG_POSTFIX "-d")
125 # initialize CURL_LIBS
130 find_package(CARES REQUIRED)
131 list(APPEND CURL_LIBS ${CARES_LIBRARY})
132 set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
135 include(CurlSymbolHiding)
137 option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
138 mark_as_advanced(HTTP_ONLY)
139 option(CURL_DISABLE_FTP "disables FTP" OFF)
140 mark_as_advanced(CURL_DISABLE_FTP)
141 option(CURL_DISABLE_LDAP "disables LDAP" OFF)
142 mark_as_advanced(CURL_DISABLE_LDAP)
143 option(CURL_DISABLE_TELNET "disables Telnet" OFF)
144 mark_as_advanced(CURL_DISABLE_TELNET)
145 option(CURL_DISABLE_DICT "disables DICT" OFF)
146 mark_as_advanced(CURL_DISABLE_DICT)
147 option(CURL_DISABLE_FILE "disables FILE" OFF)
148 mark_as_advanced(CURL_DISABLE_FILE)
149 option(CURL_DISABLE_TFTP "disables TFTP" OFF)
150 mark_as_advanced(CURL_DISABLE_TFTP)
151 option(CURL_DISABLE_HTTP "disables HTTP" OFF)
152 mark_as_advanced(CURL_DISABLE_HTTP)
154 option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
155 mark_as_advanced(CURL_DISABLE_LDAPS)
157 option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
158 mark_as_advanced(CURL_DISABLE_RTSP)
159 option(CURL_DISABLE_PROXY "to disable proxy" OFF)
160 mark_as_advanced(CURL_DISABLE_PROXY)
161 option(CURL_DISABLE_POP3 "to disable POP3" OFF)
162 mark_as_advanced(CURL_DISABLE_POP3)
163 option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
164 mark_as_advanced(CURL_DISABLE_IMAP)
165 option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
166 mark_as_advanced(CURL_DISABLE_SMTP)
167 option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
168 mark_as_advanced(CURL_DISABLE_GOPHER)
171 set(CURL_DISABLE_FTP ON)
172 set(CURL_DISABLE_LDAP ON)
173 set(CURL_DISABLE_LDAPS ON)
174 set(CURL_DISABLE_TELNET ON)
175 set(CURL_DISABLE_DICT ON)
176 set(CURL_DISABLE_FILE ON)
177 set(CURL_DISABLE_TFTP ON)
178 set(CURL_DISABLE_RTSP ON)
179 set(CURL_DISABLE_POP3 ON)
180 set(CURL_DISABLE_IMAP ON)
181 set(CURL_DISABLE_SMTP ON)
182 set(CURL_DISABLE_GOPHER ON)
185 option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
186 mark_as_advanced(CURL_DISABLE_COOKIES)
188 option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
189 mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
190 option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
191 mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
192 option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
193 mark_as_advanced(ENABLE_IPV6)
194 if(ENABLE_IPV6 AND NOT WIN32)
195 include(CheckStructHasMember)
196 check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
197 HAVE_SOCKADDR_IN6_SIN6_ADDR)
198 check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
199 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
200 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
201 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
202 # Force the feature off as this name is used as guard macro...
204 CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
211 cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
212 ON "NROFF_USEFUL;PERL_FOUND"
216 message(STATUS "Perl not found, testing disabled.")
217 set(BUILD_TESTING OFF)
223 # We need ansi c-flags, especially on HP
224 set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
225 set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
228 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
229 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
232 # Disable warnings on Borland to avoid changing 3rd party code.
234 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
237 # If we are on AIX, do the _ALL_SOURCE magic
238 if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
242 # Include all the necessary files for macros
243 include(CheckFunctionExists)
244 include(CheckIncludeFile)
245 include(CheckIncludeFiles)
246 include(CheckLibraryExists)
247 include(CheckSymbolExists)
248 include(CheckTypeSize)
249 include(CheckCSourceCompiles)
250 include(CMakeDependentOption)
252 # On windows preload settings
254 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
255 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
258 if(ENABLE_THREADED_RESOLVER)
259 find_package(Threads REQUIRED)
261 set(USE_THREADS_WIN32 ON)
263 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
264 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
266 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
269 # Check for all needed libraries
270 check_library_exists_concat("dl" dlopen HAVE_LIBDL)
271 check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
272 check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
274 # Yellowtab Zeta needs different libraries than BeOS 5.
276 set(NOT_NEED_LIBNSL 1)
277 check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
278 check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
281 if(NOT NOT_NEED_LIBNSL)
282 check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
285 check_function_exists(gethostname HAVE_GETHOSTNAME)
288 check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
289 check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
290 list(APPEND CURL_LIBS "advapi32")
293 # check SSL libraries
294 # TODO support GNUTLS, NSS, POLARSSL, AXTLS, CYASSL
297 option(CMAKE_USE_DARWINSSL "enable Apple OS native SSL/TLS" OFF)
300 option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
301 cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
302 CMAKE_USE_WINSSL OFF)
304 option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
306 set(openssl_default ON)
307 if(WIN32 OR CMAKE_USE_DARWINSSL OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
308 set(openssl_default OFF)
310 option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default})
312 count_true(enabled_ssl_options_count
318 if(enabled_ssl_options_count GREATER "1")
319 set(CURL_WITH_MULTI_SSL ON)
324 set(USE_SCHANNEL ON) # Windows native SSL/TLS support
325 set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
326 list(APPEND CURL_LIBS "crypt32")
328 if(CURL_WINDOWS_SSPI)
329 set(USE_WINDOWS_SSPI ON)
330 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
333 if(CMAKE_USE_DARWINSSL)
334 find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
335 if(NOT COREFOUNDATION_FRAMEWORK)
336 message(FATAL_ERROR "CoreFoundation framework not found")
339 find_library(SECURITY_FRAMEWORK "Security")
340 if(NOT SECURITY_FRAMEWORK)
341 message(FATAL_ERROR "Security framework not found")
345 set(USE_DARWINSSL ON)
346 list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
349 if(CMAKE_USE_OPENSSL)
350 find_package(OpenSSL REQUIRED)
353 set(HAVE_LIBCRYPTO ON)
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 option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
389 find_package(NGHTTP2 REQUIRED)
390 include_directories(${NGHTTP2_INCLUDE_DIRS})
391 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
394 if(NOT CURL_DISABLE_LDAP)
396 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
398 check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
400 set(USE_WIN32_LDAP OFF)
405 option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
406 mark_as_advanced(CMAKE_USE_OPENLDAP)
407 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
408 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
410 if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
411 message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
414 # Now that we know, we're not using windows LDAP...
416 check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
417 check_include_file_concat("winber.h" HAVE_WINBER_H)
420 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
421 check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
422 check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
424 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
425 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
426 if(CMAKE_LDAP_INCLUDE_DIR)
427 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
429 check_include_file_concat("ldap.h" HAVE_LDAP_H)
430 check_include_file_concat("lber.h" HAVE_LBER_H)
433 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
434 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
435 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
436 elseif(NOT HAVE_LIBLDAP)
437 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
438 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
439 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
441 if(CMAKE_USE_OPENLDAP)
444 if(CMAKE_LDAP_INCLUDE_DIR)
445 include_directories(${CMAKE_LDAP_INCLUDE_DIR})
450 list(APPEND _HEADER_LIST "windows.h")
453 list(APPEND _HEADER_LIST "sys/types.h")
455 list(APPEND _HEADER_LIST "ldap.h")
458 foreach(_HEADER ${_HEADER_LIST})
459 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
465 int main(int argc, char ** argv)
467 BerValue *bvp = NULL;
468 BerElement *bep = ber_init(bvp);
473 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
474 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
476 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
478 check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
483 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
490 if(CURL_DISABLE_LDAP)
491 if(NOT CURL_DISABLE_LDAPS)
492 message(STATUS "LDAP needs to be enabled to support LDAPS")
493 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
497 if(NOT CURL_DISABLE_LDAPS)
498 check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
499 check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
503 check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
505 # Check for symbol dlopen (same as HAVE_LIBDL)
506 check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
508 option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
513 find_package(ZLIB QUIET)
519 # Depend on ZLIB via imported targets if supported by the running
520 # version of CMake. This allows our dependents to get our dependencies
522 if(NOT CMAKE_VERSION VERSION_LESS 3.4)
523 list(APPEND CURL_LIBS ZLIB::ZLIB)
525 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
526 include_directories(${ZLIB_INCLUDE_DIRS})
528 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
532 option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
535 find_package(BROTLI QUIET)
538 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
539 include_directories(${BROTLI_INCLUDE_DIRS})
540 list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
545 option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
546 mark_as_advanced(CMAKE_USE_LIBSSH2)
548 set(HAVE_LIBSSH2 OFF)
549 set(HAVE_LIBSSH2_H OFF)
551 if(CMAKE_USE_LIBSSH2)
552 find_package(LibSSH2)
554 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
555 set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
556 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
557 include_directories("${LIBSSH2_INCLUDE_DIR}")
561 # find_package has already found the headers
562 set(HAVE_LIBSSH2_H ON)
563 set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
564 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
566 # now check for specific libssh2 symbols as they were added in different versions
567 set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
568 check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
569 check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
570 check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
571 check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
572 check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
573 set(CMAKE_EXTRA_INCLUDE_FILES "")
577 option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
578 mark_as_advanced(CMAKE_USE_GSSAPI)
583 set(HAVE_GSSAPI ${GSS_FOUND})
586 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
588 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRECTORIES})
589 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
590 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
591 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
593 if(GSS_FLAVOUR STREQUAL "Heimdal")
594 set(HAVE_GSSHEIMDAL ON)
597 set(_INCLUDE_LIST "")
598 if(HAVE_GSSAPI_GSSAPI_H)
599 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
601 if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
602 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
604 if(HAVE_GSSAPI_GSSAPI_KRB5_H)
605 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
608 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
609 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
611 foreach(_dir ${GSS_LINK_DIRECTORIES})
612 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
615 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
616 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
617 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
618 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
619 set(HAVE_OLD_GSSMIT ON)
624 include_directories(${GSS_INCLUDE_DIRECTORIES})
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})
632 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
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)
641 unset(USE_UNIX_SOCKETS CACHE)
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'.")
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)
662 set(CURL_CA_BUNDLE_SET TRUE)
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)
673 set(CURL_CA_PATH_SET TRUE)
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
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
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")
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")
709 if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
711 "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
712 "Set CURL_CA_PATH=none or enable one of those TLS backends.")
715 # Check for header files
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")
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)
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)
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)
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)
808 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
812 # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
814 if(HAVE_SIZEOF_LONG_LONG)
819 find_file(RANDOM_FILE urandom /dev)
820 mark_as_advanced(RANDOM_FILE)
822 # Check for some functions that are used
824 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
825 elseif(HAVE_LIBSOCKET)
826 set(CMAKE_REQUIRED_LIBRARIES socket)
829 check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
830 check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
831 # poll on macOS is unreliable, it first did not exist, then was broken until
832 # fixed in 10.9 only to break again in 10.12.
834 check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
836 check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
837 check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
838 check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
839 check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
840 check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
841 check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
842 check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
843 check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
844 check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
845 check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
846 check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
847 if(NOT HAVE_STRNCMPI)
850 check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
851 check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
852 check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
853 check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
854 check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
855 check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
856 check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
857 check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
858 check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
859 check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
860 check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
861 check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
862 check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
863 check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
864 check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
865 check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
866 check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
867 check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
868 check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
869 check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
871 check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
872 check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
874 check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
875 check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
876 if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
879 check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
880 check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
881 check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
882 check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
883 check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
884 check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
885 check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
886 check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
887 check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
888 check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
889 check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
890 check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
891 check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
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)
901 # symbol exists in win32, but function does not.
904 check_function_exists(inet_pton HAVE_INET_PTON)
905 # _WIN32_WINNT_VISTA (0x0600)
906 add_definitions(-D_WIN32_WINNT=0x0600)
908 # _WIN32_WINNT_WINXP (0x0501)
909 add_definitions(-D_WIN32_WINNT=0x0501)
912 check_function_exists(inet_pton HAVE_INET_PTON)
915 check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
917 foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
918 curl_internal_test(${CURL_TEST})
922 # sigaction and sigsetjmp are special. Use special mechanism for
923 # detecting those, but only if previous attempt failed.
925 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
928 if(NOT HAVE_SIGSETJMP)
930 check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
931 if(HAVE_MACRO_SIGSETJMP)
932 set(HAVE_SIGSETJMP 1)
937 # If there is no stricmp(), do not allow LDAP to parse URLs
939 set(HAVE_LDAP_URL_PARSE 1)
942 # Do curl specific tests
944 HAVE_FCNTL_O_NONBLOCK
946 HAVE_IOCTLSOCKET_CAMEL
947 HAVE_IOCTLSOCKET_CAMEL_FIONBIO
948 HAVE_IOCTLSOCKET_FIONBIO
950 HAVE_IOCTL_SIOCGIFADDR
951 HAVE_SETSOCKOPT_SO_NONBLOCK
952 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
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
971 HAVE_INET_NTOA_R_DECL
972 HAVE_INET_NTOA_R_DECL_REENTRANT
974 HAVE_FILE_OFFSET_BITS
976 curl_internal_test(${CURL_TEST})
979 if(HAVE_FILE_OFFSET_BITS)
980 set(_FILE_OFFSET_BITS 64)
981 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
983 check_type_size("off_t" SIZEOF_OFF_T)
985 # include this header to get the type
986 set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
987 set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
988 check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
989 set(CMAKE_EXTRA_INCLUDE_FILES "")
991 set(CMAKE_REQUIRED_FLAGS)
994 HAVE_GLIBC_STRERROR_R
995 HAVE_POSIX_STRERROR_R
997 curl_internal_test(${CURL_TEST})
1000 # Check for reentrant
1002 HAVE_GETHOSTBYADDR_R_5
1003 HAVE_GETHOSTBYADDR_R_7
1004 HAVE_GETHOSTBYADDR_R_8
1005 HAVE_GETHOSTBYNAME_R_3
1006 HAVE_GETHOSTBYNAME_R_5
1007 HAVE_GETHOSTBYNAME_R_6
1008 HAVE_INET_NTOA_R_DECL_REENTRANT)
1009 if(NOT ${CURL_TEST})
1010 if(${CURL_TEST}_REENTRANT)
1011 set(NEED_REENTRANT 1)
1018 HAVE_GETHOSTBYADDR_R_5
1019 HAVE_GETHOSTBYADDR_R_7
1020 HAVE_GETHOSTBYADDR_R_8
1021 HAVE_GETHOSTBYNAME_R_3
1022 HAVE_GETHOSTBYNAME_R_5
1023 HAVE_GETHOSTBYNAME_R_6)
1025 if(${CURL_TEST}_REENTRANT)
1031 if(HAVE_INET_NTOA_R_DECL_REENTRANT)
1032 set(HAVE_INET_NTOA_R_DECL 1)
1033 set(NEED_REENTRANT 1)
1036 # Check clock_gettime(CLOCK_MONOTONIC, x) support
1037 curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
1039 # Check compiler support of __builtin_available()
1040 curl_internal_test(HAVE_BUILTIN_AVAILABLE)
1042 # Some other minor tests
1044 if(NOT HAVE_IN_ADDR_T)
1045 set(in_addr_t "unsigned long")
1050 if(NOT CURL_SPECIAL_LIBZ)
1060 # Check for nonblocking
1061 set(HAVE_DISABLED_NONBLOCKING 1)
1064 HAVE_IOCTLSOCKET_CASE OR
1066 set(HAVE_DISABLED_NONBLOCKING)
1070 set(RETSIGTYPE void)
1075 if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1076 include(CheckCCompilerFlag)
1077 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1078 if(HAVE_C_FLAG_Wno_long_double)
1079 # The Mac version of GCC warns about use of long double. Disable it.
1080 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1081 if(MPRINTF_COMPILE_FLAGS)
1082 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1084 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1086 set_source_files_properties(mprintf.c PROPERTIES
1087 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1091 # TODO test which of these headers are required
1093 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
1095 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
1096 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
1097 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
1099 set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
1100 set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
1102 include(CMake/OtherTests.cmake)
1104 add_definitions(-DHAVE_CONFIG_H)
1106 # For Windows, all compilers used by CMake should support large files
1108 set(USE_WIN32_LARGE_FILES ON)
1110 # Use the manifest embedded in the Windows Resource
1111 set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1115 # Disable default manifest added by CMake
1116 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1118 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1119 if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1120 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1122 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1128 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1130 # this assumes clang or gcc style options
1131 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1135 # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1136 function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
1137 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1138 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1139 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1141 string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1142 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1143 string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1145 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
1146 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.
1147 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1151 include(GNUInstallDirs)
1153 set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
1154 set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
1155 set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
1156 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
1157 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
1160 add_subdirectory(docs)
1163 add_subdirectory(lib)
1166 add_subdirectory(src)
1171 add_subdirectory(tests)
1174 # Helper to populate a list (_items) with a label when conditions (the remaining
1175 # args) are satisfied
1176 function(_add_if label)
1177 # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
1179 set(_items ${_items} "${label}" PARENT_SCOPE)
1183 # Clear list and try to detect available features
1185 _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
1186 _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
1187 _add_if("DarwinSSL" SSL_ENABLED AND USE_DARWINSSL)
1188 _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
1189 _add_if("IPv6" ENABLE_IPV6)
1190 _add_if("unix-sockets" USE_UNIX_SOCKETS)
1191 _add_if("libz" HAVE_LIBZ)
1192 _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1193 _add_if("IDN" HAVE_LIBIDN2)
1194 _add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
1195 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
1196 # TODO SSP1 (WinSSL) check is missing
1197 _add_if("SSPI" USE_WINDOWS_SSPI)
1198 _add_if("GSS-API" HAVE_GSSAPI)
1199 # TODO SSP1 missing for SPNEGO
1200 _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
1201 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1202 _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
1203 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1204 # NTLM support requires crypto function adaptions from various SSL libs
1205 # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
1206 if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_DARWINSSL OR USE_MBEDTLS))
1208 # TODO missing option (autoconf: --enable-ntlm-wb)
1209 _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
1211 # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
1212 _add_if("TLS-SRP" USE_TLS_SRP)
1213 # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
1214 _add_if("HTTP2" USE_NGHTTP2)
1215 string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1216 message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1218 # Clear list and try to detect available protocols
1220 _add_if("HTTP" NOT CURL_DISABLE_HTTP)
1221 _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1222 _add_if("FTP" NOT CURL_DISABLE_FTP)
1223 _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1224 _add_if("FILE" NOT CURL_DISABLE_FILE)
1225 _add_if("TELNET" NOT CURL_DISABLE_TELNET)
1226 _add_if("LDAP" NOT CURL_DISABLE_LDAP)
1227 # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1228 # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
1229 _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
1230 ((USE_OPENLDAP AND SSL_ENABLED) OR
1231 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1232 _add_if("DICT" NOT CURL_DISABLE_DICT)
1233 _add_if("TFTP" NOT CURL_DISABLE_TFTP)
1234 _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
1235 _add_if("POP3" NOT CURL_DISABLE_POP3)
1236 _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1237 _add_if("IMAP" NOT CURL_DISABLE_IMAP)
1238 _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1239 _add_if("SMTP" NOT CURL_DISABLE_SMTP)
1240 _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1241 _add_if("SCP" USE_LIBSSH2)
1242 _add_if("SFTP" USE_LIBSSH2)
1243 _add_if("RTSP" NOT CURL_DISABLE_RTSP)
1244 _add_if("RTMP" USE_LIBRTMP)
1246 string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1247 message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1249 # curl-config needs the following options to be set.
1250 set(CC "${CMAKE_C_COMPILER}")
1251 # TODO probably put a -D... options here?
1252 set(CONFIGURE_OPTIONS "")
1253 # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
1254 set(CPPFLAG_CURL_STATICLIB "")
1255 set(CURLVERSION "${CURL_VERSION}")
1256 if(BUILD_SHARED_LIBS)
1257 set(ENABLE_SHARED "yes")
1258 set(ENABLE_STATIC "no")
1260 set(ENABLE_SHARED "no")
1261 set(ENABLE_STATIC "yes")
1263 set(exec_prefix "\${prefix}")
1264 set(includedir "\${prefix}/include")
1265 set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
1266 set(LIBCURL_LIBS "")
1267 set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
1268 foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
1269 if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
1270 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
1272 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
1275 # "a" (Linux) or "lib" (Windows)
1276 string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1277 set(prefix "${CMAKE_INSTALL_PREFIX}")
1278 # Set this to "yes" to append all libraries on which -lcurl is dependent
1279 set(REQUIRE_LIB_DEPS "no")
1282 set(VERSIONNUM "${CURL_VERSION_NUM}")
1284 # Finally generate a "curl-config" matching this config
1288 configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1289 "${CURL_BINARY_DIR}/curl-config" @ONLY)
1290 install(FILES "${CURL_BINARY_DIR}/curl-config"
1291 DESTINATION ${CMAKE_INSTALL_BINDIR}
1293 OWNER_READ OWNER_WRITE OWNER_EXECUTE
1294 GROUP_READ GROUP_EXECUTE
1295 WORLD_READ WORLD_EXECUTE)
1297 # Finally generate a pkg-config file matching this config
1298 configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1299 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
1300 install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
1301 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1304 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1305 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1306 FILES_MATCHING PATTERN "*.h")
1308 include(CMakePackageConfigHelpers)
1309 write_basic_package_version_file(
1311 VERSION ${CURL_VERSION}
1312 COMPATIBILITY SameMajorVersion
1316 # * TARGETS_EXPORT_NAME
1318 configure_package_config_file(CMake/curl-config.cmake.in
1320 INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1324 EXPORT "${TARGETS_EXPORT_NAME}"
1325 NAMESPACE "${PROJECT_NAME}::"
1326 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1330 FILES ${version_config} ${project_config}
1331 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1334 # Workaround for MSVS10 to avoid the Dialog Hell
1335 # FIXME: This could be removed with future version of CMake.
1336 if(MSVC_VERSION EQUAL 1600)
1337 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1338 if(EXISTS "${CURL_SLN_FILENAME}")
1339 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1343 if(NOT TARGET uninstall)
1345 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1346 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1349 add_custom_target(uninstall
1350 COMMAND ${CMAKE_COMMAND} -P
1351 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)