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