Annotation of embedaddon/curl/CMakeLists.txt, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>