CMakeLists.txt 33 KB

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