CMakeLists.txt 35 KB

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