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