1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) 1998 - 2016, 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. 41cmake_minimum_required(VERSION 2.8 FATAL_ERROR) 42set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}") 43include(Utilities) 44include(Macros) 45include(CMakeDependentOption) 46 47project( CURL C ) 48 49message(WARNING "the curl cmake build system is poorly maintained. Be aware") 50 51file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS) 52string (REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*" 53 CURL_VERSION ${CURL_VERSION_H_CONTENTS}) 54string (REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION}) 55string (REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+" 56 CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS}) 57string (REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM}) 58 59include_regular_expression("^.*$") # Sukender: Is it necessary? 60 61# Setup package meta-data 62# SET(PACKAGE "curl") 63message(STATUS "curl version=[${CURL_VERSION}]") 64# SET(PACKAGE_TARNAME "curl") 65# SET(PACKAGE_NAME "curl") 66# SET(PACKAGE_VERSION "-") 67# SET(PACKAGE_STRING "curl-") 68# SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/") 69set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}") 70set(OS "\"${CMAKE_SYSTEM_NAME}\"") 71 72include_directories(${PROJECT_BINARY_DIR}/include/curl) 73include_directories( ${CURL_SOURCE_DIR}/include ) 74 75option(BUILD_CURL_EXE "Set to ON to build curl executable." ON) 76option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF) 77option(ENABLE_ARES "Set to ON to enable c-ares support" OFF) 78if(WIN32) 79 CMAKE_DEPENDENT_OPTION(ENABLE_THREADED_RESOLVER 80 "Set to ON to enable threaded DNS lookup" 81 ON "NOT ENABLE_ARES" 82 OFF) 83else() 84 option(ENABLE_THREADED_RESOLVER "Set to ON to enable POSIX threaded DNS lookup" OFF) 85endif() 86option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF) 87option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF) 88 89if (ENABLE_DEBUG) 90 # DEBUGBUILD will be defined only for Debug builds 91 if(NOT CMAKE_VERSION VERSION_LESS 3.0) 92 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>) 93 else() 94 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUGBUILD) 95 endif() 96 set(ENABLE_CURLDEBUG ON) 97endif() 98 99if (ENABLE_CURLDEBUG) 100 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG) 101endif() 102 103# initialize CURL_LIBS 104set(CURL_LIBS "") 105 106if(ENABLE_THREADED_RESOLVER AND ENABLE_ARES) 107 message(FATAL_ERROR "Options ENABLE_THREADED_RESOLVER and ENABLE_ARES are mutually exclusive") 108endif() 109 110if(ENABLE_ARES) 111 set(USE_ARES 1) 112 find_package(CARES REQUIRED) 113 list(APPEND CURL_LIBS ${CARES_LIBRARY} ) 114 set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY}) 115endif() 116 117if(MSVC) 118 option(BUILD_RELEASE_DEBUG_DIRS "Set OFF to build each configuration to a separate directory" OFF) 119 mark_as_advanced(BUILD_RELEASE_DEBUG_DIRS) 120endif() 121 122include(CurlSymbolHiding) 123 124option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF) 125mark_as_advanced(HTTP_ONLY) 126option(CURL_DISABLE_FTP "disables FTP" OFF) 127mark_as_advanced(CURL_DISABLE_FTP) 128option(CURL_DISABLE_LDAP "disables LDAP" OFF) 129mark_as_advanced(CURL_DISABLE_LDAP) 130option(CURL_DISABLE_TELNET "disables Telnet" OFF) 131mark_as_advanced(CURL_DISABLE_TELNET) 132option(CURL_DISABLE_DICT "disables DICT" OFF) 133mark_as_advanced(CURL_DISABLE_DICT) 134option(CURL_DISABLE_FILE "disables FILE" OFF) 135mark_as_advanced(CURL_DISABLE_FILE) 136option(CURL_DISABLE_TFTP "disables TFTP" OFF) 137mark_as_advanced(CURL_DISABLE_TFTP) 138option(CURL_DISABLE_HTTP "disables HTTP" OFF) 139mark_as_advanced(CURL_DISABLE_HTTP) 140 141option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF) 142mark_as_advanced(CURL_DISABLE_LDAPS) 143 144option(CURL_DISABLE_RTSP "to disable RTSP" OFF) 145mark_as_advanced(CURL_DISABLE_RTSP) 146option(CURL_DISABLE_PROXY "to disable proxy" OFF) 147mark_as_advanced(CURL_DISABLE_PROXY) 148option(CURL_DISABLE_POP3 "to disable POP3" OFF) 149mark_as_advanced(CURL_DISABLE_POP3) 150option(CURL_DISABLE_IMAP "to disable IMAP" OFF) 151mark_as_advanced(CURL_DISABLE_IMAP) 152option(CURL_DISABLE_SMTP "to disable SMTP" OFF) 153mark_as_advanced(CURL_DISABLE_SMTP) 154option(CURL_DISABLE_GOPHER "to disable Gopher" OFF) 155mark_as_advanced(CURL_DISABLE_GOPHER) 156 157if(HTTP_ONLY) 158 set(CURL_DISABLE_FTP ON) 159 set(CURL_DISABLE_LDAP ON) 160 set(CURL_DISABLE_LDAPS ON) 161 set(CURL_DISABLE_TELNET ON) 162 set(CURL_DISABLE_DICT ON) 163 set(CURL_DISABLE_FILE ON) 164 set(CURL_DISABLE_TFTP ON) 165 set(CURL_DISABLE_RTSP ON) 166 set(CURL_DISABLE_POP3 ON) 167 set(CURL_DISABLE_IMAP ON) 168 set(CURL_DISABLE_SMTP ON) 169 set(CURL_DISABLE_GOPHER ON) 170endif() 171 172option(CURL_DISABLE_COOKIES "to disable cookies support" OFF) 173mark_as_advanced(CURL_DISABLE_COOKIES) 174 175option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF) 176mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH) 177option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF) 178mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS) 179option(DISABLED_THREADSAFE "Set to explicitly specify we don't want to use thread-safe functions" OFF) 180mark_as_advanced(DISABLED_THREADSAFE) 181option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON) 182mark_as_advanced(ENABLE_IPV6) 183if(ENABLE_IPV6 AND NOT WIN32) 184 include(CheckStructHasMember) 185 check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h" 186 HAVE_SOCKADDR_IN6_SIN6_ADDR) 187 check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h" 188 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) 189 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR) 190 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support") 191 # Force the feature off as this name is used as guard macro... 192 set(ENABLE_IPV6 OFF 193 CACHE BOOL "Define if you want to enable IPv6 support" FORCE) 194 endif() 195endif() 196 197option(ENABLE_MANUAL "to provide the built-in manual" ON) 198unset(USE_MANUAL CACHE) # TODO: cache NROFF/NROFF_MANOPT/USE_MANUAL vars? 199if(ENABLE_MANUAL) 200 find_program(NROFF NAMES gnroff nroff) 201 if(NROFF) 202 # Need a way to write to stdin, this will do 203 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test") 204 # Tests for a valid nroff option to generate a manpage 205 foreach(_MANOPT "-man" "-mandoc") 206 execute_process(COMMAND "${NROFF}" ${_MANOPT} 207 OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT 208 INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" 209 ERROR_QUIET) 210 # Save the option if it was valid 211 if(NROFF_MANOPT_OUTPUT) 212 message("Found *nroff option: -- ${_MANOPT}") 213 set(NROFF_MANOPT ${_MANOPT}) 214 set(USE_MANUAL 1) 215 break() 216 endif() 217 endforeach() 218 # No need for the temporary file 219 file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt") 220 if(NOT USE_MANUAL) 221 message(WARNING "Found no *nroff option to get plaintext from man pages") 222 endif() 223 else() 224 message(WARNING "Found no *nroff program") 225 endif() 226endif() 227 228# We need ansi c-flags, especially on HP 229set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}") 230set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS}) 231 232# Disable warnings on Borland to avoid changing 3rd party code. 233if(BORLAND) 234 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-") 235endif(BORLAND) 236 237# If we are on AIX, do the _ALL_SOURCE magic 238if(${CMAKE_SYSTEM_NAME} MATCHES AIX) 239 set(_ALL_SOURCE 1) 240endif(${CMAKE_SYSTEM_NAME} MATCHES AIX) 241 242# Include all the necessary files for macros 243include (CheckFunctionExists) 244include (CheckIncludeFile) 245include (CheckIncludeFiles) 246include (CheckLibraryExists) 247include (CheckSymbolExists) 248include (CheckTypeSize) 249include (CheckCSourceCompiles) 250include (CMakeDependentOption) 251 252# On windows preload settings 253if(WIN32) 254 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_") 255 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake) 256endif(WIN32) 257 258if(ENABLE_THREADED_RESOLVER) 259 if(WIN32) 260 set(USE_THREADS_WIN32 ON) 261 else() 262 check_include_file_concat("pthread.h" HAVE_PTHREAD_H) 263 if(HAVE_PTHREAD_H) 264 set(CMAKE_THREAD_PREFER_PTHREAD 1) 265 find_package(Threads) 266 if(CMAKE_USE_PTHREADS_INIT) 267 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 268 set(USE_THREADS_POSIX 1) 269 endif() 270 endif() 271 endif() 272endif() 273 274# Check for all needed libraries 275check_library_exists_concat("dl" dlopen HAVE_LIBDL) 276check_library_exists_concat("socket" connect HAVE_LIBSOCKET) 277check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL) 278 279# Yellowtab Zeta needs different libraries than BeOS 5. 280if(BEOS) 281 set(NOT_NEED_LIBNSL 1) 282 check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND) 283 check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI) 284endif(BEOS) 285 286if(NOT NOT_NEED_LIBNSL) 287 check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL) 288endif(NOT NOT_NEED_LIBNSL) 289 290check_function_exists(gethostname HAVE_GETHOSTNAME) 291 292set(OPENSSL_DEFAULT ON) 293if(WIN32) 294 set(OPENSSL_DEFAULT OFF) 295 check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32) 296 check_library_exists_concat("winmm" getch HAVE_LIBWINMM) 297endif() 298 299option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${OPENSSL_DEFAULT}) 300mark_as_advanced(CMAKE_USE_OPENSSL) 301 302if(WIN32) 303 CMAKE_DEPENDENT_OPTION(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON 304 "NOT CMAKE_USE_OPENSSL" OFF) 305 mark_as_advanced(CURL_WINDOWS_SSPI) 306endif() 307 308set(USE_OPENSSL OFF) 309set(HAVE_LIBCRYPTO OFF) 310set(HAVE_LIBSSL OFF) 311 312if(CMAKE_USE_OPENSSL) 313 find_package(OpenSSL) 314 if(OPENSSL_FOUND) 315 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES}) 316 set(USE_OPENSSL ON) 317 set(HAVE_LIBCRYPTO ON) 318 set(HAVE_LIBSSL ON) 319 include_directories(${OPENSSL_INCLUDE_DIR}) 320 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) 321 check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H) 322 check_include_file("openssl/engine.h" HAVE_OPENSSL_ENGINE_H) 323 check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H) 324 check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H) 325 check_include_file("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H) 326 check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H) 327 check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H) 328 check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H) 329 check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H) 330 elseif(WIN32) 331 set(CURL_WINDOWS_SSPI ON) 332 endif() 333endif() 334 335option(USE_NGHTTP2 "Use Nghttp2 library" OFF) 336if(USE_NGHTTP2) 337 find_package(NGHTTP2 REQUIRED) 338 include_directories(${NGHTTP2_INCLUDE_DIRS}) 339 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES}) 340endif() 341 342if(NOT CURL_DISABLE_LDAP) 343 if(WIN32) 344 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON) 345 if(USE_WIN32_LDAP) 346 check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32) 347 if(NOT HAVE_WLDAP32) 348 set(USE_WIN32_LDAP OFF) 349 endif() 350 endif() 351 endif() 352 353 option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF) 354 mark_as_advanced(CMAKE_USE_OPENLDAP) 355 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library") 356 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library") 357 358 if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP) 359 message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time") 360 endif() 361 362 # Now that we know, we're not using windows LDAP... 363 if(USE_WIN32_LDAP) 364 check_include_file_concat("winldap.h" HAVE_WINLDAP_H) 365 check_include_file_concat("winber.h" HAVE_WINBER_H) 366 else() 367 # Check for LDAP 368 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}) 369 check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP) 370 check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER) 371 372 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES}) 373 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory") 374 if(CMAKE_LDAP_INCLUDE_DIR) 375 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR}) 376 endif() 377 check_include_file_concat("ldap.h" HAVE_LDAP_H) 378 check_include_file_concat("lber.h" HAVE_LBER_H) 379 380 if(NOT HAVE_LDAP_H) 381 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON") 382 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE) 383 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used 384 elseif(NOT HAVE_LIBLDAP) 385 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON") 386 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE) 387 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used 388 else() 389 if(CMAKE_USE_OPENLDAP) 390 set(USE_OPENLDAP ON) 391 endif() 392 if(CMAKE_LDAP_INCLUDE_DIR) 393 include_directories(${CMAKE_LDAP_INCLUDE_DIR}) 394 endif() 395 set(NEED_LBER_H ON) 396 set(_HEADER_LIST) 397 if(HAVE_WINDOWS_H) 398 list(APPEND _HEADER_LIST "windows.h") 399 endif() 400 if(HAVE_SYS_TYPES_H) 401 list(APPEND _HEADER_LIST "sys/types.h") 402 endif() 403 list(APPEND _HEADER_LIST "ldap.h") 404 405 set(_SRC_STRING "") 406 foreach(_HEADER ${_HEADER_LIST}) 407 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n") 408 endforeach() 409 410 set(_SRC_STRING 411 " 412 ${_INCLUDE_STRING} 413 int main(int argc, char ** argv) 414 { 415 BerValue *bvp = NULL; 416 BerElement *bep = ber_init(bvp); 417 ber_free(bep, 1); 418 return 0; 419 }" 420 ) 421 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1") 422 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB}) 423 if(HAVE_LIBLBER) 424 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB}) 425 endif() 426 check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H) 427 428 if(NOT_NEED_LBER_H) 429 set(NEED_LBER_H OFF) 430 else() 431 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H") 432 endif() 433 endif() 434 endif() 435 436endif() 437 438# No ldap, no ldaps. 439if(CURL_DISABLE_LDAP) 440 if(NOT CURL_DISABLE_LDAPS) 441 message(STATUS "LDAP needs to be enabled to support LDAPS") 442 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE) 443 endif() 444endif() 445 446if(NOT CURL_DISABLE_LDAPS) 447 check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H) 448 check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H) 449endif() 450 451# Check for idn 452check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2) 453 454# Check for symbol dlopen (same as HAVE_LIBDL) 455check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN) 456 457option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON) 458set(HAVE_LIBZ OFF) 459set(HAVE_ZLIB_H OFF) 460set(HAVE_ZLIB OFF) 461if(CURL_ZLIB) 462 find_package(ZLIB QUIET) 463 if(ZLIB_FOUND) 464 set(HAVE_ZLIB_H ON) 465 set(HAVE_ZLIB ON) 466 set(HAVE_LIBZ ON) 467 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES}) 468 include_directories(${ZLIB_INCLUDE_DIRS}) 469 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS}) 470 endif() 471endif() 472 473#libSSH2 474option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON) 475mark_as_advanced(CMAKE_USE_LIBSSH2) 476set(USE_LIBSSH2 OFF) 477set(HAVE_LIBSSH2 OFF) 478set(HAVE_LIBSSH2_H OFF) 479 480if(CMAKE_USE_LIBSSH2) 481 find_package(LibSSH2) 482 if(LIBSSH2_FOUND) 483 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY}) 484 set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY}) 485 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}") 486 include_directories("${LIBSSH2_INCLUDE_DIR}") 487 set(HAVE_LIBSSH2 ON) 488 set(USE_LIBSSH2 ON) 489 490 # find_package has already found the headers 491 set(HAVE_LIBSSH2_H ON) 492 set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h") 493 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H") 494 495 # now check for specific libssh2 symbols as they were added in different versions 496 set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h") 497 check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION) 498 check_function_exists(libssh2_init HAVE_LIBSSH2_INIT) 499 check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT) 500 check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64) 501 check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE) 502 set(CMAKE_EXTRA_INCLUDE_FILES "") 503 504 endif(LIBSSH2_FOUND) 505endif(CMAKE_USE_LIBSSH2) 506 507option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF) 508mark_as_advanced(CMAKE_USE_GSSAPI) 509 510if(CMAKE_USE_GSSAPI) 511 find_package(GSS) 512 513 set(HAVE_GSSAPI ${GSS_FOUND}) 514 if(GSS_FOUND) 515 516 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"") 517 518 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRECTORIES}) 519 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H) 520 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H) 521 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H) 522 523 if(GSS_FLAVOUR STREQUAL "Heimdal") 524 set(HAVE_GSSHEIMDAL ON) 525 else() # MIT 526 set(HAVE_GSSMIT ON) 527 set(_INCLUDE_LIST "") 528 if(HAVE_GSSAPI_GSSAPI_H) 529 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h") 530 endif() 531 if(HAVE_GSSAPI_GSSAPI_GENERIC_H) 532 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h") 533 endif() 534 if(HAVE_GSSAPI_GSSAPI_KRB5_H) 535 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h") 536 endif() 537 538 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}") 539 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}") 540 541 foreach(_dir ${GSS_LINK_DIRECTORIES}) 542 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"") 543 endforeach() 544 545 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}") 546 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES}) 547 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE) 548 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE) 549 set(HAVE_OLD_GSSMIT ON) 550 endif() 551 552 endif() 553 554 include_directories(${GSS_INCLUDE_DIRECTORIES}) 555 link_directories(${GSS_LINK_DIRECTORIES}) 556 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}") 557 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}") 558 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}") 559 list(APPEND CURL_LIBS ${GSS_LIBRARIES}) 560 561 else() 562 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.") 563 endif() 564endif() 565 566option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON) 567if(ENABLE_UNIX_SOCKETS) 568 include(CheckStructHasMember) 569 check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS) 570else() 571 unset(USE_UNIX_SOCKETS CACHE) 572endif() 573 574 575# Check for header files 576if(NOT UNIX) 577 check_include_file_concat("windows.h" HAVE_WINDOWS_H) 578 check_include_file_concat("winsock.h" HAVE_WINSOCK_H) 579 check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H) 580 check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H) 581 if(CURL_WINDOWS_SSPI) 582 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32") 583 check_include_file_concat("sspi.h" HAVE_SSPI_H) 584 if(HAVE_SSPI_H) 585 check_include_file_concat("schannel.h" HAVE_SCHANNEL_H) 586 set(USE_WINDOWS_SSPI ON) 587 if(HAVE_SCHANNEL_H) 588 set(USE_SCHANNEL ON) 589 set(SSL_ENABLED ON) 590 set(CURL_LIBS ${CURL_LIBS} "crypt32") 591 endif() 592 endif() 593 endif() 594endif(NOT UNIX) 595 596check_include_file_concat("stdio.h" HAVE_STDIO_H) 597check_include_file_concat("inttypes.h" HAVE_INTTYPES_H) 598check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H) 599check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H) 600check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H) 601check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H) 602check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H) 603check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H) 604check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H) 605check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H) 606check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H) 607check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H) 608check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H) 609check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H) 610check_include_file_concat("sys/un.h" HAVE_SYS_UN_H) 611check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H) 612check_include_file_concat("alloca.h" HAVE_ALLOCA_H) 613check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H) 614check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H) 615check_include_file_concat("assert.h" HAVE_ASSERT_H) 616check_include_file_concat("crypto.h" HAVE_CRYPTO_H) 617check_include_file_concat("des.h" HAVE_DES_H) 618check_include_file_concat("err.h" HAVE_ERR_H) 619check_include_file_concat("errno.h" HAVE_ERRNO_H) 620check_include_file_concat("fcntl.h" HAVE_FCNTL_H) 621check_include_file_concat("idn2.h" HAVE_IDN2_H) 622check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H) 623check_include_file_concat("io.h" HAVE_IO_H) 624check_include_file_concat("krb.h" HAVE_KRB_H) 625check_include_file_concat("libgen.h" HAVE_LIBGEN_H) 626check_include_file_concat("limits.h" HAVE_LIMITS_H) 627check_include_file_concat("locale.h" HAVE_LOCALE_H) 628check_include_file_concat("net/if.h" HAVE_NET_IF_H) 629check_include_file_concat("netdb.h" HAVE_NETDB_H) 630check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H) 631check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H) 632 633check_include_file_concat("pem.h" HAVE_PEM_H) 634check_include_file_concat("poll.h" HAVE_POLL_H) 635check_include_file_concat("pwd.h" HAVE_PWD_H) 636check_include_file_concat("rsa.h" HAVE_RSA_H) 637check_include_file_concat("setjmp.h" HAVE_SETJMP_H) 638check_include_file_concat("sgtty.h" HAVE_SGTTY_H) 639check_include_file_concat("signal.h" HAVE_SIGNAL_H) 640check_include_file_concat("ssl.h" HAVE_SSL_H) 641check_include_file_concat("stdbool.h" HAVE_STDBOOL_H) 642check_include_file_concat("stdint.h" HAVE_STDINT_H) 643check_include_file_concat("stdio.h" HAVE_STDIO_H) 644check_include_file_concat("stdlib.h" HAVE_STDLIB_H) 645check_include_file_concat("string.h" HAVE_STRING_H) 646check_include_file_concat("strings.h" HAVE_STRINGS_H) 647check_include_file_concat("stropts.h" HAVE_STROPTS_H) 648check_include_file_concat("termio.h" HAVE_TERMIO_H) 649check_include_file_concat("termios.h" HAVE_TERMIOS_H) 650check_include_file_concat("time.h" HAVE_TIME_H) 651check_include_file_concat("unistd.h" HAVE_UNISTD_H) 652check_include_file_concat("utime.h" HAVE_UTIME_H) 653check_include_file_concat("x509.h" HAVE_X509_H) 654 655check_include_file_concat("process.h" HAVE_PROCESS_H) 656check_include_file_concat("stddef.h" HAVE_STDDEF_H) 657check_include_file_concat("dlfcn.h" HAVE_DLFCN_H) 658check_include_file_concat("malloc.h" HAVE_MALLOC_H) 659check_include_file_concat("memory.h" HAVE_MEMORY_H) 660check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H) 661check_include_file_concat("stdint.h" HAVE_STDINT_H) 662check_include_file_concat("sockio.h" HAVE_SOCKIO_H) 663check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H) 664 665check_type_size(size_t SIZEOF_SIZE_T) 666check_type_size(ssize_t SIZEOF_SSIZE_T) 667check_type_size("long long" SIZEOF_LONG_LONG) 668check_type_size("long" SIZEOF_LONG) 669check_type_size("short" SIZEOF_SHORT) 670check_type_size("int" SIZEOF_INT) 671check_type_size("__int64" SIZEOF___INT64) 672check_type_size("long double" SIZEOF_LONG_DOUBLE) 673check_type_size("time_t" SIZEOF_TIME_T) 674if(NOT HAVE_SIZEOF_SSIZE_T) 675 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T) 676 set(ssize_t long) 677 endif(SIZEOF_LONG EQUAL SIZEOF_SIZE_T) 678 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T) 679 set(ssize_t __int64) 680 endif(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T) 681endif(NOT HAVE_SIZEOF_SSIZE_T) 682# off_t is sized later, after the HAVE_FILE_OFFSET_BITS test 683 684# Different sizeofs, etc. 685 686# define CURL_SIZEOF_LONG 4 687# define CURL_TYPEOF_CURL_OFF_T long long 688# define CURL_FORMAT_CURL_OFF_T "lld" 689# define CURL_FORMAT_CURL_OFF_TU "llu" 690# define CURL_FORMAT_OFF_T "%lld" 691# define CURL_SIZEOF_CURL_OFF_T 8 692# define CURL_SUFFIX_CURL_OFF_T LL 693# define CURL_SUFFIX_CURL_OFF_TU ULL 694 695set(CURL_SIZEOF_LONG ${SIZEOF_LONG}) 696 697if(SIZEOF_LONG EQUAL 8) 698 set(CURL_TYPEOF_CURL_OFF_T long) 699 set(CURL_SIZEOF_CURL_OFF_T 8) 700 set(CURL_FORMAT_CURL_OFF_T "ld") 701 set(CURL_FORMAT_CURL_OFF_TU "lu") 702 set(CURL_FORMAT_OFF_T "%ld") 703 set(CURL_SUFFIX_CURL_OFF_T L) 704 set(CURL_SUFFIX_CURL_OFF_TU UL) 705endif(SIZEOF_LONG EQUAL 8) 706 707if(SIZEOF_LONG_LONG EQUAL 8) 708 set(CURL_TYPEOF_CURL_OFF_T "long long") 709 set(CURL_SIZEOF_CURL_OFF_T 8) 710 set(CURL_FORMAT_CURL_OFF_T "lld") 711 set(CURL_FORMAT_CURL_OFF_TU "llu") 712 set(CURL_FORMAT_OFF_T "%lld") 713 set(CURL_SUFFIX_CURL_OFF_T LL) 714 set(CURL_SUFFIX_CURL_OFF_TU ULL) 715endif(SIZEOF_LONG_LONG EQUAL 8) 716 717if(NOT CURL_TYPEOF_CURL_OFF_T) 718 set(CURL_TYPEOF_CURL_OFF_T ${ssize_t}) 719 set(CURL_SIZEOF_CURL_OFF_T ${SIZEOF_SSIZE_T}) 720 # TODO: need adjustment here. 721 set(CURL_FORMAT_CURL_OFF_T "ld") 722 set(CURL_FORMAT_CURL_OFF_TU "lu") 723 set(CURL_FORMAT_OFF_T "%ld") 724 set(CURL_SUFFIX_CURL_OFF_T L) 725 set(CURL_SUFFIX_CURL_OFF_TU LU) 726endif(NOT CURL_TYPEOF_CURL_OFF_T) 727 728if(HAVE_SIZEOF_LONG_LONG) 729 set(HAVE_LONGLONG 1) 730 set(HAVE_LL 1) 731endif(HAVE_SIZEOF_LONG_LONG) 732 733find_file(RANDOM_FILE urandom /dev) 734mark_as_advanced(RANDOM_FILE) 735 736# Check for some functions that are used 737if(HAVE_LIBWS2_32) 738 set(CMAKE_REQUIRED_LIBRARIES ws2_32) 739elseif(HAVE_LIBSOCKET) 740 set(CMAKE_REQUIRED_LIBRARIES socket) 741endif() 742 743check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME) 744check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET) 745# poll on macOS is unreliable, it first did not exist, then was broken until 746# fixed in 10.9 only to break again in 10.12. 747if(NOT APPLE) 748 check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL) 749endif() 750check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT) 751check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP) 752check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR) 753check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R) 754check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME) 755check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME) 756check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP) 757check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP) 758check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI) 759check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI) 760check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM) 761if(NOT HAVE_STRNCMPI) 762 set(HAVE_STRCMPI) 763endif(NOT HAVE_STRNCMPI) 764check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR) 765check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R) 766check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY) 767check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR) 768check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA) 769check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R) 770check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR) 771check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR) 772check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR) 773check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET) 774check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF) 775check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP) 776check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R) 777check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT) 778check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID) 779check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID) 780check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME) 781if(CMAKE_USE_OPENSSL) 782 check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS) 783 check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN) 784 check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD) 785 if(HAVE_LIBCRYPTO AND HAVE_LIBSSL) 786 set(USE_OPENSSL 1) 787 endif(HAVE_LIBCRYPTO AND HAVE_LIBSSL) 788endif(CMAKE_USE_OPENSSL) 789check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R) 790check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R) 791 792check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME) 793check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R) 794 795check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC) 796check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO) 797if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO) 798 set(HAVE_SIGNAL 1) 799endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO) 800check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME) 801check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL) 802check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64) 803check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R) 804check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT) 805check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR) 806check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK) 807check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO) 808check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO) 809check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS) 810check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE) 811check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE) 812check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME) 813check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT) 814check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE) 815check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT) 816check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL) 817check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL) 818check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT) 819 820# symbol exists in win32, but function does not. 821check_function_exists(inet_pton HAVE_INET_PTON) 822 823# sigaction and sigsetjmp are special. Use special mechanism for 824# detecting those, but only if previous attempt failed. 825if(HAVE_SIGNAL_H) 826 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION) 827endif(HAVE_SIGNAL_H) 828 829if(NOT HAVE_SIGSETJMP) 830 if(HAVE_SETJMP_H) 831 check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP) 832 if(HAVE_MACRO_SIGSETJMP) 833 set(HAVE_SIGSETJMP 1) 834 endif(HAVE_MACRO_SIGSETJMP) 835 endif(HAVE_SETJMP_H) 836endif(NOT HAVE_SIGSETJMP) 837 838# If there is no stricmp(), do not allow LDAP to parse URLs 839if(NOT HAVE_STRICMP) 840 set(HAVE_LDAP_URL_PARSE 1) 841endif(NOT HAVE_STRICMP) 842 843# Do curl specific tests 844foreach(CURL_TEST 845 HAVE_FCNTL_O_NONBLOCK 846 HAVE_IOCTLSOCKET 847 HAVE_IOCTLSOCKET_CAMEL 848 HAVE_IOCTLSOCKET_CAMEL_FIONBIO 849 HAVE_IOCTLSOCKET_FIONBIO 850 HAVE_IOCTL_FIONBIO 851 HAVE_IOCTL_SIOCGIFADDR 852 HAVE_SETSOCKOPT_SO_NONBLOCK 853 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 854 TIME_WITH_SYS_TIME 855 HAVE_O_NONBLOCK 856 HAVE_GETHOSTBYADDR_R_5 857 HAVE_GETHOSTBYADDR_R_7 858 HAVE_GETHOSTBYADDR_R_8 859 HAVE_GETHOSTBYADDR_R_5_REENTRANT 860 HAVE_GETHOSTBYADDR_R_7_REENTRANT 861 HAVE_GETHOSTBYADDR_R_8_REENTRANT 862 HAVE_GETHOSTBYNAME_R_3 863 HAVE_GETHOSTBYNAME_R_5 864 HAVE_GETHOSTBYNAME_R_6 865 HAVE_GETHOSTBYNAME_R_3_REENTRANT 866 HAVE_GETHOSTBYNAME_R_5_REENTRANT 867 HAVE_GETHOSTBYNAME_R_6_REENTRANT 868 HAVE_SOCKLEN_T 869 HAVE_IN_ADDR_T 870 HAVE_BOOL_T 871 STDC_HEADERS 872 RETSIGTYPE_TEST 873 HAVE_INET_NTOA_R_DECL 874 HAVE_INET_NTOA_R_DECL_REENTRANT 875 HAVE_GETADDRINFO 876 HAVE_FILE_OFFSET_BITS 877 ) 878 curl_internal_test(${CURL_TEST}) 879endforeach(CURL_TEST) 880 881if(HAVE_FILE_OFFSET_BITS) 882 set(_FILE_OFFSET_BITS 64) 883 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64") 884endif(HAVE_FILE_OFFSET_BITS) 885check_type_size("off_t" SIZEOF_OFF_T) 886set(CMAKE_REQUIRED_FLAGS) 887 888foreach(CURL_TEST 889 HAVE_GLIBC_STRERROR_R 890 HAVE_POSIX_STRERROR_R 891 ) 892 curl_internal_test_run(${CURL_TEST}) 893endforeach(CURL_TEST) 894 895# Check for reentrant 896foreach(CURL_TEST 897 HAVE_GETHOSTBYADDR_R_5 898 HAVE_GETHOSTBYADDR_R_7 899 HAVE_GETHOSTBYADDR_R_8 900 HAVE_GETHOSTBYNAME_R_3 901 HAVE_GETHOSTBYNAME_R_5 902 HAVE_GETHOSTBYNAME_R_6 903 HAVE_INET_NTOA_R_DECL_REENTRANT) 904 if(NOT ${CURL_TEST}) 905 if(${CURL_TEST}_REENTRANT) 906 set(NEED_REENTRANT 1) 907 endif(${CURL_TEST}_REENTRANT) 908 endif(NOT ${CURL_TEST}) 909endforeach(CURL_TEST) 910 911if(NEED_REENTRANT) 912 foreach(CURL_TEST 913 HAVE_GETHOSTBYADDR_R_5 914 HAVE_GETHOSTBYADDR_R_7 915 HAVE_GETHOSTBYADDR_R_8 916 HAVE_GETHOSTBYNAME_R_3 917 HAVE_GETHOSTBYNAME_R_5 918 HAVE_GETHOSTBYNAME_R_6) 919 set(${CURL_TEST} 0) 920 if(${CURL_TEST}_REENTRANT) 921 set(${CURL_TEST} 1) 922 endif(${CURL_TEST}_REENTRANT) 923 endforeach(CURL_TEST) 924endif(NEED_REENTRANT) 925 926if(HAVE_INET_NTOA_R_DECL_REENTRANT) 927 set(HAVE_INET_NTOA_R_DECL 1) 928 set(NEED_REENTRANT 1) 929endif(HAVE_INET_NTOA_R_DECL_REENTRANT) 930 931# Some other minor tests 932 933if(NOT HAVE_IN_ADDR_T) 934 set(in_addr_t "unsigned long") 935endif(NOT HAVE_IN_ADDR_T) 936 937# Fix libz / zlib.h 938 939if(NOT CURL_SPECIAL_LIBZ) 940 if(NOT HAVE_LIBZ) 941 set(HAVE_ZLIB_H 0) 942 endif(NOT HAVE_LIBZ) 943 944 if(NOT HAVE_ZLIB_H) 945 set(HAVE_LIBZ 0) 946 endif(NOT HAVE_ZLIB_H) 947endif(NOT CURL_SPECIAL_LIBZ) 948 949# Check for nonblocking 950set(HAVE_DISABLED_NONBLOCKING 1) 951if(HAVE_FIONBIO OR 952 HAVE_IOCTLSOCKET OR 953 HAVE_IOCTLSOCKET_CASE OR 954 HAVE_O_NONBLOCK) 955 set(HAVE_DISABLED_NONBLOCKING) 956endif(HAVE_FIONBIO OR 957 HAVE_IOCTLSOCKET OR 958 HAVE_IOCTLSOCKET_CASE OR 959 HAVE_O_NONBLOCK) 960 961if(RETSIGTYPE_TEST) 962 set(RETSIGTYPE void) 963else(RETSIGTYPE_TEST) 964 set(RETSIGTYPE int) 965endif(RETSIGTYPE_TEST) 966 967if(CMAKE_COMPILER_IS_GNUCC AND APPLE) 968 include(CheckCCompilerFlag) 969 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double) 970 if(HAVE_C_FLAG_Wno_long_double) 971 # The Mac version of GCC warns about use of long double. Disable it. 972 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS) 973 if(MPRINTF_COMPILE_FLAGS) 974 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double") 975 else(MPRINTF_COMPILE_FLAGS) 976 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double") 977 endif(MPRINTF_COMPILE_FLAGS) 978 set_source_files_properties(mprintf.c PROPERTIES 979 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS}) 980 endif(HAVE_C_FLAG_Wno_long_double) 981endif(CMAKE_COMPILER_IS_GNUCC AND APPLE) 982 983if(HAVE_SOCKLEN_T) 984 set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t") 985 if(WIN32) 986 set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h;ws2tcpip.h") 987 elseif(HAVE_SYS_SOCKET_H) 988 set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h") 989 endif() 990 check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T) 991 set(CMAKE_EXTRA_INCLUDE_FILES) 992 if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T) 993 message(FATAL_ERROR 994 "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log") 995 endif() 996else() 997 set(CURL_TYPEOF_CURL_SOCKLEN_T int) 998 set(CURL_SIZEOF_CURL_SOCKLEN_T ${SIZEOF_INT}) 999endif() 1000 1001# TODO test which of these headers are required for the typedefs used in curlbuild.h 1002if(WIN32) 1003 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H}) 1004else() 1005 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H}) 1006 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H}) 1007 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H}) 1008endif() 1009set(CURL_PULL_STDINT_H ${HAVE_STDINT_H}) 1010set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H}) 1011 1012include(CMake/OtherTests.cmake) 1013 1014add_definitions(-DHAVE_CONFIG_H) 1015 1016# For windows, do not allow the compiler to use default target (Vista). 1017if(WIN32) 1018 add_definitions(-D_WIN32_WINNT=0x0501) 1019endif(WIN32) 1020 1021# For windows, all compilers used by cmake should support large files 1022if(WIN32) 1023 set(USE_WIN32_LARGE_FILES ON) 1024endif(WIN32) 1025 1026if(MSVC) 1027 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) 1028endif(MSVC) 1029 1030# Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it). 1031function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE) 1032 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT) 1033 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1034 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1035 1036 string(REGEX REPLACE "\\\\\n" "�!�" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1037 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1038 string(REPLACE "�!�" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) 1039 1040 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${} 1041 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. 1042 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT}) 1043 1044endfunction() 1045 1046add_subdirectory(lib) 1047if(BUILD_CURL_EXE) 1048 add_subdirectory(src) 1049endif() 1050 1051include(CTest) 1052if(BUILD_TESTING) 1053 add_subdirectory(tests) 1054endif() 1055 1056# TODO support GNUTLS, NSS, POLARSSL, AXTLS, CYASSL, WINSSL, DARWINSSL 1057if(USE_OPENSSL) 1058 set(SSL_ENABLED 1) 1059endif() 1060 1061# Helper to populate a list (_items) with a label when conditions (the remaining 1062# args) are satisfied 1063function(_add_if label) 1064 # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection 1065 if(${ARGN}) 1066 set(_items ${_items} "${label}" PARENT_SCOPE) 1067 endif() 1068endfunction() 1069 1070# Clear list and try to detect available features 1071set(_items) 1072_add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI) 1073_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL) 1074_add_if("IPv6" ENABLE_IPV6) 1075_add_if("unix-sockets" USE_UNIX_SOCKETS) 1076_add_if("libz" HAVE_LIBZ) 1077_add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32) 1078_add_if("IDN" HAVE_LIBIDN2) 1079_add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND 1080 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES)) 1081# TODO SSP1 (WinSSL) check is missing 1082_add_if("SSPI" USE_WINDOWS_SSPI) 1083_add_if("GSS-API" HAVE_GSSAPI) 1084# TODO SSP1 missing for SPNEGO 1085_add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND 1086 (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) 1087_add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND 1088 (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) 1089# NTLM support requires crypto function adaptions from various SSL libs 1090# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS, DARWINSSL 1091if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR 1092 USE_WINDOWS_SSPI OR GNUTLS_ENABLED OR NSS_ENABLED OR DARWINSSL_ENABLED)) 1093 _add_if("NTLM" 1) 1094 # TODO missing option (autoconf: --enable-ntlm-wb) 1095 _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED) 1096endif() 1097# TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP 1098_add_if("TLS-SRP" USE_TLS_SRP) 1099# TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header 1100_add_if("HTTP2" USE_NGHTTP2) 1101string(REPLACE ";" " " SUPPORT_FEATURES "${_items}") 1102message(STATUS "Enabled features: ${SUPPORT_FEATURES}") 1103 1104# Clear list and try to detect available protocols 1105set(_items) 1106_add_if("HTTP" NOT CURL_DISABLE_HTTP) 1107_add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED) 1108_add_if("FTP" NOT CURL_DISABLE_FTP) 1109_add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED) 1110_add_if("FILE" NOT CURL_DISABLE_FILE) 1111_add_if("TELNET" NOT CURL_DISABLE_TELNET) 1112_add_if("LDAP" NOT CURL_DISABLE_LDAP) 1113# CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS 1114# TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps) 1115_add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND 1116 ((USE_OPENLDAP AND SSL_ENABLED) OR 1117 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL))) 1118_add_if("DICT" NOT CURL_DISABLE_DICT) 1119_add_if("TFTP" NOT CURL_DISABLE_TFTP) 1120_add_if("GOPHER" NOT CURL_DISABLE_GOPHER) 1121_add_if("POP3" NOT CURL_DISABLE_POP3) 1122_add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED) 1123_add_if("IMAP" NOT CURL_DISABLE_IMAP) 1124_add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED) 1125_add_if("SMTP" NOT CURL_DISABLE_SMTP) 1126_add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED) 1127_add_if("SCP" USE_LIBSSH2) 1128_add_if("SFTP" USE_LIBSSH2) 1129_add_if("RTSP" NOT CURL_DISABLE_RTSP) 1130_add_if("RTMP" USE_LIBRTMP) 1131list(SORT _items) 1132string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}") 1133message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}") 1134 1135# curl-config needs the following options to be set. 1136set(CC "${CMAKE_C_COMPILER}") 1137# TODO probably put a -D... options here? 1138set(CONFIGURE_OPTIONS "") 1139# TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB? 1140set(CPPFLAG_CURL_STATICLIB "") 1141# TODO need to set this (see CURL_CHECK_CA_BUNDLE in acinclude.m4) 1142set(CURL_CA_BUNDLE "") 1143set(CURLVERSION "${CURL_VERSION}") 1144set(ENABLE_SHARED "yes") 1145if(CURL_STATICLIB) 1146 set(ENABLE_STATIC "yes") 1147else() 1148 set(ENABLE_STATIC "no") 1149endif() 1150set(exec_prefix "\${prefix}") 1151set(includedir "\${prefix}/include") 1152set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}") 1153set(LIBCURL_LIBS "") 1154set(libdir "${CMAKE_INSTALL_PREFIX}/lib") 1155foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS}) 1156 if(_lib MATCHES ".*/.*") 1157 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}") 1158 else() 1159 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}") 1160 endif() 1161endforeach() 1162# "a" (Linux) or "lib" (Windows) 1163string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}") 1164set(prefix "${CMAKE_INSTALL_PREFIX}") 1165# Set this to "yes" to append all libraries on which -lcurl is dependent 1166set(REQUIRE_LIB_DEPS "no") 1167# SUPPORT_FEATURES 1168# SUPPORT_PROTOCOLS 1169set(VERSIONNUM "${CURL_VERSION_NUM}") 1170 1171# Finally generate a "curl-config" matching this config 1172configure_file("${CURL_SOURCE_DIR}/curl-config.in" 1173 "${CURL_BINARY_DIR}/curl-config" @ONLY) 1174install(FILES "${CURL_BINARY_DIR}/curl-config" 1175 DESTINATION bin 1176 PERMISSIONS 1177 OWNER_READ OWNER_WRITE OWNER_EXECUTE 1178 GROUP_READ GROUP_EXECUTE 1179 WORLD_READ WORLD_EXECUTE) 1180 1181# Finally generate a pkg-config file matching this config 1182configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in" 1183 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY) 1184install(FILES "${CURL_BINARY_DIR}/libcurl.pc" 1185 DESTINATION lib/pkgconfig) 1186 1187# This needs to be run very last so other parts of the scripts can take advantage of this. 1188if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE) 1189 set(CURL_CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track whether this is the first time running CMake or if CMake has been configured before") 1190endif() 1191 1192# Installation. 1193# First, install generated curlbuild.h 1194install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/curl/curlbuild.h" 1195 DESTINATION include/curl ) 1196# Next, install other headers excluding curlbuild.h 1197install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl" 1198 DESTINATION include 1199 FILES_MATCHING PATTERN "*.h" 1200 PATTERN "curlbuild.h" EXCLUDE) 1201 1202 1203# Workaround for MSVS10 to avoid the Dialog Hell 1204# FIXME: This could be removed with future version of CMake. 1205if(MSVC_VERSION EQUAL 1600) 1206 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln") 1207 if(EXISTS "${CURL_SLN_FILENAME}") 1208 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n") 1209 endif() 1210endif() 1211