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.
41cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)
42set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
43include(Utilities)
44
45project( CURL C )
46
47message(WARNING "the curl cmake build system is poorly maintained. Be aware")
48
49file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
50string (REGEX MATCH "LIBCURL_VERSION_MAJOR[ \t]+([0-9]+)"
51  LIBCURL_VERSION_MJ ${CURL_VERSION_H_CONTENTS})
52string (REGEX MATCH "([0-9]+)"
53  LIBCURL_VERSION_MJ ${LIBCURL_VERSION_MJ})
54string (REGEX MATCH
55  "LIBCURL_VERSION_MINOR[ \t]+([0-9]+)"
56  LIBCURL_VERSION_MI ${CURL_VERSION_H_CONTENTS})
57string (REGEX MATCH "([0-9]+)" LIBCURL_VERSION_MI ${LIBCURL_VERSION_MI})
58string (REGEX MATCH
59  "LIBCURL_VERSION_PATCH[ \t]+([0-9]+)"
60  LIBCURL_VERSION_PT ${CURL_VERSION_H_CONTENTS})
61string (REGEX MATCH "([0-9]+)" LIBCURL_VERSION_PT ${LIBCURL_VERSION_PT})
62set (CURL_MAJOR_VERSION ${LIBCURL_VERSION_MJ})
63set (CURL_MINOR_VERSION ${LIBCURL_VERSION_MI})
64set (CURL_PATCH_VERSION ${LIBCURL_VERSION_PT})
65
66include_regular_expression("^.*$")    # Sukender: Is it necessary?
67
68# Setup package meta-data
69# SET(PACKAGE "curl")
70set(CURL_VERSION ${CURL_MAJOR_VERSION}.${CURL_MINOR_VERSION}.${CURL_PATCH_VERSION})
71message(STATUS "curl version=[${CURL_VERSION}]")
72# SET(PACKAGE_TARNAME "curl")
73# SET(PACKAGE_NAME "curl")
74# SET(PACKAGE_VERSION "-")
75# SET(PACKAGE_STRING "curl-")
76# SET(PACKAGE_BUGREPORT "a suitable curl mailing list => http://curl.haxx.se/mail/")
77set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
78set(OS "\"${CMAKE_SYSTEM_NAME}\"")
79
80include_directories(${PROJECT_BINARY_DIR}/include/curl)
81include_directories( ${CURL_SOURCE_DIR}/include )
82
83option(BUILD_CURL_EXE "Set to ON to build cURL executable." ON)
84option(BUILD_CURL_TESTS "Set to ON to build cURL tests." ON)
85option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF)
86option(CURL_USE_ARES "Set to ON to enable c-ares support" OFF)
87# initialize CURL_LIBS
88set(CURL_LIBS "")
89
90if(CURL_USE_ARES)
91  set(USE_ARES ${CURL_USE_ARES})
92  find_package(CARES REQUIRED)
93  list(APPEND CURL_LIBS ${CARES_LIBRARY} )
94  set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
95endif()
96
97option(BUILD_DASHBOARD_REPORTS "Set to ON to activate reporting of cURL builds here http://www.cdash.org/CDashPublic/index.php?project=CURL" OFF)
98if(BUILD_DASHBOARD_REPORTS)
99  #INCLUDE(Dart)
100  include(CTest)
101endif(BUILD_DASHBOARD_REPORTS)
102
103if(MSVC)
104  option(BUILD_RELEASE_DEBUG_DIRS "Set OFF to build each configuration to a separate directory" OFF)
105  mark_as_advanced(BUILD_RELEASE_DEBUG_DIRS)
106endif()
107
108option(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide all symbols that aren't officially external)." ON)
109mark_as_advanced(CURL_HIDDEN_SYMBOLS)
110
111# IF(WIN32)
112# OPTION(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON)
113# MARK_AS_ADVANCED(CURL_WINDOWS_SSPI)
114# ENDIF()
115
116option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
117mark_as_advanced(HTTP_ONLY)
118option(CURL_DISABLE_FTP "disables FTP" OFF)
119mark_as_advanced(CURL_DISABLE_FTP)
120option(CURL_DISABLE_LDAP "disables LDAP" OFF)
121mark_as_advanced(CURL_DISABLE_LDAP)
122option(CURL_DISABLE_TELNET "disables Telnet" OFF)
123mark_as_advanced(CURL_DISABLE_TELNET)
124option(CURL_DISABLE_DICT "disables DICT" OFF)
125mark_as_advanced(CURL_DISABLE_DICT)
126option(CURL_DISABLE_FILE "disables FILE" OFF)
127mark_as_advanced(CURL_DISABLE_FILE)
128option(CURL_DISABLE_TFTP "disables TFTP" OFF)
129mark_as_advanced(CURL_DISABLE_TFTP)
130option(CURL_DISABLE_HTTP "disables HTTP" OFF)
131mark_as_advanced(CURL_DISABLE_HTTP)
132
133option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
134mark_as_advanced(CURL_DISABLE_LDAPS)
135
136if(HTTP_ONLY)
137  set(CURL_DISABLE_FTP ON)
138  set(CURL_DISABLE_LDAP ON)
139  set(CURL_DISABLE_LDAPS ON)
140  set(CURL_DISABLE_TELNET ON)
141  set(CURL_DISABLE_DICT ON)
142  set(CURL_DISABLE_FILE ON)
143  set(CURL_DISABLE_TFTP ON)
144endif()
145
146option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
147mark_as_advanced(CURL_DISABLE_COOKIES)
148
149option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
150mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
151option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
152mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
153option(DISABLED_THREADSAFE "Set to explicitly specify we don't want to use thread-safe functions" OFF)
154mark_as_advanced(DISABLED_THREADSAFE)
155option(ENABLE_IPV6 "Define if you want to enable IPv6 support" OFF)
156mark_as_advanced(ENABLE_IPV6)
157
158
159# We need ansi c-flags, especially on HP
160set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
161set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
162
163# Disable warnings on Borland to avoid changing 3rd party code.
164if(BORLAND)
165  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
166endif(BORLAND)
167
168# If we are on AIX, do the _ALL_SOURCE magic
169if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
170  set(_ALL_SOURCE 1)
171endif(${CMAKE_SYSTEM_NAME} MATCHES AIX)
172
173# Include all the necessary files for macros
174include (CheckFunctionExists)
175include (CheckIncludeFile)
176include (CheckIncludeFiles)
177include (CheckLibraryExists)
178include (CheckSymbolExists)
179include (CheckTypeSize)
180
181# On windows preload settings
182if(WIN32)
183  include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
184endif(WIN32)
185
186# This macro checks if the symbol exists in the library and if it
187# does, it prepends library to the list.
188macro(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
189  check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
190    ${VARIABLE})
191  if(${VARIABLE})
192    set(CURL_LIBS ${LIBRARY} ${CURL_LIBS})
193  endif(${VARIABLE})
194endmacro(CHECK_LIBRARY_EXISTS_CONCAT)
195
196# Check for all needed libraries
197check_library_exists_concat("dl"     dlopen       HAVE_LIBDL)
198check_library_exists_concat("socket" connect      HAVE_LIBSOCKET)
199check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
200
201# Yellowtab Zeta needs different libraries than BeOS 5.
202if(BEOS)
203  set(NOT_NEED_LIBNSL 1)
204  check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
205  check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
206endif(BEOS)
207
208if(NOT NOT_NEED_LIBNSL)
209  check_library_exists_concat("nsl"    gethostbyname  HAVE_LIBNSL)
210endif(NOT NOT_NEED_LIBNSL)
211
212check_library_exists_concat("ws2_32" getch        HAVE_LIBWS2_32)
213check_library_exists_concat("winmm"  getch        HAVE_LIBWINMM)
214check_library_exists("wldap32" cldap_open "" HAVE_WLDAP32)
215
216if(WIN32)
217  set(CURL_DEFAULT_DISABLE_LDAP OFF)
218  # some windows compilers do not have wldap32
219  if(NOT HAVE_WLDAP32)
220    set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
221    message(STATUS "wldap32 not found CURL_DISABLE_LDAP set ON")
222    option(CURL_LDAP_WIN "Use Windows LDAP implementation" OFF)
223  else()
224    option(CURL_LDAP_WIN "Use Windows LDAP implementation" ON)
225  endif()
226  mark_as_advanced(CURL_LDAP_WIN)
227endif()
228
229
230# IF(NOT CURL_SPECIAL_LIBZ)
231#  CHECK_LIBRARY_EXISTS_CONCAT("z"      inflateEnd   HAVE_LIBZ)
232# ENDIF(NOT CURL_SPECIAL_LIBZ)
233
234# Check for idn
235check_library_exists_concat("idn" idna_to_ascii_lz HAVE_LIBIDN)
236
237# Check for LDAP
238check_library_exists_concat("ldap" ldap_init HAVE_LIBLDAP)
239# if(NOT HAVE_LIBLDAP)
240# SET(CURL_DISABLE_LDAP ON)
241# endif(NOT HAVE_LIBLDAP)
242
243# Check for symbol dlopen (same as HAVE_LIBDL)
244check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
245
246# For other tests to use the same libraries
247set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBS})
248
249option(CURL_ZLIB "Set to ON to enable building cURL with zlib support." ON)
250set(HAVE_LIBZ OFF)
251set(HAVE_ZLIB_H OFF)
252set(HAVE_ZLIB OFF)
253if(CURL_ZLIB)  # AND CURL_CONFIG_HAS_BEEN_RUN_BEFORE
254  find_package(ZLIB QUIET)
255  if(ZLIB_FOUND)
256    set(HAVE_ZLIB_H ON)
257    set(HAVE_ZLIB ON)
258    set(HAVE_LIBZ ON)
259    list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
260  endif()
261endif()
262
263option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ON)
264mark_as_advanced(CMAKE_USE_OPENSSL)
265if(CMAKE_USE_OPENSSL)
266
267  set(USE_SSLEAY OFF)
268  set(USE_OPENSSL OFF)
269  set(HAVE_LIBCRYPTO OFF)
270  set(HAVE_LIBSSL OFF)
271
272  find_package(OpenSSL)
273  if(OPENSSL_FOUND)
274    list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
275    list(APPEND CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
276    set(USE_SSLEAY ON)
277    set(USE_OPENSSL ON)
278    set(HAVE_LIBCRYPTO ON)
279    set(HAVE_LIBSSL ON)
280  endif(OPENSSL_FOUND)
281endif(CMAKE_USE_OPENSSL)
282
283# If we have features.h, then do the _BSD_SOURCE magic
284check_include_file("features.h"       HAVE_FEATURES_H)
285
286# Check if header file exists and add it to the list.
287macro(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
288  check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
289  if(${VARIABLE})
290    set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
291    set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
292  endif(${VARIABLE})
293endmacro(CHECK_INCLUDE_FILE_CONCAT)
294
295
296# Check for header files
297if(NOT UNIX)
298  check_include_file_concat("ws2tcpip.h"     HAVE_WS2TCPIP_H)
299  check_include_file_concat("winsock2.h"     HAVE_WINSOCK2_H)
300endif(NOT UNIX)
301check_include_file_concat("stdio.h"          HAVE_STDIO_H)
302if(NOT UNIX)
303  check_include_file_concat("windows.h"      HAVE_WINDOWS_H)
304  check_include_file_concat("winsock.h"      HAVE_WINSOCK_H)
305endif(NOT UNIX)
306
307check_include_file_concat("inttypes.h"       HAVE_INTTYPES_H)
308check_include_file_concat("sys/filio.h"      HAVE_SYS_FILIO_H)
309check_include_file_concat("sys/ioctl.h"      HAVE_SYS_IOCTL_H)
310check_include_file_concat("sys/param.h"      HAVE_SYS_PARAM_H)
311check_include_file_concat("sys/poll.h"       HAVE_SYS_POLL_H)
312check_include_file_concat("sys/resource.h"   HAVE_SYS_RESOURCE_H)
313check_include_file_concat("sys/select.h"     HAVE_SYS_SELECT_H)
314check_include_file_concat("sys/socket.h"     HAVE_SYS_SOCKET_H)
315check_include_file_concat("sys/sockio.h"     HAVE_SYS_SOCKIO_H)
316check_include_file_concat("sys/stat.h"       HAVE_SYS_STAT_H)
317check_include_file_concat("sys/time.h"       HAVE_SYS_TIME_H)
318check_include_file_concat("sys/types.h"      HAVE_SYS_TYPES_H)
319check_include_file_concat("sys/uio.h"        HAVE_SYS_UIO_H)
320check_include_file_concat("sys/un.h"         HAVE_SYS_UN_H)
321check_include_file_concat("sys/utime.h"      HAVE_SYS_UTIME_H)
322check_include_file_concat("alloca.h"         HAVE_ALLOCA_H)
323check_include_file_concat("arpa/inet.h"      HAVE_ARPA_INET_H)
324check_include_file_concat("arpa/tftp.h"      HAVE_ARPA_TFTP_H)
325check_include_file_concat("assert.h"         HAVE_ASSERT_H)
326check_include_file_concat("crypto.h"         HAVE_CRYPTO_H)
327check_include_file_concat("des.h"            HAVE_DES_H)
328check_include_file_concat("err.h"            HAVE_ERR_H)
329check_include_file_concat("errno.h"          HAVE_ERRNO_H)
330check_include_file_concat("fcntl.h"          HAVE_FCNTL_H)
331check_include_file_concat("gssapi/gssapi.h"  HAVE_GSSAPI_GSSAPI_H)
332check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
333check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
334check_include_file_concat("idn-free.h"       HAVE_IDN_FREE_H)
335check_include_file_concat("ifaddrs.h"        HAVE_IFADDRS_H)
336check_include_file_concat("io.h"             HAVE_IO_H)
337check_include_file_concat("krb.h"            HAVE_KRB_H)
338check_include_file_concat("libgen.h"         HAVE_LIBGEN_H)
339check_include_file_concat("libssh2.h"        HAVE_LIBSSH2_H)
340check_include_file_concat("limits.h"         HAVE_LIMITS_H)
341check_include_file_concat("locale.h"         HAVE_LOCALE_H)
342check_include_file_concat("net/if.h"         HAVE_NET_IF_H)
343check_include_file_concat("netdb.h"          HAVE_NETDB_H)
344check_include_file_concat("netinet/in.h"     HAVE_NETINET_IN_H)
345check_include_file_concat("netinet/tcp.h"    HAVE_NETINET_TCP_H)
346if(CMAKE_USE_OPENSSL AND OPENSSL_FOUND)
347  check_include_file_concat("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
348  check_include_file_concat("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
349  check_include_file_concat("openssl/err.h"    HAVE_OPENSSL_ERR_H)
350  check_include_file_concat("openssl/pem.h"    HAVE_OPENSSL_PEM_H)
351  check_include_file_concat("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H)
352  check_include_file_concat("openssl/rsa.h"    HAVE_OPENSSL_RSA_H)
353  check_include_file_concat("openssl/ssl.h"    HAVE_OPENSSL_SSL_H)
354  check_include_file_concat("openssl/x509.h"   HAVE_OPENSSL_X509_H)
355  check_include_file_concat("openssl/rand.h"   HAVE_OPENSSL_RAND_H)
356endif(CMAKE_USE_OPENSSL AND OPENSSL_FOUND)
357check_include_file_concat("pem.h"            HAVE_PEM_H)
358check_include_file_concat("poll.h"           HAVE_POLL_H)
359check_include_file_concat("pwd.h"            HAVE_PWD_H)
360check_include_file_concat("rsa.h"            HAVE_RSA_H)
361check_include_file_concat("setjmp.h"         HAVE_SETJMP_H)
362check_include_file_concat("sgtty.h"          HAVE_SGTTY_H)
363check_include_file_concat("signal.h"         HAVE_SIGNAL_H)
364check_include_file_concat("ssl.h"            HAVE_SSL_H)
365check_include_file_concat("stdbool.h"        HAVE_STDBOOL_H)
366check_include_file_concat("stdint.h"         HAVE_STDINT_H)
367check_include_file_concat("stdio.h"          HAVE_STDIO_H)
368check_include_file_concat("stdlib.h"         HAVE_STDLIB_H)
369check_include_file_concat("string.h"         HAVE_STRING_H)
370check_include_file_concat("strings.h"        HAVE_STRINGS_H)
371check_include_file_concat("stropts.h"        HAVE_STROPTS_H)
372check_include_file_concat("termio.h"         HAVE_TERMIO_H)
373check_include_file_concat("termios.h"        HAVE_TERMIOS_H)
374check_include_file_concat("time.h"           HAVE_TIME_H)
375check_include_file_concat("tld.h"            HAVE_TLD_H)
376check_include_file_concat("unistd.h"         HAVE_UNISTD_H)
377check_include_file_concat("utime.h"          HAVE_UTIME_H)
378check_include_file_concat("x509.h"           HAVE_X509_H)
379
380check_include_file_concat("process.h"        HAVE_PROCESS_H)
381check_include_file_concat("stddef.h"         HAVE_STDDEF_H)
382check_include_file_concat("dlfcn.h"          HAVE_DLFCN_H)
383check_include_file_concat("malloc.h"         HAVE_MALLOC_H)
384check_include_file_concat("memory.h"         HAVE_MEMORY_H)
385check_include_file_concat("ldap.h"           HAVE_LDAP_H)
386check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
387check_include_file_concat("stdint.h"        HAVE_STDINT_H)
388check_include_file_concat("sockio.h"        HAVE_SOCKIO_H)
389check_include_file_concat("sys/utsname.h"   HAVE_SYS_UTSNAME_H)
390check_include_file_concat("idna.h"          HAVE_IDNA_H)
391
392if(NOT HAVE_LDAP_H)
393  message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
394  set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
395endif()
396
397# No ldap, no ldaps.
398if(CURL_DISABLE_LDAP)
399  if(NOT CURL_DISABLE_LDAPS)
400    message(STATUS "LDAP needs to be enabled to support LDAPS")
401    set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
402  endif()
403endif()
404
405check_type_size(size_t  SIZEOF_SIZE_T)
406check_type_size(ssize_t  SIZEOF_SSIZE_T)
407check_type_size("long long"  SIZEOF_LONG_LONG)
408check_type_size("long"  SIZEOF_LONG)
409check_type_size("short"  SIZEOF_SHORT)
410check_type_size("int"  SIZEOF_INT)
411check_type_size("__int64"  SIZEOF___INT64)
412check_type_size("long double"  SIZEOF_LONG_DOUBLE)
413check_type_size("time_t"  SIZEOF_TIME_T)
414if(NOT HAVE_SIZEOF_SSIZE_T)
415  if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
416    set(ssize_t long)
417  endif(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
418  if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
419    set(ssize_t __int64)
420  endif(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
421endif(NOT HAVE_SIZEOF_SSIZE_T)
422
423# Different sizeofs, etc.
424
425#    define CURL_SIZEOF_LONG        4
426#    define CURL_TYPEOF_CURL_OFF_T  long long
427#    define CURL_FORMAT_CURL_OFF_T  "lld"
428#    define CURL_FORMAT_CURL_OFF_TU "llu"
429#    define CURL_FORMAT_OFF_T       "%lld"
430#    define CURL_SIZEOF_CURL_OFF_T  8
431#    define CURL_SUFFIX_CURL_OFF_T  LL
432#    define CURL_SUFFIX_CURL_OFF_TU ULL
433
434set(CURL_SIZEOF_LONG ${SIZEOF_LONG})
435
436if(SIZEOF_LONG EQUAL 8)
437  set(CURL_TYPEOF_CURL_OFF_T long)
438  set(CURL_SIZEOF_CURL_OFF_T 8)
439  set(CURL_FORMAT_CURL_OFF_T "ld")
440  set(CURL_FORMAT_CURL_OFF_TU "lu")
441  set(CURL_FORMAT_OFF_T "%ld")
442  set(CURL_SUFFIX_CURL_OFF_T L)
443  set(CURL_SUFFIX_CURL_OFF_TU UL)
444endif(SIZEOF_LONG EQUAL 8)
445
446if(SIZEOF_LONG_LONG EQUAL 8)
447  set(CURL_TYPEOF_CURL_OFF_T "long long")
448  set(CURL_SIZEOF_CURL_OFF_T 8)
449  set(CURL_FORMAT_CURL_OFF_T "lld")
450  set(CURL_FORMAT_CURL_OFF_TU "llu")
451  set(CURL_FORMAT_OFF_T "%lld")
452  set(CURL_SUFFIX_CURL_OFF_T LL)
453  set(CURL_SUFFIX_CURL_OFF_TU ULL)
454endif(SIZEOF_LONG_LONG EQUAL 8)
455
456if(NOT CURL_TYPEOF_CURL_OFF_T)
457  set(CURL_TYPEOF_CURL_OFF_T ${ssize_t})
458  set(CURL_SIZEOF_CURL_OFF_T ${SIZEOF_SSIZE_T})
459  # TODO: need adjustment here.
460  set(CURL_FORMAT_CURL_OFF_T "ld")
461  set(CURL_FORMAT_CURL_OFF_TU "lu")
462  set(CURL_FORMAT_OFF_T "%ld")
463  set(CURL_SUFFIX_CURL_OFF_T L)
464  set(CURL_SUFFIX_CURL_OFF_TU LU)
465endif(NOT CURL_TYPEOF_CURL_OFF_T)
466
467if(HAVE_SIZEOF_LONG_LONG)
468  set(HAVE_LONGLONG 1)
469  set(HAVE_LL 1)
470endif(HAVE_SIZEOF_LONG_LONG)
471
472find_file(RANDOM_FILE urandom /dev)
473mark_as_advanced(RANDOM_FILE)
474
475# Check for some functions that are used
476check_symbol_exists(basename      "${CURL_INCLUDES}" HAVE_BASENAME)
477check_symbol_exists(socket        "${CURL_INCLUDES}" HAVE_SOCKET)
478check_symbol_exists(poll          "${CURL_INCLUDES}" HAVE_POLL)
479check_symbol_exists(select        "${CURL_INCLUDES}" HAVE_SELECT)
480check_symbol_exists(strdup        "${CURL_INCLUDES}" HAVE_STRDUP)
481check_symbol_exists(strstr        "${CURL_INCLUDES}" HAVE_STRSTR)
482check_symbol_exists(strtok_r      "${CURL_INCLUDES}" HAVE_STRTOK_R)
483check_symbol_exists(strftime      "${CURL_INCLUDES}" HAVE_STRFTIME)
484check_symbol_exists(uname         "${CURL_INCLUDES}" HAVE_UNAME)
485check_symbol_exists(strcasecmp    "${CURL_INCLUDES}" HAVE_STRCASECMP)
486check_symbol_exists(stricmp       "${CURL_INCLUDES}" HAVE_STRICMP)
487check_symbol_exists(strcmpi       "${CURL_INCLUDES}" HAVE_STRCMPI)
488check_symbol_exists(strncmpi      "${CURL_INCLUDES}" HAVE_STRNCMPI)
489check_symbol_exists(alarm         "${CURL_INCLUDES}" HAVE_ALARM)
490if(NOT HAVE_STRNCMPI)
491  set(HAVE_STRCMPI)
492endif(NOT HAVE_STRNCMPI)
493check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
494check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
495check_symbol_exists(gettimeofday  "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
496check_symbol_exists(inet_addr     "${CURL_INCLUDES}" HAVE_INET_ADDR)
497check_symbol_exists(inet_ntoa     "${CURL_INCLUDES}" HAVE_INET_NTOA)
498check_symbol_exists(inet_ntoa_r   "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
499check_symbol_exists(tcsetattr     "${CURL_INCLUDES}" HAVE_TCSETATTR)
500check_symbol_exists(tcgetattr     "${CURL_INCLUDES}" HAVE_TCGETATTR)
501check_symbol_exists(perror        "${CURL_INCLUDES}" HAVE_PERROR)
502check_symbol_exists(closesocket   "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
503check_symbol_exists(setvbuf       "${CURL_INCLUDES}" HAVE_SETVBUF)
504check_symbol_exists(sigsetjmp     "${CURL_INCLUDES}" HAVE_SIGSETJMP)
505check_symbol_exists(getpass_r     "${CURL_INCLUDES}" HAVE_GETPASS_R)
506check_symbol_exists(strlcat       "${CURL_INCLUDES}" HAVE_STRLCAT)
507check_symbol_exists(getpwuid      "${CURL_INCLUDES}" HAVE_GETPWUID)
508check_symbol_exists(geteuid       "${CURL_INCLUDES}" HAVE_GETEUID)
509check_symbol_exists(utime         "${CURL_INCLUDES}" HAVE_UTIME)
510if(CMAKE_USE_OPENSSL)
511  check_symbol_exists(RAND_status   "${CURL_INCLUDES}" HAVE_RAND_STATUS)
512  check_symbol_exists(RAND_screen   "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
513  check_symbol_exists(RAND_egd      "${CURL_INCLUDES}" HAVE_RAND_EGD)
514  check_symbol_exists(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}"
515    HAVE_CRYPTO_CLEANUP_ALL_EX_DATA)
516  if(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
517    set(USE_OPENSSL 1)
518    set(USE_SSLEAY 1)
519  endif(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
520endif(CMAKE_USE_OPENSSL)
521check_symbol_exists(gmtime_r      "${CURL_INCLUDES}" HAVE_GMTIME_R)
522check_symbol_exists(localtime_r   "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
523
524check_symbol_exists(gethostbyname   "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
525check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
526
527check_symbol_exists(signal        "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
528check_symbol_exists(SIGALRM       "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
529if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
530  set(HAVE_SIGNAL 1)
531endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
532check_symbol_exists(uname          "${CURL_INCLUDES}" HAVE_UNAME)
533check_symbol_exists(strtoll        "${CURL_INCLUDES}" HAVE_STRTOLL)
534check_symbol_exists(_strtoi64      "${CURL_INCLUDES}" HAVE__STRTOI64)
535check_symbol_exists(strerror_r     "${CURL_INCLUDES}" HAVE_STRERROR_R)
536check_symbol_exists(siginterrupt   "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
537check_symbol_exists(perror         "${CURL_INCLUDES}" HAVE_PERROR)
538check_symbol_exists(fork           "${CURL_INCLUDES}" HAVE_FORK)
539check_symbol_exists(freeaddrinfo   "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
540check_symbol_exists(freeifaddrs    "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
541check_symbol_exists(pipe           "${CURL_INCLUDES}" HAVE_PIPE)
542check_symbol_exists(ftruncate      "${CURL_INCLUDES}" HAVE_FTRUNCATE)
543check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
544check_symbol_exists(getrlimit      "${CURL_INCLUDES}" HAVE_GETRLIMIT)
545check_symbol_exists(idn_free       "${CURL_INCLUDES}" HAVE_IDN_FREE)
546check_symbol_exists(idna_strerror  "${CURL_INCLUDES}" HAVE_IDNA_STRERROR)
547check_symbol_exists(tld_strerror   "${CURL_INCLUDES}" HAVE_TLD_STRERROR)
548check_symbol_exists(setlocale      "${CURL_INCLUDES}" HAVE_SETLOCALE)
549check_symbol_exists(setrlimit      "${CURL_INCLUDES}" HAVE_SETRLIMIT)
550check_symbol_exists(fcntl          "${CURL_INCLUDES}" HAVE_FCNTL)
551check_symbol_exists(ioctl          "${CURL_INCLUDES}" HAVE_IOCTL)
552check_symbol_exists(setsockopt     "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
553
554# symbol exists in win32, but function does not.
555check_function_exists(inet_pton HAVE_INET_PTON)
556
557# sigaction and sigsetjmp are special. Use special mechanism for
558# detecting those, but only if previous attempt failed.
559if(HAVE_SIGNAL_H)
560  check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
561endif(HAVE_SIGNAL_H)
562
563if(NOT HAVE_SIGSETJMP)
564  if(HAVE_SETJMP_H)
565    check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
566    if(HAVE_MACRO_SIGSETJMP)
567      set(HAVE_SIGSETJMP 1)
568    endif(HAVE_MACRO_SIGSETJMP)
569  endif(HAVE_SETJMP_H)
570endif(NOT HAVE_SIGSETJMP)
571
572# If there is no stricmp(), do not allow LDAP to parse URLs
573if(NOT HAVE_STRICMP)
574  set(HAVE_LDAP_URL_PARSE 1)
575endif(NOT HAVE_STRICMP)
576
577# For other curl specific tests, use this macro.
578macro(CURL_INTERNAL_TEST CURL_TEST)
579  if("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
580    set(MACRO_CHECK_FUNCTION_DEFINITIONS
581      "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
582    if(CMAKE_REQUIRED_LIBRARIES)
583      set(CURL_TEST_ADD_LIBRARIES
584        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
585    endif(CMAKE_REQUIRED_LIBRARIES)
586
587    message(STATUS "Performing Curl Test ${CURL_TEST}")
588    try_compile(${CURL_TEST}
589      ${CMAKE_BINARY_DIR}
590      ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
591      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
592      "${CURL_TEST_ADD_LIBRARIES}"
593      OUTPUT_VARIABLE OUTPUT)
594    if(${CURL_TEST})
595      set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
596      message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
597      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
598        "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
599        "${OUTPUT}\n")
600    else(${CURL_TEST})
601      message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
602      set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
603      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
604        "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
605        "${OUTPUT}\n")
606    endif(${CURL_TEST})
607  endif("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
608endmacro(CURL_INTERNAL_TEST)
609
610macro(CURL_INTERNAL_TEST_RUN CURL_TEST)
611  if("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
612    set(MACRO_CHECK_FUNCTION_DEFINITIONS
613      "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
614    if(CMAKE_REQUIRED_LIBRARIES)
615      set(CURL_TEST_ADD_LIBRARIES
616        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
617    endif(CMAKE_REQUIRED_LIBRARIES)
618
619    message(STATUS "Performing Curl Test ${CURL_TEST}")
620    try_run(${CURL_TEST} ${CURL_TEST}_COMPILE
621      ${CMAKE_BINARY_DIR}
622      ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
623      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
624      "${CURL_TEST_ADD_LIBRARIES}"
625      OUTPUT_VARIABLE OUTPUT)
626    if(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
627      set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
628      message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
629    else(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
630      message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
631      set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
632      file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
633        "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
634        "${OUTPUT}")
635      if(${CURL_TEST}_COMPILE)
636        file(APPEND
637          "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
638          "There was a problem running this test\n")
639      endif(${CURL_TEST}_COMPILE)
640      file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
641        "\n\n")
642    endif(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
643  endif("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
644endmacro(CURL_INTERNAL_TEST_RUN)
645
646# Do curl specific tests
647foreach(CURL_TEST
648    HAVE_FCNTL_O_NONBLOCK
649    HAVE_IOCTLSOCKET
650    HAVE_IOCTLSOCKET_CAMEL
651    HAVE_IOCTLSOCKET_CAMEL_FIONBIO
652    HAVE_IOCTLSOCKET_FIONBIO
653    HAVE_IOCTL_FIONBIO
654    HAVE_IOCTL_SIOCGIFADDR
655    HAVE_SETSOCKOPT_SO_NONBLOCK
656    HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
657    TIME_WITH_SYS_TIME
658    HAVE_O_NONBLOCK
659    HAVE_GETHOSTBYADDR_R_5
660    HAVE_GETHOSTBYADDR_R_7
661    HAVE_GETHOSTBYADDR_R_8
662    HAVE_GETHOSTBYADDR_R_5_REENTRANT
663    HAVE_GETHOSTBYADDR_R_7_REENTRANT
664    HAVE_GETHOSTBYADDR_R_8_REENTRANT
665    HAVE_GETHOSTBYNAME_R_3
666    HAVE_GETHOSTBYNAME_R_5
667    HAVE_GETHOSTBYNAME_R_6
668    HAVE_GETHOSTBYNAME_R_3_REENTRANT
669    HAVE_GETHOSTBYNAME_R_5_REENTRANT
670    HAVE_GETHOSTBYNAME_R_6_REENTRANT
671    HAVE_SOCKLEN_T
672    HAVE_IN_ADDR_T
673    HAVE_BOOL_T
674    STDC_HEADERS
675    RETSIGTYPE_TEST
676    HAVE_INET_NTOA_R_DECL
677    HAVE_INET_NTOA_R_DECL_REENTRANT
678    HAVE_GETADDRINFO
679    HAVE_FILE_OFFSET_BITS
680    )
681  curl_internal_test(${CURL_TEST})
682endforeach(CURL_TEST)
683if(HAVE_FILE_OFFSET_BITS)
684  set(_FILE_OFFSET_BITS 64)
685endif(HAVE_FILE_OFFSET_BITS)
686foreach(CURL_TEST
687    HAVE_GLIBC_STRERROR_R
688    HAVE_POSIX_STRERROR_R
689    )
690  curl_internal_test_run(${CURL_TEST})
691endforeach(CURL_TEST)
692
693# Check for reentrant
694foreach(CURL_TEST
695    HAVE_GETHOSTBYADDR_R_5
696    HAVE_GETHOSTBYADDR_R_7
697    HAVE_GETHOSTBYADDR_R_8
698    HAVE_GETHOSTBYNAME_R_3
699    HAVE_GETHOSTBYNAME_R_5
700    HAVE_GETHOSTBYNAME_R_6
701    HAVE_INET_NTOA_R_DECL_REENTRANT)
702  if(NOT ${CURL_TEST})
703    if(${CURL_TEST}_REENTRANT)
704      set(NEED_REENTRANT 1)
705    endif(${CURL_TEST}_REENTRANT)
706  endif(NOT ${CURL_TEST})
707endforeach(CURL_TEST)
708
709if(NEED_REENTRANT)
710  foreach(CURL_TEST
711      HAVE_GETHOSTBYADDR_R_5
712      HAVE_GETHOSTBYADDR_R_7
713      HAVE_GETHOSTBYADDR_R_8
714      HAVE_GETHOSTBYNAME_R_3
715      HAVE_GETHOSTBYNAME_R_5
716      HAVE_GETHOSTBYNAME_R_6)
717    set(${CURL_TEST} 0)
718    if(${CURL_TEST}_REENTRANT)
719      set(${CURL_TEST} 1)
720    endif(${CURL_TEST}_REENTRANT)
721  endforeach(CURL_TEST)
722endif(NEED_REENTRANT)
723
724if(HAVE_INET_NTOA_R_DECL_REENTRANT)
725  set(HAVE_INET_NTOA_R_DECL 1)
726  set(NEED_REENTRANT 1)
727endif(HAVE_INET_NTOA_R_DECL_REENTRANT)
728
729# Some other minor tests
730
731if(NOT HAVE_IN_ADDR_T)
732  set(in_addr_t "unsigned long")
733endif(NOT HAVE_IN_ADDR_T)
734
735# Fix libz / zlib.h
736
737if(NOT CURL_SPECIAL_LIBZ)
738  if(NOT HAVE_LIBZ)
739    set(HAVE_ZLIB_H 0)
740  endif(NOT HAVE_LIBZ)
741
742  if(NOT HAVE_ZLIB_H)
743    set(HAVE_LIBZ 0)
744  endif(NOT HAVE_ZLIB_H)
745endif(NOT CURL_SPECIAL_LIBZ)
746
747if(_FILE_OFFSET_BITS)
748  set(_FILE_OFFSET_BITS 64)
749endif(_FILE_OFFSET_BITS)
750set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
751set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/curl/curl.h")
752check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
753set(CMAKE_EXTRA_INCLUDE_FILES)
754set(CMAKE_REQUIRED_FLAGS)
755
756
757# Check for nonblocking
758set(HAVE_DISABLED_NONBLOCKING 1)
759if(HAVE_FIONBIO OR
760    HAVE_IOCTLSOCKET OR
761    HAVE_IOCTLSOCKET_CASE OR
762    HAVE_O_NONBLOCK)
763  set(HAVE_DISABLED_NONBLOCKING)
764endif(HAVE_FIONBIO OR
765  HAVE_IOCTLSOCKET OR
766  HAVE_IOCTLSOCKET_CASE OR
767  HAVE_O_NONBLOCK)
768
769if(RETSIGTYPE_TEST)
770  set(RETSIGTYPE void)
771else(RETSIGTYPE_TEST)
772  set(RETSIGTYPE int)
773endif(RETSIGTYPE_TEST)
774
775if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
776  include(CheckCCompilerFlag)
777  check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
778  if(HAVE_C_FLAG_Wno_long_double)
779    # The Mac version of GCC warns about use of long double.  Disable it.
780    get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
781    if(MPRINTF_COMPILE_FLAGS)
782      set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
783    else(MPRINTF_COMPILE_FLAGS)
784      set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
785    endif(MPRINTF_COMPILE_FLAGS)
786    set_source_files_properties(mprintf.c PROPERTIES
787      COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
788  endif(HAVE_C_FLAG_Wno_long_double)
789endif(CMAKE_COMPILER_IS_GNUCC AND APPLE)
790
791if(HAVE_SOCKLEN_T)
792  set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t")
793  if(WIN32)
794    set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h;ws2tcpip.h")
795  elseif(HAVE_SYS_SOCKET_H)
796    set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
797  endif()
798  check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T)
799  set(CMAKE_EXTRA_INCLUDE_FILES)
800  if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T)
801    message(FATAL_ERROR
802     "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log")
803  endif()
804else()
805  set(CURL_TYPEOF_CURL_SOCKLEN_T int)
806  set(CURL_SIZEOF_CURL_SOCKLEN_T ${SIZEOF_INT})
807endif()
808
809# TODO test which of these headers are required for the typedefs used in curlbuild.h
810if(WIN32)
811  set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
812else()
813  set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
814  set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
815  set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
816endif()
817set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
818set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
819
820include(CMake/OtherTests.cmake)
821
822add_definitions(-DHAVE_CONFIG_H)
823
824# For windows, do not allow the compiler to use default target (Vista).
825if(WIN32)
826  add_definitions(-D_WIN32_WINNT=0x0501)
827endif(WIN32)
828
829if(MSVC)
830  add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
831endif(MSVC)
832
833# Sets up the dependencies (zlib, OpenSSL, etc.) of a cURL subproject according to options.
834# TODO This is far to be complete!
835function(SETUP_CURL_DEPENDENCIES TARGET_NAME)
836  if(CURL_ZLIB AND ZLIB_FOUND)
837    include_directories(${ZLIB_INCLUDE_DIR})
838    #ADD_DEFINITIONS( -DHAVE_ZLIB_H -DHAVE_ZLIB -DHAVE_LIBZ )
839  endif()
840
841  if(CMAKE_USE_OPENSSL AND OPENSSL_FOUND)
842    include_directories(${OPENSSL_INCLUDE_DIR})
843  endif()
844  if(CMAKE_USE_OPENSSL AND CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
845    #ADD_DEFINITIONS( -DUSE_SSLEAY )
846  endif()
847
848  target_link_libraries(${TARGET_NAME} ${CURL_LIBS})
849endfunction()
850
851# Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
852function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
853  file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
854  string(REPLACE "$(top_srcdir)"   "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
855  string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
856
857  string(REGEX REPLACE "\\\\\n" "�!�" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
858  string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
859  string(REPLACE "�!�" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
860
861  string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace $() with ${}
862  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.
863  file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
864
865endfunction()
866
867add_subdirectory(lib)
868if(BUILD_CURL_EXE)
869  add_subdirectory(src)
870endif()
871if(BUILD_CURL_TESTS)
872  add_subdirectory(tests)
873endif()
874
875# This needs to be run very last so other parts of the scripts can take advantage of this.
876if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
877  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")
878endif()
879
880# Installation.
881# First, install generated curlbuild.h
882install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/curl/curlbuild.h"
883    DESTINATION include/curl )
884# Next, install other headers excluding curlbuild.h
885install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
886    DESTINATION include
887    FILES_MATCHING PATTERN "*.h"
888    PATTERN "curlbuild.h" EXCLUDE)
889
890
891# Workaround for MSVS10 to avoid the Dialog Hell
892# FIXME: This could be removed with future version of CMake.
893if(MSVC_VERSION EQUAL 1600)
894  set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
895  if(EXISTS "${CURL_SLN_FILENAME}")
896    file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
897  endif()
898endif()
899