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