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