CMakeLists.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. # Include all the necessary files for macros
  2. set(CMAKE_MODULE_PATH "${CURL_SOURCE_DIR}/CMake")
  3. include (CheckFunctionExists)
  4. include (CheckIncludeFile)
  5. include (CheckIncludeFiles)
  6. include (CheckLibraryExists)
  7. include (CheckSymbolExists)
  8. include (CheckCSourceCompiles)
  9. # if crosscompiling is on, the CHECK_TYPE_SIZE macro coming with cmake uses
  10. # TRY_COMPILE instead of TRY_RUN which makes crosscompiling easier, Alex
  11. if(CMAKE_CROSSCOMPILING)
  12. include ("${CMAKE_ROOT}/Modules/CheckTypeSize.cmake")
  13. else(CMAKE_CROSSCOMPILING)
  14. include (CheckTypeSize)
  15. endif(CMAKE_CROSSCOMPILING)
  16. set(libCurl_SRCS
  17. file.c timeval.c base64.c hostip.c progress.c formdata.c
  18. cookie.c http.c sendf.c ftp.c url.c dict.c if2ip.c speedcheck.c
  19. ldap.c ssluse.c version.c getenv.c escape.c mprintf.c telnet.c
  20. netrc.c getinfo.c transfer.c strequal.c easy.c security.c krb4.c
  21. krb5.c memdebug.c http_chunks.c strtok.c connect.c llist.c hash.c
  22. multi.c content_encoding.c share.c http_digest.c md5.c
  23. http_negotiate.c http_ntlm.c inet_pton.c strtoofft.c strerror.c
  24. hostares.c hostasyn.c hostip4.c hostip6.c hostsyn.c hostthre.c
  25. inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c
  26. strdup.c socks.c ssh.c nss.c qssl.c
  27. arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h
  28. progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h
  29. if2ip.h speedcheck.h urldata.h curl_ldap.h ssluse.h escape.h telnet.h
  30. getinfo.h strequal.h krb4.h memdebug.h inet_ntoa_r.h http_chunks.h
  31. strtok.h connect.h llist.h hash.h content_encoding.h share.h
  32. curl_md5.h http_digest.h http_negotiate.h http_ntlm.h inet_pton.h
  33. strtoofft.h strerror.h inet_ntop.h curlx.h memory.h setup.h
  34. transfer.h select.h easyif.h multiif.h parsedate.h sslgen.h gtls.h
  35. tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h ssh.h nssg.h
  36. curl_base64.h
  37. )
  38. set(CURL_DISABLE_LDAP 1)
  39. if(NOT CURL_DISABLE_LDAP)
  40. set(libCurl_SRCS
  41. ${libCurl_SRCS}
  42. ldap.c
  43. )
  44. endif(NOT CURL_DISABLE_LDAP)
  45. # if we have Kerberos 4, right now this is never on
  46. #OPTION(CURL_KRB4 "Use Kerberos 4" OFF)
  47. if(CURL_KRB4)
  48. set(libCurl_SRCS ${libCurl_SRCS}
  49. krb4.c
  50. security.c
  51. )
  52. endif(CURL_KRB4)
  53. #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
  54. mark_as_advanced(CURL_MALLOC_DEBUG)
  55. if(CURL_MALLOC_DEBUG)
  56. set(libCurl_SRCS ${libCurl_SRCS}
  57. memdebug.c
  58. )
  59. endif(CURL_MALLOC_DEBUG)
  60. # On windows preload settings
  61. if(WIN32)
  62. include(${CURL_SOURCE_DIR}/CMake/WindowsCache.cmake)
  63. endif(WIN32)
  64. # This macro checks if the symbol exists in the library and if it
  65. # does, it appends library to the list.
  66. set(CURL_LIBS "")
  67. macro(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
  68. check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} ""
  69. ${VARIABLE})
  70. if(${VARIABLE})
  71. set(CURL_LIBS ${CURL_LIBS} ${LIBRARY})
  72. endif(${VARIABLE})
  73. endmacro(CHECK_LIBRARY_EXISTS_CONCAT)
  74. # Check for all needed libraries
  75. check_library_exists_concat("dl" dlopen HAVE_LIBDL)
  76. #CHECK_LIBRARY_EXISTS_CONCAT("ucb" gethostname HAVE_LIBUCB)
  77. check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
  78. check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
  79. # Yellowtab Zeta needs different libraries than BeOS 5.
  80. if(BEOS)
  81. set(NOT_NEED_LIBNSL 1)
  82. check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
  83. check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
  84. endif(BEOS)
  85. check_library_exists_concat("network" recv HAVE_LIBNETWORK)
  86. if(NOT NOT_NEED_LIBNSL)
  87. check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
  88. endif(NOT NOT_NEED_LIBNSL)
  89. check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
  90. check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
  91. if(NOT CURL_SPECIAL_LIBZ)
  92. check_library_exists_concat("z" inflateEnd HAVE_LIBZ)
  93. endif(NOT CURL_SPECIAL_LIBZ)
  94. option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ON)
  95. mark_as_advanced(CMAKE_USE_OPENSSL)
  96. if(CMAKE_USE_OPENSSL)
  97. check_library_exists_concat("crypto" CRYPTO_lock HAVE_LIBCRYPTO)
  98. check_library_exists_concat("ssl" SSL_connect HAVE_LIBSSL)
  99. endif(CMAKE_USE_OPENSSL)
  100. # Check for idn
  101. check_library_exists_concat("idn" idna_to_ascii_lz HAVE_LIBIDN)
  102. # Check for symbol dlopen (same as HAVE_LIBDL)
  103. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  104. # For other tests to use the same libraries
  105. set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBS})
  106. if(CURL_SPECIAL_LIBZ)
  107. set(CURL_LIBS ${CURL_LIBS} "${CURL_SPECIAL_LIBZ}")
  108. include_directories(${CURL_SPECIAL_LIBZ_INCLUDES})
  109. set(HAVE_LIBZ 0)
  110. set(HAVE_ZLIB_H 0)
  111. endif(CURL_SPECIAL_LIBZ)
  112. # do we have process.h
  113. check_include_file("process.h" HAVE_PROCESS_H)
  114. # Check if header file exists and add it to the list.
  115. macro(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
  116. check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
  117. if(${VARIABLE})
  118. set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
  119. endif(${VARIABLE})
  120. endmacro(CHECK_INCLUDE_FILE_CONCAT)
  121. # Check for header files
  122. if(NOT UNIX)
  123. check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
  124. check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
  125. endif(NOT UNIX)
  126. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  127. if(NOT UNIX)
  128. check_include_file_concat("windows.h" HAVE_WINDOWS_H)
  129. check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
  130. endif(NOT UNIX)
  131. check_include_file_concat("stddef.h" HAVE_STDDEF_H)
  132. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  133. check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
  134. check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
  135. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  136. check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
  137. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  138. check_include_file_concat("malloc.h" HAVE_MALLOC_H)
  139. check_include_file_concat("memory.h" HAVE_MEMORY_H)
  140. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  141. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  142. check_include_file_concat("assert.h" HAVE_ASSERT_H)
  143. check_include_file_concat("limits.h" HAVE_LIMITS_H)
  144. if(CMAKE_USE_OPENSSL)
  145. check_include_file_concat("openssl/x509.h" HAVE_OPENSSL_X509_H)
  146. check_include_file_concat("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
  147. check_include_file_concat("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  148. check_include_file_concat("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  149. check_include_file_concat("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  150. check_include_file_concat("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  151. check_include_file_concat("openssl/err.h" HAVE_OPENSSL_ERR_H)
  152. check_include_file_concat("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  153. check_include_file_concat("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H)
  154. endif(CMAKE_USE_OPENSSL)
  155. if(NOT CURL_SPECIAL_LIBZ)
  156. check_include_file_concat("zlib.h" HAVE_ZLIB_H)
  157. endif(NOT CURL_SPECIAL_LIBZ)
  158. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  159. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  160. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  161. check_include_file_concat("netinet/if_ether.h"
  162. HAVE_NETINET_IF_ETHER_H)
  163. check_include_file_concat("netinet/tcp.h"
  164. HAVE_NETINET_TCP_H)
  165. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  166. check_include_file_concat("utime.h" HAVE_UTIME_H)
  167. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  168. check_include_file_concat("pwd.h" HAVE_PWD_H)
  169. check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
  170. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  171. check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
  172. check_include_file_concat("string.h" HAVE_STRING_H)
  173. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  174. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  175. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  176. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  177. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  178. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  179. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  180. check_include_file_concat("io.h" HAVE_IO_H)
  181. check_include_file_concat("time.h" HAVE_TIME_H)
  182. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  183. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  184. check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
  185. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  186. check_include_file_concat("x509.h" HAVE_X509_H)
  187. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  188. check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
  189. check_include_file_concat("signal.h" HAVE_SIGNAL_H)
  190. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  191. check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
  192. check_include_file_concat("idn-free.h" HAVE_IDN_FREE_H)
  193. check_include_file_concat("idna.h" HAVE_IDNA_H)
  194. check_include_file_concat("tld.h" HAVE_TLD_H)
  195. check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
  196. check_include_file_concat("errno.h" HAVE_ERRNO_H)
  197. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  198. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  199. check_type_size(size_t SIZEOF_SIZE_T)
  200. check_type_size(ssize_t SIZEOF_SSIZE_T)
  201. check_type_size("long long" SIZEOF_LONG_LONG)
  202. check_type_size("long" SIZEOF_LONG)
  203. check_type_size("__int64" SIZEOF___INT64)
  204. check_type_size("long double" SIZEOF_LONG_DOUBLE)
  205. check_type_size("time_t" SIZEOF_TIME_T)
  206. if(NOT HAVE_SIZEOF_SSIZE_T)
  207. if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  208. set(ssize_t long)
  209. endif(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  210. if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  211. set(ssize_t __int64)
  212. endif(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  213. endif(NOT HAVE_SIZEOF_SSIZE_T)
  214. if(HAVE_SIZEOF_LONG_LONG)
  215. set(HAVE_LONGLONG 1)
  216. set(HAVE_LL 1)
  217. endif(HAVE_SIZEOF_LONG_LONG)
  218. find_file(RANDOM_FILE urandom /dev)
  219. mark_as_advanced(RANDOM_FILE)
  220. # Check for some functions that are used
  221. check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
  222. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  223. check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
  224. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  225. check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
  226. check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
  227. check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
  228. check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
  229. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  230. check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
  231. check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
  232. check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
  233. check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
  234. check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
  235. if(NOT HAVE_STRNCMPI)
  236. set(HAVE_STRCMPI)
  237. endif(NOT HAVE_STRNCMPI)
  238. check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
  239. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  240. check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
  241. check_symbol_exists(inet_pton "${CURL_INCLUDES}" HAVE_INET_PTON)
  242. check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
  243. check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
  244. check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
  245. check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
  246. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  247. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  248. check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
  249. check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
  250. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  251. check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
  252. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  253. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  254. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  255. if(CMAKE_USE_OPENSSL)
  256. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  257. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  258. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  259. check_symbol_exists(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}"
  260. HAVE_CRYPTO_CLEANUP_ALL_EX_DATA)
  261. endif(CMAKE_USE_OPENSSL)
  262. check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
  263. check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
  264. check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
  265. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  266. check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
  267. check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
  268. check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
  269. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  270. set(HAVE_SIGNAL 1)
  271. endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  272. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  273. check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
  274. check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
  275. check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
  276. check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
  277. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  278. check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
  279. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  280. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  281. check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
  282. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  283. check_symbol_exists(idn_free "${CURL_INCLUDES}" HAVE_IDN_FREE)
  284. check_symbol_exists(idna_strerror "${CURL_INCLUDES}" HAVE_IDNA_STRERROR)
  285. check_symbol_exists(tld_strerror "${CURL_INCLUDES}" HAVE_TLD_STRERROR)
  286. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  287. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  288. # sigaction and sigsetjmp are special. Use special mechanism for
  289. # detecting those, but only if previous attempt failed.
  290. if(HAVE_SIGNAL_H)
  291. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  292. endif(HAVE_SIGNAL_H)
  293. if(NOT HAVE_SIGSETJMP)
  294. if(HAVE_SETJMP_H)
  295. check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
  296. if(HAVE_MACRO_SIGSETJMP)
  297. set(HAVE_SIGSETJMP 1)
  298. endif(HAVE_MACRO_SIGSETJMP)
  299. endif(HAVE_SETJMP_H)
  300. endif(NOT HAVE_SIGSETJMP)
  301. # For other curl specific tests, use this macro.
  302. macro(CURL_INTERNAL_TEST CURL_TEST)
  303. if("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
  304. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  305. "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
  306. if(CMAKE_REQUIRED_LIBRARIES)
  307. set(CURL_TEST_ADD_LIBRARIES
  308. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  309. endif(CMAKE_REQUIRED_LIBRARIES)
  310. message(STATUS "Performing Curl Test ${CURL_TEST}")
  311. try_compile(${CURL_TEST}
  312. ${CMAKE_BINARY_DIR}
  313. ${CURL_SOURCE_DIR}/CMake/CurlTests.c
  314. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  315. "${CURL_TEST_ADD_LIBRARIES}"
  316. OUTPUT_VARIABLE OUTPUT)
  317. if(${CURL_TEST})
  318. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  319. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  320. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  321. "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
  322. "${OUTPUT}\n")
  323. else(${CURL_TEST})
  324. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  325. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  326. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  327. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  328. "${OUTPUT}\n")
  329. endif(${CURL_TEST})
  330. endif("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
  331. endmacro(CURL_INTERNAL_TEST)
  332. macro(CURL_INTERNAL_TEST_RUN CURL_TEST)
  333. if("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
  334. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  335. "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
  336. if(CMAKE_REQUIRED_LIBRARIES)
  337. set(CURL_TEST_ADD_LIBRARIES
  338. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  339. endif(CMAKE_REQUIRED_LIBRARIES)
  340. message(STATUS "Performing Curl Test ${CURL_TEST}")
  341. try_run(${CURL_TEST} ${CURL_TEST}_COMPILE
  342. ${CMAKE_BINARY_DIR}
  343. ${CURL_SOURCE_DIR}/CMake/CurlTests.c
  344. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  345. "${CURL_TEST_ADD_LIBRARIES}"
  346. OUTPUT_VARIABLE OUTPUT)
  347. if(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  348. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  349. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  350. else(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  351. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  352. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  353. file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  354. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  355. "${OUTPUT}")
  356. if(${CURL_TEST}_COMPILE)
  357. file(APPEND
  358. "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  359. "There was a running problem of this test\n")
  360. endif(${CURL_TEST}_COMPILE)
  361. file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  362. "\n\n")
  363. endif(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  364. endif("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
  365. endmacro(CURL_INTERNAL_TEST_RUN)
  366. # Do curl specific tests
  367. #OPTION(CURL_HAVE_DISABLED_NONBLOCKING "Disable non-blocking socket detection" OFF)
  368. set(CURL_NONBLOCKING_TESTS)
  369. if(NOT CURL_HAVE_DISABLED_NONBLOCKING)
  370. set(CURL_NONBLOCKING_TESTS
  371. HAVE_FIONBIO
  372. HAVE_IOCTLSOCKET
  373. HAVE_IOCTLSOCKET_CASE
  374. HAVE_O_NONBLOCK
  375. HAVE_SO_NONBLOCK
  376. )
  377. endif(NOT CURL_HAVE_DISABLED_NONBLOCKING)
  378. foreach(CURL_TEST
  379. ${CURL_NONBLOCKING_TESTS}
  380. TIME_WITH_SYS_TIME
  381. HAVE_O_NONBLOCKHAVE_GETHOSTBYADDR_R_5
  382. HAVE_GETHOSTBYADDR_R_7
  383. HAVE_GETHOSTBYADDR_R_8
  384. HAVE_GETHOSTBYADDR_R_5_REENTRANT
  385. HAVE_GETHOSTBYADDR_R_7_REENTRANT
  386. HAVE_GETHOSTBYADDR_R_8_REENTRANT
  387. HAVE_GETHOSTBYNAME_R_3
  388. HAVE_GETHOSTBYNAME_R_5
  389. HAVE_GETHOSTBYNAME_R_6
  390. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  391. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  392. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  393. HAVE_SOCKLEN_T
  394. HAVE_IN_ADDR_T
  395. STDC_HEADERS
  396. RETSIGTYPE_TEST
  397. HAVE_INET_NTOA_R_DECL
  398. HAVE_INET_NTOA_R_DECL_REENTRANT
  399. HAVE_GETADDRINFO
  400. HAVE_FILE_OFFSET_BITS
  401. )
  402. curl_internal_test(${CURL_TEST})
  403. endforeach(CURL_TEST)
  404. if(HAVE_FILE_OFFSET_BITS)
  405. set(_FILE_OFFSET_BITS 64)
  406. endif(HAVE_FILE_OFFSET_BITS)
  407. foreach(CURL_TEST
  408. HAVE_GLIBC_STRERROR_R
  409. HAVE_POSIX_STRERROR_R
  410. )
  411. curl_internal_test_run(${CURL_TEST})
  412. endforeach(CURL_TEST)
  413. # Check for reentrant
  414. foreach(CURL_TEST
  415. HAVE_GETHOSTBYADDR_R_5
  416. HAVE_GETHOSTBYADDR_R_7
  417. HAVE_GETHOSTBYADDR_R_8
  418. HAVE_GETHOSTBYNAME_R_3
  419. HAVE_GETHOSTBYNAME_R_5
  420. HAVE_GETHOSTBYNAME_R_6
  421. HAVE_INET_NTOA_R_DECL_REENTRANT)
  422. if(NOT ${CURL_TEST})
  423. if(${CURL_TEST}_REENTRANT)
  424. set(NEED_REENTRANT 1)
  425. endif(${CURL_TEST}_REENTRANT)
  426. endif(NOT ${CURL_TEST})
  427. endforeach(CURL_TEST)
  428. if(NEED_REENTRANT)
  429. foreach(CURL_TEST
  430. HAVE_GETHOSTBYADDR_R_5
  431. HAVE_GETHOSTBYADDR_R_7
  432. HAVE_GETHOSTBYADDR_R_8
  433. HAVE_GETHOSTBYNAME_R_3
  434. HAVE_GETHOSTBYNAME_R_5
  435. HAVE_GETHOSTBYNAME_R_6)
  436. set(${CURL_TEST} 0)
  437. if(${CURL_TEST}_REENTRANT)
  438. set(${CURL_TEST} 1)
  439. endif(${CURL_TEST}_REENTRANT)
  440. endforeach(CURL_TEST)
  441. endif(NEED_REENTRANT)
  442. if(HAVE_INET_NTOA_R_DECL_REENTRANT)
  443. set(HAVE_INET_NTOA_R_DECL 1)
  444. set(NEED_REENTRANT 1)
  445. endif(HAVE_INET_NTOA_R_DECL_REENTRANT)
  446. # Some other minor tests
  447. if(NOT HAVE_SOCKLEN_T)
  448. set(socklen_t "int")
  449. endif(NOT HAVE_SOCKLEN_T)
  450. if(NOT HAVE_IN_ADDR_T)
  451. set(in_addr_t "unsigned long")
  452. endif(NOT HAVE_IN_ADDR_T)
  453. # Fix libz / zlib.h
  454. if(NOT CURL_SPECIAL_LIBZ)
  455. if(NOT HAVE_LIBZ)
  456. set(HAVE_ZLIB_H 0)
  457. endif(NOT HAVE_LIBZ)
  458. if(NOT HAVE_ZLIB_H)
  459. set(HAVE_LIBZ 0)
  460. endif(NOT HAVE_ZLIB_H)
  461. endif(NOT CURL_SPECIAL_LIBZ)
  462. if(_FILE_OFFSET_BITS)
  463. set(_FILE_OFFSET_BITS 64)
  464. endif(_FILE_OFFSET_BITS)
  465. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  466. set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/curl/curl.h")
  467. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  468. set(CMAKE_EXTRA_INCLUDE_FILES)
  469. set(CMAKE_REQUIRED_FLAGS)
  470. # Check for nonblocking
  471. set(HAVE_DISABLED_NONBLOCKING 1)
  472. if(HAVE_FIONBIO OR
  473. HAVE_IOCTLSOCKET OR
  474. HAVE_IOCTLSOCKET_CASE OR
  475. HAVE_O_NONBLOCK)
  476. set(HAVE_DISABLED_NONBLOCKING)
  477. endif(HAVE_FIONBIO OR
  478. HAVE_IOCTLSOCKET OR
  479. HAVE_IOCTLSOCKET_CASE OR
  480. HAVE_O_NONBLOCK)
  481. if(RETSIGTYPE_TEST)
  482. set(RETSIGTYPE void)
  483. else(RETSIGTYPE_TEST)
  484. set(RETSIGTYPE int)
  485. endif(RETSIGTYPE_TEST)
  486. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  487. include(CheckCCompilerFlag)
  488. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  489. if(HAVE_C_FLAG_Wno_long_double)
  490. # The Mac version of GCC warns about use of long double. Disable it.
  491. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  492. if(MPRINTF_COMPILE_FLAGS)
  493. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  494. else(MPRINTF_COMPILE_FLAGS)
  495. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  496. endif(MPRINTF_COMPILE_FLAGS)
  497. set_source_files_properties(mprintf.c PROPERTIES
  498. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  499. endif(HAVE_C_FLAG_Wno_long_double)
  500. endif(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  501. include(${CURL_SOURCE_DIR}/CMake/OtherTests.cmake)
  502. # The rest of the build
  503. include_directories(${CURL_SOURCE_DIR})
  504. include_directories(${CURL_BINARY_DIR})
  505. if(WIN32)
  506. set(WIN32_LEAN_AND_MEAN TRUE)
  507. endif(WIN32)
  508. configure_file(${CURL_SOURCE_DIR}/lib/config.cmake.h.in
  509. ${CURL_BINARY_DIR}/lib/config.h)
  510. set(CURL_SIZEOF_LONG ${SIZEOF_LONG})
  511. configure_file(${CURL_SOURCE_DIR}/include/curl/curlbuild.cmake.h.in
  512. ${CURL_BINARY_DIR}/include/curl/curlbuild.h)
  513. add_library(cmcurl ${libCurl_SRCS})
  514. target_link_libraries(cmcurl ${CURL_LIBS})
  515. option(CURL_TESTING "Do libCurl testing" OFF)
  516. if(CURL_TESTING)
  517. subdirs(Testing)
  518. endif(CURL_TESTING)
  519. #add_executable(LIBCURL Testing/curltest.c)
  520. #target_link_libraries(LIBCURL cmcurl ${CMAKE_DL_LIBS})
  521. #add_test(curl "${EXECUTABLE_OUTPUT_PATH}/LIBCURL")