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