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