CMakeLists.txt 35 KB

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