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