LibCurl.cmake 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2014, Daniel Stenberg, <[email protected]>, 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.8 FATAL_ERROR)
  41. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
  42. include(Utilities)
  43. include(Macros)
  44. project( CURL C )
  45. #message(WARNING "the curl cmake build system is poorly maintained. Be aware")
  46. file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
  47. string (REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
  48. CURL_VERSION ${CURL_VERSION_H_CONTENTS})
  49. string (REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
  50. string (REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
  51. CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
  52. string (REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
  53. include_regular_expression("^.*$") # Sukender: Is it necessary?
  54. # Setup package meta-data
  55. # SET(PACKAGE "curl")
  56. message(STATUS "curl version=[${CURL_VERSION}]")
  57. # SET(PACKAGE_TARNAME "curl")
  58. # SET(PACKAGE_NAME "curl")
  59. # SET(PACKAGE_VERSION "-")
  60. # SET(PACKAGE_STRING "curl-")
  61. # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => http://curl.haxx.se/mail/")
  62. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  63. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  64. include_directories(${CURL_BINARY_DIR}/include/curl ${CURL_SOURCE_DIR}/include)
  65. option(BUILD_CURL_EXE "Set to ON to build cURL executable." OFF)
  66. option(BUILD_CURL_TESTS "Set to ON to build cURL tests." OFF)
  67. option(CURL_STATICLIB "Set to ON to build libcurl with static linking." ON)
  68. option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
  69. option(ENABLE_THREADED_RESOLVER "Set to ON to enable POSIX threaded DNS lookup" OFF)
  70. # initialize CURL_LIBS
  71. set(CURL_LIBS "")
  72. if(ENABLE_THREADED_RESOLVER AND ENABLE_ARES)
  73. message(FATAL_ERROR "Options ENABLE_THREADED_RESOLVER and ENABLE_ARES are mutually exclusive")
  74. endif()
  75. if(ENABLE_ARES)
  76. set(USE_ARES 1)
  77. find_package(CARES REQUIRED)
  78. list(APPEND CURL_LIBS ${CARES_LIBRARY} )
  79. set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
  80. endif()
  81. option(BUILD_DASHBOARD_REPORTS "Set to ON to activate reporting of cURL builds here http://www.cdash.org/CDashPublic/index.php?project=CURL" OFF)
  82. if(BUILD_DASHBOARD_REPORTS)
  83. #INCLUDE(Dart)
  84. include(CTest)
  85. endif(BUILD_DASHBOARD_REPORTS)
  86. if(WIN32)
  87. option(BUILD_RELEASE_DEBUG_DIRS "Set OFF to build each configuration to a separate directory" OFF)
  88. mark_as_advanced(BUILD_RELEASE_DEBUG_DIRS)
  89. endif()
  90. option(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide all symbols that aren't officially external)." ON)
  91. mark_as_advanced(CURL_HIDDEN_SYMBOLS)
  92. IF(WIN32)
  93. OPTION(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON)
  94. MARK_AS_ADVANCED(CURL_WINDOWS_SSPI)
  95. if (CURL_WINDOWS_SSPI)
  96. add_definitions(-DUSE_WINDOWS_SSPI -DUSE_SCHANNEL)
  97. set(SSL_ENABLED 1)
  98. endif()
  99. ENDIF()
  100. if(APPLE)
  101. # This is for both iOS and OSX
  102. find_library(CORE_FOUNDATION CoreFoundation)
  103. if(NOT CORE_FOUNDATION)
  104. message(FATAL_ERROR "Apple Core Foundation framework not found!")
  105. endif()
  106. list(APPEND CURL_LIBS ${CORE_FOUNDATION})
  107. find_library(SECURITY Security)
  108. if(NOT SECURITY)
  109. message(FATAL_ERROR "Apple Security framework not found!")
  110. endif()
  111. list(APPEND CURL_LIBS ${SECURITY})
  112. add_definitions(-DUSE_DARWINSSL)
  113. set(SSL_ENABLED 1)
  114. endif()
  115. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" ON)
  116. mark_as_advanced(HTTP_ONLY)
  117. option(CURL_DISABLE_FTP "disables FTP" OFF)
  118. mark_as_advanced(CURL_DISABLE_FTP)
  119. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  120. mark_as_advanced(CURL_DISABLE_LDAP)
  121. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  122. mark_as_advanced(CURL_DISABLE_TELNET)
  123. option(CURL_DISABLE_DICT "disables DICT" OFF)
  124. mark_as_advanced(CURL_DISABLE_DICT)
  125. option(CURL_DISABLE_FILE "disables FILE" OFF)
  126. mark_as_advanced(CURL_DISABLE_FILE)
  127. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  128. mark_as_advanced(CURL_DISABLE_TFTP)
  129. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  130. mark_as_advanced(CURL_DISABLE_HTTP)
  131. option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
  132. mark_as_advanced(CURL_DISABLE_LDAPS)
  133. option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
  134. mark_as_advanced(CURL_DISABLE_RTSP)
  135. option(CURL_DISABLE_PROXY "to disable proxy" OFF)
  136. mark_as_advanced(CURL_DISABLE_PROXY)
  137. option(CURL_DISABLE_POP3 "to disable POP3" OFF)
  138. mark_as_advanced(CURL_DISABLE_POP3)
  139. option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
  140. mark_as_advanced(CURL_DISABLE_IMAP)
  141. option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
  142. mark_as_advanced(CURL_DISABLE_SMTP)
  143. option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
  144. mark_as_advanced(CURL_DISABLE_GOPHER)
  145. if(HTTP_ONLY)
  146. set(CURL_DISABLE_FTP ON)
  147. set(CURL_DISABLE_LDAP ON)
  148. set(CURL_DISABLE_LDAPS ON)
  149. set(CURL_DISABLE_TELNET ON)
  150. set(CURL_DISABLE_DICT ON)
  151. set(CURL_DISABLE_FILE ON)
  152. set(CURL_DISABLE_TFTP ON)
  153. set(CURL_DISABLE_RTSP ON)
  154. set(CURL_DISABLE_POP3 ON)
  155. set(CURL_DISABLE_IMAP ON)
  156. set(CURL_DISABLE_SMTP ON)
  157. set(CURL_DISABLE_GOPHER ON)
  158. endif()
  159. option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
  160. mark_as_advanced(CURL_DISABLE_COOKIES)
  161. option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
  162. mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
  163. option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
  164. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  165. option(DISABLED_THREADSAFE "Set to explicitly specify we don't want to use thread-safe functions" OFF)
  166. mark_as_advanced(DISABLED_THREADSAFE)
  167. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
  168. mark_as_advanced(ENABLE_IPV6)
  169. if(ENABLE_IPV6 AND NOT WIN32)
  170. if(APPLE)
  171. # This is for both iOS and OSX
  172. set(HAVE_SOCKADDR_IN6_SIN6_ADDR 1)
  173. set(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1)
  174. else()
  175. include(CheckStructHasMember)
  176. check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
  177. HAVE_SOCKADDR_IN6_SIN6_ADDR)
  178. check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
  179. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
  180. endif()
  181. if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
  182. message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
  183. # Force the feature off as this name is used as guard macro...
  184. set(ENABLE_IPV6 OFF
  185. CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
  186. endif()
  187. endif()
  188. option(ENABLE_MANUAL "to provide the built-in manual" OFF)
  189. unset(USE_MANUAL CACHE) # TODO: cache NROFF/NROFF_MANOPT/USE_MANUAL vars?
  190. if(ENABLE_MANUAL)
  191. find_program(NROFF NAMES gnroff nroff)
  192. if(NROFF)
  193. # Need a way to write to stdin, this will do
  194. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
  195. # Tests for a valid nroff option to generate a manpage
  196. foreach(_MANOPT "-man" "-mandoc")
  197. execute_process(COMMAND "${NROFF}" ${_MANOPT}
  198. OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
  199. INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
  200. ERROR_QUIET)
  201. # Save the option if it was valid
  202. if(NROFF_MANOPT_OUTPUT)
  203. message("Found *nroff option: -- ${_MANOPT}")
  204. set(NROFF_MANOPT ${_MANOPT})
  205. set(USE_MANUAL 1)
  206. break()
  207. endif()
  208. endforeach()
  209. # No need for the temporary file
  210. file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
  211. if(NOT USE_MANUAL)
  212. message(WARNING "Found no *nroff option to get plaintext from man pages")
  213. endif()
  214. else()
  215. message(WARNING "Found no *nroff program")
  216. endif()
  217. endif()
  218. # We need ansi c-flags, especially on HP
  219. set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  220. set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
  221. # Disable warnings on Borland to avoid changing 3rd party code.
  222. if(BORLAND)
  223. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  224. endif(BORLAND)
  225. # If we are on AIX, do the _ALL_SOURCE magic
  226. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  227. set(_ALL_SOURCE 1)
  228. endif(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  229. # Include all the necessary files for macros
  230. if(NOT APPLE)
  231. # This not used for either iOS or OSX
  232. include (CheckFunctionExists)
  233. include (CheckIncludeFile)
  234. include (CheckIncludeFiles)
  235. include (CheckLibraryExists)
  236. include (CheckSymbolExists)
  237. include (CheckTypeSize)
  238. include (CheckCSourceCompiles)
  239. endif()
  240. # On windows preload settings
  241. if(WIN32)
  242. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  243. endif(WIN32)
  244. if(ENABLE_THREADED_RESOLVER)
  245. check_include_file_concat("pthread.h" HAVE_PTHREAD_H)
  246. if(HAVE_PTHREAD_H)
  247. set(CMAKE_THREAD_PREFER_PTHREAD 1)
  248. find_package(Threads)
  249. if(CMAKE_USE_PTHREADS_INIT)
  250. set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
  251. set(USE_THREADS_POSIX 1)
  252. endif()
  253. endif()
  254. endif()
  255. # Check for all needed libraries
  256. if(APPLE)
  257. # This is for both iOS and OSX
  258. set(HAVE_LIBDL OFF)
  259. set(HAVE_LIBSOCKET OFF)
  260. set(NOT_NEED_LIBNSL ON)
  261. else()
  262. check_library_exists_concat("dl" dlopen HAVE_LIBDL)
  263. check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
  264. check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
  265. endif()
  266. # Yellowtab Zeta needs different libraries than BeOS 5.
  267. if(BEOS)
  268. set(NOT_NEED_LIBNSL 1)
  269. check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
  270. check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
  271. endif(BEOS)
  272. if(NOT NOT_NEED_LIBNSL)
  273. check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
  274. endif(NOT NOT_NEED_LIBNSL)
  275. if(NOT APPLE)
  276. # This not used for both iOS or OSX
  277. check_function_exists(gethostname HAVE_GETHOSTNAME)
  278. endif()
  279. if(WIN32)
  280. check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
  281. check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
  282. endif()
  283. if (WIN32 OR APPLE)
  284. # Use platform spicific encryption on Windows, iOS, and OSX.
  285. option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" OFF)
  286. else()
  287. option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ON)
  288. endif()
  289. mark_as_advanced(CMAKE_USE_OPENSSL)
  290. set(USE_SSLEAY OFF)
  291. set(USE_OPENSSL OFF)
  292. set(HAVE_LIBCRYPTO OFF)
  293. set(HAVE_LIBSSL OFF)
  294. if(CMAKE_USE_OPENSSL)
  295. find_package(OpenSSL)
  296. if(OPENSSL_FOUND)
  297. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  298. set(USE_SSLEAY ON)
  299. set(USE_OPENSSL ON)
  300. set(HAVE_LIBCRYPTO ON)
  301. set(HAVE_LIBSSL ON)
  302. include_directories(${OPENSSL_INCLUDE_DIR})
  303. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  304. if(APPLE)
  305. set(HAVE_OPENSSL_CRYPTO_H ON)
  306. set(HAVE_OPENSSL_ENGINE_H ON)
  307. set(HAVE_OPENSSL_ERR_H ON)
  308. set(HAVE_OPENSSL_PEM_H ON)
  309. set(HAVE_OPENSSL_PKCS12_H ON)
  310. set(HAVE_OPENSSL_RSA_H ON)
  311. set(HAVE_OPENSSL_SSL_H ON)
  312. set(HAVE_OPENSSL_X509_H ON)
  313. set(HAVE_OPENSSL_RAND_H ON)
  314. else()
  315. check_include_file_concat("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  316. check_include_file_concat("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
  317. check_include_file_concat("openssl/err.h" HAVE_OPENSSL_ERR_H)
  318. check_include_file_concat("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  319. check_include_file_concat("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H)
  320. check_include_file_concat("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  321. check_include_file_concat("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  322. check_include_file_concat("openssl/x509.h" HAVE_OPENSSL_X509_H)
  323. check_include_file_concat("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  324. endif()
  325. endif()
  326. endif()
  327. if(NOT CURL_DISABLE_LDAP)
  328. if(WIN32)
  329. option(CURL_LDAP_WIN "Use Windows LDAP implementation" ON)
  330. if(CURL_LDAP_WIN)
  331. check_library_exists("wldap32" cldap_open "" HAVE_WLDAP32)
  332. if(NOT HAVE_WLDAP32)
  333. set(CURL_LDAP_WIN OFF)
  334. endif()
  335. endif()
  336. endif()
  337. option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
  338. mark_as_advanced(CMAKE_USE_OPENLDAP)
  339. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  340. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  341. if(CMAKE_USE_OPENLDAP AND CURL_LDAP_WIN)
  342. message(FATAL_ERROR "Cannot use CURL_LDAP_WIN and CMAKE_USE_OPENLDAP at the same time")
  343. endif()
  344. # Now that we know, we're not using windows LDAP...
  345. if(NOT CURL_LDAP_WIN)
  346. # Check for LDAP
  347. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  348. check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
  349. check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
  350. else()
  351. check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
  352. check_include_file_concat("winber.h" HAVE_WINBER_H)
  353. endif()
  354. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  355. if(CMAKE_LDAP_INCLUDE_DIR)
  356. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  357. endif()
  358. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  359. check_include_file_concat("lber.h" HAVE_LBER_H)
  360. if(NOT HAVE_LDAP_H)
  361. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  362. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  363. elseif(NOT HAVE_LIBLDAP)
  364. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  365. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  366. else()
  367. if(CMAKE_USE_OPENLDAP)
  368. set(USE_OPENLDAP ON)
  369. endif()
  370. if(CMAKE_LDAP_INCLUDE_DIR)
  371. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  372. endif()
  373. set(NEED_LBER_H ON)
  374. set(_HEADER_LIST)
  375. if(HAVE_WINDOWS_H)
  376. list(APPEND _HEADER_LIST "windows.h")
  377. endif()
  378. if(HAVE_SYS_TYPES_H)
  379. list(APPEND _HEADER_LIST "sys/types.h")
  380. endif()
  381. list(APPEND _HEADER_LIST "ldap.h")
  382. set(_SRC_STRING "")
  383. foreach(_HEADER ${_HEADER_LIST})
  384. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  385. endforeach()
  386. set(_SRC_STRING
  387. "
  388. ${_INCLUDE_STRING}
  389. int main(int argc, char ** argv)
  390. {
  391. BerValue *bvp = NULL;
  392. BerElement *bep = ber_init(bvp);
  393. ber_free(bep, 1);
  394. return 0;
  395. }"
  396. )
  397. set(CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1" "-DWIN32_LEAN_AND_MEAN")
  398. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  399. if(HAVE_LIBLBER)
  400. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  401. endif()
  402. check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
  403. if(NOT_NEED_LBER_H)
  404. set(NEED_LBER_H OFF)
  405. else()
  406. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  407. endif()
  408. endif()
  409. endif()
  410. # No ldap, no ldaps.
  411. if(CURL_DISABLE_LDAP)
  412. if(NOT CURL_DISABLE_LDAPS)
  413. message(STATUS "LDAP needs to be enabled to support LDAPS")
  414. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  415. endif()
  416. endif()
  417. if(NOT CURL_DISABLE_LDAPS)
  418. check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
  419. check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
  420. endif()
  421. if(NOT APPLE)
  422. # This not used for either iOS or OSX
  423. # Check for idn
  424. check_library_exists_concat("idn" idna_to_ascii_lz HAVE_LIBIDN)
  425. # Check for symbol dlopen (same as HAVE_LIBDL)
  426. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  427. endif()
  428. option(CURL_ZLIB "Set to ON to enable building cURL with zlib support." ON)
  429. set(HAVE_LIBZ OFF)
  430. set(HAVE_ZLIB_H OFF)
  431. set(HAVE_ZLIB OFF)
  432. if(CURL_ZLIB)
  433. find_package(ZLIB QUIET)
  434. if(ZLIB_FOUND)
  435. set(HAVE_ZLIB_H ON)
  436. set(HAVE_ZLIB ON)
  437. set(HAVE_LIBZ ON)
  438. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  439. include_directories(${ZLIB_INCLUDE_DIRS})
  440. endif()
  441. endif()
  442. #libSSH2
  443. option(CMAKE_USE_LIBSSH2 "Use libSSH2" OFF)
  444. mark_as_advanced(CMAKE_USE_LIBSSH2)
  445. set(USE_LIBSSH2 OFF)
  446. set(HAVE_LIBSSH2 OFF)
  447. set(HAVE_LIBSSH2_H OFF)
  448. if(CMAKE_USE_LIBSSH2)
  449. find_package(LibSSH2)
  450. if(LIBSSH2_FOUND)
  451. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  452. set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
  453. set(CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  454. include_directories("${LIBSSH2_INCLUDE_DIR}")
  455. set(HAVE_LIBSSH2 ON)
  456. set(USE_LIBSSH2 ON)
  457. # find_package has already found the headers
  458. set(HAVE_LIBSSH2_H ON)
  459. set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
  460. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
  461. # now check for specific libssh2 symbols as they were added in different versions
  462. set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
  463. check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
  464. check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
  465. check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
  466. check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
  467. check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
  468. set(CMAKE_EXTRA_INCLUDE_FILES "")
  469. endif(LIBSSH2_FOUND)
  470. endif(CMAKE_USE_LIBSSH2)
  471. option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
  472. mark_as_advanced(CMAKE_USE_GSSAPI)
  473. if(CMAKE_USE_GSSAPI)
  474. find_package(GSS)
  475. set(HAVE_GSS_API ${GSS_FOUND})
  476. if(GSS_FOUND)
  477. message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
  478. set(CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
  479. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  480. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  481. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  482. if(GSS_FLAVOUR STREQUAL "Heimdal")
  483. set(HAVE_GSSHEIMDAL ON)
  484. else() # MIT
  485. set(HAVE_GSSMIT ON)
  486. set(_INCLUDE_LIST "")
  487. if(HAVE_GSSAPI_GSSAPI_H)
  488. list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
  489. endif()
  490. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  491. list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
  492. endif()
  493. if(HAVE_GSSAPI_GSSAPI_KRB5_H)
  494. list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
  495. endif()
  496. string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
  497. string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
  498. foreach(_dir ${GSS_LINK_DIRECTORIES})
  499. set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
  500. endforeach()
  501. set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
  502. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  503. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  504. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  505. set(HAVE_OLD_GSSMIT ON)
  506. endif()
  507. endif()
  508. include_directories(${GSS_INCLUDE_DIR})
  509. link_directories(${GSS_LINK_DIRECTORIES})
  510. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
  511. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  512. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  513. list(APPEND CURL_LIBS ${GSS_LIBRARIES})
  514. else()
  515. message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
  516. endif()
  517. endif()
  518. option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
  519. if(ENABLE_UNIX_SOCKETS)
  520. if(APPLE)
  521. # This is for both iOS and OSX
  522. set(USE_UNIX_SOCKETS ON)
  523. else()
  524. include(CheckStructHasMember)
  525. check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
  526. endif()
  527. else()
  528. unset(USE_UNIX_SOCKETS CACHE)
  529. endif()
  530. # Check for header files
  531. if(NOT UNIX)
  532. check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
  533. check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
  534. check_include_file_concat("windows.h" HAVE_WINDOWS_H)
  535. check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
  536. endif(NOT UNIX)
  537. if(APPLE)
  538. # This is for both iOS and OSX
  539. set(HAVE_INTTYPES_H ON)
  540. set(HAVE_SYS_FILIO_H ON)
  541. set(HAVE_SYS_IOCTL_H ON)
  542. set(HAVE_SYS_PARAM_H ON)
  543. set(HAVE_SYS_POLL_H ON)
  544. set(HAVE_SYS_RESOURCE_H ON)
  545. set(HAVE_SYS_SELECT_H ON)
  546. set(HAVE_SYS_SOCKET_H ON)
  547. set(HAVE_SYS_SOCKIO_H ON)
  548. set(HAVE_SYS_STAT_H ON)
  549. set(HAVE_SYS_TIME_H ON)
  550. set(HAVE_SYS_TYPES_H ON)
  551. set(HAVE_SYS_UIO_H ON)
  552. set(HAVE_SYS_UN_H ON)
  553. set(HAVE_SYS_UTIME_H OFF)
  554. set(HAVE_ALLOCA_H ON)
  555. set(HAVE_ARPA_INET_H ON)
  556. set(HAVE_ARPA_TFTP_H ON)
  557. set(HAVE_ASSERT_H ON)
  558. set(HAVE_CRYPTO_H OFF)
  559. set(HAVE_DES_H OFF)
  560. set(HAVE_ERR_H ON)
  561. set(HAVE_ERRNO_H ON)
  562. set(HAVE_FCNTL_H ON)
  563. set(HAVE_IDN_FREE_H OFF)
  564. set(HAVE_IFADDRS_H ON)
  565. set(HAVE_IO_H OFF)
  566. set(HAVE_KRB_H OFF)
  567. set(HAVE_LIBGEN_H ON)
  568. set(HAVE_LIMITS_H ON)
  569. set(HAVE_LOCALE_H ON)
  570. set(HAVE_NET_IF_H ON)
  571. set(HAVE_NETDB_H ON)
  572. set(HAVE_NETINET_IN_H ON)
  573. set(HAVE_NETINET_TCP_H ON)
  574. set(HAVE_PEM_H OFF)
  575. set(HAVE_POLL_H ON)
  576. set(HAVE_PWD_H ON)
  577. set(HAVE_RSA_H OFF)
  578. set(HAVE_SETJMP_H ON)
  579. set(HAVE_SGTTY_H ON)
  580. set(HAVE_SIGNAL_H ON)
  581. set(HAVE_SSL_H OFF)
  582. set(HAVE_STDBOOL_H ON)
  583. set(HAVE_STDINT_H ON)
  584. set(HAVE_STDIO_H ON)
  585. set(HAVE_STDLIB_H ON)
  586. set(HAVE_STRING_H ON)
  587. set(HAVE_STRINGS_H ON)
  588. set(HAVE_STROPTS_H OFF)
  589. set(HAVE_TERMIO_H OFF)
  590. set(HAVE_TERMIOS_H ON)
  591. set(HAVE_TIME_H ON)
  592. set(HAVE_TLD_H OFF)
  593. set(HAVE_UNISTD_H ON)
  594. set(HAVE_UTIME_H ON)
  595. set(HAVE_X509_H OFF)
  596. set(HAVE_PROCESS_H OFF)
  597. set(HAVE_STDDEF_H ON)
  598. set(HAVE_DLFCN_H ON)
  599. set(HAVE_MALLOC_H OFF)
  600. set(HAVE_MEMORY_H ON)
  601. set(HAVE_NETINET_IF_ETHER_H ON)
  602. set(HAVE_STDINT_H ON)
  603. set(HAVE_SOCKIO_H ON)
  604. set(HAVE_SYS_UTSNAME_H ON)
  605. set(HAVE_IDNA_H ON)
  606. set(SIZEOF_SIZE_T 8)
  607. set(SIZEOF_SSIZE_T 8)
  608. set(HAVE_SIZEOF_SSIZE_T ON)
  609. set(SIZEOF_LONG_LONG 8)
  610. set(HAVE_SIZEOF_LONG_LONG ON)
  611. set(SIZEOF_LONG 8)
  612. set(SIZEOF_SHORT 2)
  613. set(SIZEOF_INT 4)
  614. set(SIZEOF___INT64 8)
  615. set(SIZEOF_LONG_DOUBLE 8)
  616. set(SIZEOF_TIME_T 8)
  617. else(APPLE)
  618. check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
  619. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  620. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  621. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  622. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  623. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  624. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  625. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  626. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  627. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  628. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  629. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  630. check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
  631. check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
  632. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  633. check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
  634. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  635. check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
  636. check_include_file_concat("assert.h" HAVE_ASSERT_H)
  637. check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
  638. check_include_file_concat("des.h" HAVE_DES_H)
  639. check_include_file_concat("err.h" HAVE_ERR_H)
  640. check_include_file_concat("errno.h" HAVE_ERRNO_H)
  641. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  642. check_include_file_concat("idn-free.h" HAVE_IDN_FREE_H)
  643. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  644. check_include_file_concat("io.h" HAVE_IO_H)
  645. check_include_file_concat("krb.h" HAVE_KRB_H)
  646. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  647. check_include_file_concat("limits.h" HAVE_LIMITS_H)
  648. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  649. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  650. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  651. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  652. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
  653. check_include_file_concat("pem.h" HAVE_PEM_H)
  654. check_include_file_concat("poll.h" HAVE_POLL_H)
  655. check_include_file_concat("pwd.h" HAVE_PWD_H)
  656. check_include_file_concat("rsa.h" HAVE_RSA_H)
  657. check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
  658. check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
  659. check_include_file_concat("signal.h" HAVE_SIGNAL_H)
  660. check_include_file_concat("ssl.h" HAVE_SSL_H)
  661. check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
  662. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  663. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  664. check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
  665. check_include_file_concat("string.h" HAVE_STRING_H)
  666. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  667. check_include_file_concat("stropts.h" HAVE_STROPTS_H)
  668. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  669. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  670. check_include_file_concat("time.h" HAVE_TIME_H)
  671. check_include_file_concat("tld.h" HAVE_TLD_H)
  672. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  673. check_include_file_concat("utime.h" HAVE_UTIME_H)
  674. check_include_file_concat("x509.h" HAVE_X509_H)
  675. check_include_file_concat("process.h" HAVE_PROCESS_H)
  676. check_include_file_concat("stddef.h" HAVE_STDDEF_H)
  677. check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
  678. check_include_file_concat("malloc.h" HAVE_MALLOC_H)
  679. check_include_file_concat("memory.h" HAVE_MEMORY_H)
  680. check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
  681. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  682. check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
  683. check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
  684. check_include_file_concat("idna.h" HAVE_IDNA_H)
  685. check_type_size(size_t SIZEOF_SIZE_T)
  686. check_type_size(ssize_t SIZEOF_SSIZE_T)
  687. check_type_size("long long" SIZEOF_LONG_LONG)
  688. check_type_size("long" SIZEOF_LONG)
  689. check_type_size("short" SIZEOF_SHORT)
  690. check_type_size("int" SIZEOF_INT)
  691. check_type_size("__int64" SIZEOF___INT64)
  692. check_type_size("long double" SIZEOF_LONG_DOUBLE)
  693. check_type_size("time_t" SIZEOF_TIME_T)
  694. endif(APPLE)
  695. if(NOT HAVE_SIZEOF_SSIZE_T)
  696. if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  697. set(ssize_t long)
  698. endif(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  699. if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  700. set(ssize_t __int64)
  701. endif(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  702. endif(NOT HAVE_SIZEOF_SSIZE_T)
  703. # Different sizeofs, etc.
  704. # define CURL_SIZEOF_LONG 4
  705. # define CURL_TYPEOF_CURL_OFF_T long long
  706. # define CURL_FORMAT_CURL_OFF_T "lld"
  707. # define CURL_FORMAT_CURL_OFF_TU "llu"
  708. # define CURL_FORMAT_OFF_T "%lld"
  709. # define CURL_SIZEOF_CURL_OFF_T 8
  710. # define CURL_SUFFIX_CURL_OFF_T LL
  711. # define CURL_SUFFIX_CURL_OFF_TU ULL
  712. set(CURL_SIZEOF_LONG ${SIZEOF_LONG})
  713. if(SIZEOF_LONG EQUAL 8)
  714. set(CURL_TYPEOF_CURL_OFF_T long)
  715. set(CURL_SIZEOF_CURL_OFF_T 8)
  716. set(CURL_FORMAT_CURL_OFF_T "ld")
  717. set(CURL_FORMAT_CURL_OFF_TU "lu")
  718. set(CURL_FORMAT_OFF_T "%ld")
  719. set(CURL_SUFFIX_CURL_OFF_T L)
  720. set(CURL_SUFFIX_CURL_OFF_TU UL)
  721. endif(SIZEOF_LONG EQUAL 8)
  722. if(SIZEOF_LONG_LONG EQUAL 8)
  723. set(CURL_TYPEOF_CURL_OFF_T "long long")
  724. set(CURL_SIZEOF_CURL_OFF_T 8)
  725. set(CURL_FORMAT_CURL_OFF_T "lld")
  726. set(CURL_FORMAT_CURL_OFF_TU "llu")
  727. set(CURL_FORMAT_OFF_T "%lld")
  728. set(CURL_SUFFIX_CURL_OFF_T LL)
  729. set(CURL_SUFFIX_CURL_OFF_TU ULL)
  730. endif(SIZEOF_LONG_LONG EQUAL 8)
  731. if(NOT CURL_TYPEOF_CURL_OFF_T)
  732. set(CURL_TYPEOF_CURL_OFF_T ${ssize_t})
  733. set(CURL_SIZEOF_CURL_OFF_T ${SIZEOF_SSIZE_T})
  734. # TODO: need adjustment here.
  735. set(CURL_FORMAT_CURL_OFF_T "ld")
  736. set(CURL_FORMAT_CURL_OFF_TU "lu")
  737. set(CURL_FORMAT_OFF_T "%ld")
  738. set(CURL_SUFFIX_CURL_OFF_T L)
  739. set(CURL_SUFFIX_CURL_OFF_TU LU)
  740. endif(NOT CURL_TYPEOF_CURL_OFF_T)
  741. if(HAVE_SIZEOF_LONG_LONG)
  742. set(HAVE_LONGLONG 1)
  743. set(HAVE_LL 1)
  744. endif(HAVE_SIZEOF_LONG_LONG)
  745. find_file(RANDOM_FILE urandom /dev)
  746. mark_as_advanced(RANDOM_FILE)
  747. # Check for some functions that are used
  748. if(HAVE_LIBWS2_32)
  749. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  750. elseif(HAVE_LIBSOCKET)
  751. set(CMAKE_REQUIRED_LIBRARIES socket)
  752. endif()
  753. if(APPLE)
  754. # This is for both iOS and OSX
  755. set(HAVE_BASENAME ON)
  756. set(HAVE_SOCKET ON)
  757. set(HAVE_POLL ON)
  758. set(HAVE_SELECT ON)
  759. set(HAVE_STRDUP ON)
  760. set(HAVE_STRSTR ON)
  761. set(HAVE_STRTOK_R ON)
  762. set(HAVE_STRFTIME ON)
  763. set(HAVE_UNAME ON)
  764. set(HAVE_STRCASECMP ON)
  765. set(HAVE_STRICMP OFF)
  766. set(HAVE_STRCMPI OFF)
  767. set(HAVE_STRNCMPI OFF)
  768. set(HAVE_ALARM ON)
  769. if(NOT HAVE_STRNCMPI)
  770. set(HAVE_STRCMPI)
  771. endif(NOT HAVE_STRNCMPI)
  772. set(HAVE_GETHOSTBYADDR ON)
  773. set(HAVE_GETHOSTBYADDR_R OFF)
  774. set(HAVE_GETTIMEOFDAY ON)
  775. set(HAVE_INET_ADDR ON)
  776. set(HAVE_INET_NTOA OFF)
  777. set(HAVE_INET_NTOA_R OFF)
  778. set(HAVE_TCSETATTR OFF)
  779. set(HAVE_TCGETATTR OFF)
  780. set(HAVE_PERROR ON)
  781. set(HAVE_CLOSESOCKET OFF)
  782. set(HAVE_SETVBUF OFF)
  783. set(HAVE_SIGSETJMP ON)
  784. set(HAVE_GETPASS_R OFF)
  785. set(HAVE_STRLCAT ON)
  786. set(HAVE_GETPWUID ON)
  787. set(HAVE_GETEUID ON)
  788. set(HAVE_UTIME OFF)
  789. if(CMAKE_USE_OPENSSL)
  790. set(HAVE_RAND_STATUS OFF)
  791. set(HAVE_RAND_SCREEN OFF)
  792. set(HAVE_RAND_EGD OFF)
  793. set(HAVE_CRYPTO_CLEANUP_ALL_EX_DATA OFF)
  794. if(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  795. set(USE_OPENSSL 1)
  796. set(USE_SSLEAY 1)
  797. endif(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  798. endif(CMAKE_USE_OPENSSL)
  799. set(HAVE_GMTIME_R ON)
  800. set(HAVE_LOCALTIME_R ON)
  801. set(HAVE_GETHOSTBYNAME ON)
  802. set(HAVE_GETHOSTBYNAME_R OFF)
  803. set(HAVE_SIGNAL_FUNC ON)
  804. set(HAVE_SIGNAL_MACRO ON)
  805. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  806. set(HAVE_SIGNAL 1)
  807. endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  808. set(HAVE_UNAME ON)
  809. set(HAVE_STRTOLL ON)
  810. set(HAVE__STRTOI64 ON)
  811. set(HAVE_STRERROR_R ON)
  812. set(HAVE_SIGINTERRUPT ON)
  813. set(HAVE_PERROR ON)
  814. set(HAVE_FORK ON)
  815. set(HAVE_GETADDRINFO ON)
  816. set(HAVE_FREEADDRINFO ON)
  817. set(HAVE_FREEIFADDRS ON)
  818. set(HAVE_PIPE ON)
  819. set(HAVE_FTRUNCATE ON)
  820. set(HAVE_GETPROTOBYNAME ON)
  821. set(HAVE_GETRLIMIT ON)
  822. set(HAVE_IDN_FREE OFF)
  823. set(HAVE_IDNA_STRERROR OFF)
  824. set(HAVE_TLD_STRERROR OFF)
  825. set(HAVE_SETLOCALE ON)
  826. set(HAVE_SETRLIMIT ON)
  827. set(HAVE_FCNTL ON)
  828. set(HAVE_IOCTL ON)
  829. set(HAVE_SETSOCKOPT ON)
  830. # symbol exists in win32, but function does not.
  831. set(HAVE_INET_PTON ON)
  832. # sigaction and sigsetjmp are special. Use special mechanism for
  833. # detecting those, but only if previous attempt failed.
  834. if(HAVE_SIGNAL_H)
  835. set(HAVE_SIGACTION ON)
  836. endif(HAVE_SIGNAL_H)
  837. if(NOT HAVE_SIGSETJMP)
  838. if(HAVE_SETJMP_H)
  839. set(HAVE_MACRO_SIGSETJMP ON)
  840. if(HAVE_MACRO_SIGSETJMP)
  841. set(HAVE_SIGSETJMP 1)
  842. endif(HAVE_MACRO_SIGSETJMP)
  843. endif(HAVE_SETJMP_H)
  844. endif(NOT HAVE_SIGSETJMP)
  845. else(APPLE)
  846. check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
  847. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  848. check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
  849. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  850. check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
  851. check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
  852. check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
  853. check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
  854. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  855. check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
  856. check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
  857. check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
  858. check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
  859. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  860. if(NOT HAVE_STRNCMPI)
  861. set(HAVE_STRCMPI)
  862. endif(NOT HAVE_STRNCMPI)
  863. check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
  864. check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
  865. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  866. check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
  867. check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
  868. check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
  869. check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
  870. check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
  871. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  872. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  873. check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
  874. check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
  875. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  876. check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
  877. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  878. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  879. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  880. if(CMAKE_USE_OPENSSL)
  881. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  882. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  883. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  884. check_symbol_exists(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}"
  885. HAVE_CRYPTO_CLEANUP_ALL_EX_DATA)
  886. if(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  887. set(USE_OPENSSL 1)
  888. set(USE_SSLEAY 1)
  889. endif(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  890. endif(CMAKE_USE_OPENSSL)
  891. check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
  892. check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
  893. check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
  894. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  895. check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
  896. check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
  897. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  898. set(HAVE_SIGNAL 1)
  899. endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  900. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  901. check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
  902. check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
  903. check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
  904. check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
  905. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  906. check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
  907. check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
  908. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  909. check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
  910. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  911. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  912. check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
  913. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  914. check_symbol_exists(idn_free "${CURL_INCLUDES}" HAVE_IDN_FREE)
  915. check_symbol_exists(idna_strerror "${CURL_INCLUDES}" HAVE_IDNA_STRERROR)
  916. check_symbol_exists(tld_strerror "${CURL_INCLUDES}" HAVE_TLD_STRERROR)
  917. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  918. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  919. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  920. check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
  921. check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
  922. # symbol exists in win32, but function does not.
  923. check_function_exists(inet_pton HAVE_INET_PTON)
  924. # sigaction and sigsetjmp are special. Use special mechanism for
  925. # detecting those, but only if previous attempt failed.
  926. if(HAVE_SIGNAL_H)
  927. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  928. endif(HAVE_SIGNAL_H)
  929. if(NOT HAVE_SIGSETJMP)
  930. if(HAVE_SETJMP_H)
  931. check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
  932. if(HAVE_MACRO_SIGSETJMP)
  933. set(HAVE_SIGSETJMP 1)
  934. endif(HAVE_MACRO_SIGSETJMP)
  935. endif(HAVE_SETJMP_H)
  936. endif(NOT HAVE_SIGSETJMP)
  937. endif(APPLE)
  938. # If there is no stricmp(), do not allow LDAP to parse URLs
  939. if(NOT HAVE_STRICMP)
  940. set(HAVE_LDAP_URL_PARSE 1)
  941. endif(NOT HAVE_STRICMP)
  942. # See if we're being cross compiled, so make sure that tests that need to
  943. # run already have results filled. Also fill results if we don't want to
  944. # run the checks that would fill them, such as on OSX.
  945. if(CMAKE_CROSSCOMPILING OR APPLE)
  946. SET(HAVE_GLIBC_STRERROR_R "" CACHE STRING "Result from TRY_RUN" FORCE)
  947. SET(HAVE_GLIBC_STRERROR_R__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE)
  948. SET(HAVE_POSIX_STRERROR_R 1 CACHE STRING "Result from TRY_RUN" FORCE)
  949. SET(HAVE_POSIX_STRERROR_R__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE)
  950. SET(HAVE_POLL_FINE_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE)
  951. SET(HAVE_POLL_FINE ON CACHE STRING "Result from TRY_RUN" FORCE)
  952. endif(CMAKE_CROSSCOMPILING OR APPLE)
  953. # iOS can't to try_compile, so put the results of the tests for iOS here explicitly.
  954. if (APPLE)
  955. # This is for both iOS and OSX
  956. # Say what iOS and OSX has explicitly.
  957. set(HAVE_FCNTL_O_NONBLOCK ON)
  958. set(HAVE_IOCTLSOCKET OFF)
  959. set(HAVE_IOCTLSOCKET_CAMEL OFF)
  960. set(HAVE_IOCTLSOCKET_CAMEL_FIONBIO OFF)
  961. set(HAVE_IOCTLSOCKET_FIONBIO OFF)
  962. set(HAVE_IOCTL_FIONBIO ON)
  963. set(HAVE_IOCTL_SIOCGIFADDR ON)
  964. set(HAVE_SETSOCKOPT_SO_NONBLOCK ON)
  965. set(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID ON)
  966. set(TIME_WITH_SYS_TIME ON)
  967. set(HAVE_O_NONBLOCK ON)
  968. set(HAVE_GETHOSTBYADDR_R_5 ON)
  969. set(HAVE_GETHOSTBYADDR_R_7 ON)
  970. set(HAVE_GETHOSTBYADDR_R_8 ON)
  971. set(HAVE_GETHOSTBYADDR_R_5_REENTRANT ON)
  972. set(HAVE_GETHOSTBYADDR_R_7_REENTRANT ON)
  973. set(HAVE_GETHOSTBYADDR_R_8_REENTRANT ON)
  974. set(HAVE_GETHOSTBYNAME_R_3 ON)
  975. set(HAVE_GETHOSTBYNAME_R_5 ON)
  976. set(HAVE_GETHOSTBYNAME_R_6 ON)
  977. set(HAVE_GETHOSTBYNAME_R_3_REENTRANT ON)
  978. set(HAVE_GETHOSTBYNAME_R_5_REENTRANT ON)
  979. set(HAVE_GETHOSTBYNAME_R_6_REENTRANT ON)
  980. set(HAVE_SOCKLEN_T ON)
  981. set(HAVE_IN_ADDR_T ON)
  982. set(HAVE_BOOL_T ON)
  983. set(STDC_HEADERS ON)
  984. set(RETSIGTYPE_TEST ON)
  985. set(HAVE_INET_NTOA_R_DECL OFF)
  986. set(HAVE_INET_NTOA_R_DECL_REENTRANT OFF)
  987. set(HAVE_GETADDRINFO ON)
  988. set(HAVE_FILE_OFFSET_BITS ON)
  989. if(HAVE_FILE_OFFSET_BITS)
  990. set(_FILE_OFFSET_BITS 64)
  991. endif(HAVE_FILE_OFFSET_BITS)
  992. # Extra iOS and OSX variables that are normally set by tests
  993. set(RECV_TYPE_ARG1 "int")
  994. set(RECV_TYPE_ARG2 "void *")
  995. set(RECV_TYPE_ARG3 "size_t")
  996. set(RECV_TYPE_ARG4 "int")
  997. set(RECV_TYPE_RETV "ssize_t")
  998. set(HAVE_RECV 1)
  999. set(SEND_QUAL_ARG2 "const")
  1000. set(SEND_TYPE_ARG1 "int")
  1001. set(SEND_TYPE_ARG2 "void *")
  1002. set(SEND_TYPE_ARG3 "size_t")
  1003. set(SEND_TYPE_ARG4 "int")
  1004. set(SEND_TYPE_RETV "ssize_t")
  1005. set(HAVE_SEND 1)
  1006. set(HAVE_STRUCT_TIMEVAL 1)
  1007. else(APPLE)
  1008. # Do curl specific tests
  1009. foreach(CURL_TEST
  1010. HAVE_FCNTL_O_NONBLOCK
  1011. HAVE_IOCTLSOCKET
  1012. HAVE_IOCTLSOCKET_CAMEL
  1013. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  1014. HAVE_IOCTLSOCKET_FIONBIO
  1015. HAVE_IOCTL_FIONBIO
  1016. HAVE_IOCTL_SIOCGIFADDR
  1017. HAVE_SETSOCKOPT_SO_NONBLOCK
  1018. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
  1019. TIME_WITH_SYS_TIME
  1020. HAVE_O_NONBLOCK
  1021. HAVE_GETHOSTBYADDR_R_5
  1022. HAVE_GETHOSTBYADDR_R_7
  1023. HAVE_GETHOSTBYADDR_R_8
  1024. HAVE_GETHOSTBYADDR_R_5_REENTRANT
  1025. HAVE_GETHOSTBYADDR_R_7_REENTRANT
  1026. HAVE_GETHOSTBYADDR_R_8_REENTRANT
  1027. HAVE_GETHOSTBYNAME_R_3
  1028. HAVE_GETHOSTBYNAME_R_5
  1029. HAVE_GETHOSTBYNAME_R_6
  1030. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  1031. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  1032. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  1033. HAVE_SOCKLEN_T
  1034. HAVE_IN_ADDR_T
  1035. HAVE_BOOL_T
  1036. STDC_HEADERS
  1037. RETSIGTYPE_TEST
  1038. HAVE_INET_NTOA_R_DECL
  1039. HAVE_INET_NTOA_R_DECL_REENTRANT
  1040. HAVE_GETADDRINFO
  1041. HAVE_FILE_OFFSET_BITS
  1042. )
  1043. curl_internal_test(${CURL_TEST})
  1044. endforeach(CURL_TEST)
  1045. if(HAVE_FILE_OFFSET_BITS)
  1046. set(_FILE_OFFSET_BITS 64)
  1047. endif(HAVE_FILE_OFFSET_BITS)
  1048. foreach(CURL_TEST
  1049. HAVE_GLIBC_STRERROR_R
  1050. HAVE_POSIX_STRERROR_R
  1051. )
  1052. curl_internal_test_run(${CURL_TEST})
  1053. endforeach(CURL_TEST)
  1054. # Check for reentrant
  1055. foreach(CURL_TEST
  1056. HAVE_GETHOSTBYADDR_R_5
  1057. HAVE_GETHOSTBYADDR_R_7
  1058. HAVE_GETHOSTBYADDR_R_8
  1059. HAVE_GETHOSTBYNAME_R_3
  1060. HAVE_GETHOSTBYNAME_R_5
  1061. HAVE_GETHOSTBYNAME_R_6
  1062. HAVE_INET_NTOA_R_DECL_REENTRANT)
  1063. if(NOT ${CURL_TEST})
  1064. if(${CURL_TEST}_REENTRANT)
  1065. set(NEED_REENTRANT 1)
  1066. endif(${CURL_TEST}_REENTRANT)
  1067. endif(NOT ${CURL_TEST})
  1068. endforeach(CURL_TEST)
  1069. endif(APPLE)
  1070. if(NEED_REENTRANT)
  1071. foreach(CURL_TEST
  1072. HAVE_GETHOSTBYADDR_R_5
  1073. HAVE_GETHOSTBYADDR_R_7
  1074. HAVE_GETHOSTBYADDR_R_8
  1075. HAVE_GETHOSTBYNAME_R_3
  1076. HAVE_GETHOSTBYNAME_R_5
  1077. HAVE_GETHOSTBYNAME_R_6)
  1078. set(${CURL_TEST} 0)
  1079. if(${CURL_TEST}_REENTRANT)
  1080. set(${CURL_TEST} 1)
  1081. endif(${CURL_TEST}_REENTRANT)
  1082. endforeach(CURL_TEST)
  1083. endif(NEED_REENTRANT)
  1084. if(HAVE_INET_NTOA_R_DECL_REENTRANT)
  1085. set(HAVE_INET_NTOA_R_DECL 1)
  1086. set(NEED_REENTRANT 1)
  1087. endif(HAVE_INET_NTOA_R_DECL_REENTRANT)
  1088. # Some other minor tests
  1089. if(NOT HAVE_IN_ADDR_T)
  1090. set(in_addr_t "unsigned long")
  1091. endif(NOT HAVE_IN_ADDR_T)
  1092. # Fix libz / zlib.h
  1093. if(NOT CURL_SPECIAL_LIBZ)
  1094. if(NOT HAVE_LIBZ)
  1095. set(HAVE_ZLIB_H 0)
  1096. endif(NOT HAVE_LIBZ)
  1097. if(NOT HAVE_ZLIB_H)
  1098. set(HAVE_LIBZ 0)
  1099. endif(NOT HAVE_ZLIB_H)
  1100. endif(NOT CURL_SPECIAL_LIBZ)
  1101. if(_FILE_OFFSET_BITS)
  1102. set(_FILE_OFFSET_BITS 64)
  1103. endif(_FILE_OFFSET_BITS)
  1104. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  1105. set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/curl/curl.h")
  1106. if (APPLE)
  1107. set(SIZEOF_CURL_OFF_T ${SIZEOF_SIZE_T})
  1108. else(APPLE)
  1109. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  1110. endif(APPLE)
  1111. set(CMAKE_EXTRA_INCLUDE_FILES)
  1112. set(CMAKE_REQUIRED_FLAGS)
  1113. # Check for nonblocking
  1114. set(HAVE_DISABLED_NONBLOCKING 1)
  1115. if(HAVE_FIONBIO OR
  1116. HAVE_IOCTLSOCKET OR
  1117. HAVE_IOCTLSOCKET_CASE OR
  1118. HAVE_O_NONBLOCK)
  1119. set(HAVE_DISABLED_NONBLOCKING)
  1120. endif(HAVE_FIONBIO OR
  1121. HAVE_IOCTLSOCKET OR
  1122. HAVE_IOCTLSOCKET_CASE OR
  1123. HAVE_O_NONBLOCK)
  1124. if(RETSIGTYPE_TEST)
  1125. set(RETSIGTYPE void)
  1126. else(RETSIGTYPE_TEST)
  1127. set(RETSIGTYPE int)
  1128. endif(RETSIGTYPE_TEST)
  1129. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  1130. include(CheckCCompilerFlag)
  1131. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  1132. if(HAVE_C_FLAG_Wno_long_double)
  1133. # The Mac version of GCC warns about use of long double. Disable it.
  1134. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  1135. if(MPRINTF_COMPILE_FLAGS)
  1136. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  1137. else(MPRINTF_COMPILE_FLAGS)
  1138. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  1139. endif(MPRINTF_COMPILE_FLAGS)
  1140. set_source_files_properties(mprintf.c PROPERTIES
  1141. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  1142. endif(HAVE_C_FLAG_Wno_long_double)
  1143. endif(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  1144. if(HAVE_SOCKLEN_T)
  1145. set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t")
  1146. if(WIN32)
  1147. set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h;ws2tcpip.h")
  1148. elseif(HAVE_SYS_SOCKET_H)
  1149. set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
  1150. endif()
  1151. if (APPLE)
  1152. # This is for both iOS and OSX
  1153. set(CURL_SIZEOF_CURL_SOCKLEN_T 4)
  1154. set(HAVE_CURL_SIZEOF_CURL_SOCKLEN_T ON)
  1155. else(APPLE)
  1156. check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T)
  1157. endif(APPLE)
  1158. set(CMAKE_EXTRA_INCLUDE_FILES)
  1159. if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T)
  1160. message(FATAL_ERROR
  1161. "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log")
  1162. endif()
  1163. else()
  1164. set(CURL_TYPEOF_CURL_SOCKLEN_T int)
  1165. set(CURL_SIZEOF_CURL_SOCKLEN_T ${SIZEOF_INT})
  1166. endif()
  1167. # TODO test which of these headers are required for the typedefs used in curlbuild.h
  1168. if(WIN32)
  1169. set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
  1170. else()
  1171. set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
  1172. set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
  1173. set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
  1174. endif()
  1175. set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
  1176. set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
  1177. if(NOT APPLE)
  1178. # This not used for either iOS or OSX
  1179. include(CMake/OtherTests.cmake)
  1180. endif(NOT APPLE)
  1181. add_definitions(-DHAVE_CONFIG_H)
  1182. # For windows, do not allow the compiler to use default target (Vista).
  1183. if(WIN32)
  1184. add_definitions(-D_WIN32_WINNT=0x0501)
  1185. endif(WIN32)
  1186. if(MSVC)
  1187. add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  1188. endif(MSVC)
  1189. # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
  1190. function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
  1191. file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
  1192. string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1193. string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1194. string(REGEX REPLACE "\\\\\n" "ᄃ!ᄃ" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1195. string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1196. string(REPLACE "ᄃ!ᄃ" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1197. string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
  1198. 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.
  1199. file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
  1200. endfunction()
  1201. add_subdirectory(lib)
  1202. if(BUILD_CURL_EXE)
  1203. add_subdirectory(src)
  1204. endif()
  1205. if(BUILD_CURL_TESTS)
  1206. add_subdirectory(tests)
  1207. endif()
  1208. # TODO support GNUTLS, NSS, POLARSSL, AXTLS, CYASSL, WINSSL, DARWINSSL
  1209. if(USE_OPENSSL)
  1210. set(SSL_ENABLED 1)
  1211. endif()
  1212. # Helper to populate a list (_items) with a label when conditions (the remaining
  1213. # args) are satisfied
  1214. function(_add_if label)
  1215. # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
  1216. if(${ARGN})
  1217. set(_items ${_items} "${label}" PARENT_SCOPE)
  1218. endif()
  1219. endfunction()
  1220. # Clear list and try to detect available features
  1221. set(_items)
  1222. _add_if("SSL" SSL_ENABLED)
  1223. _add_if("IPv6" ENABLE_IPV6)
  1224. _add_if("unix-sockets" USE_UNIX_SOCKETS)
  1225. _add_if("libz" HAVE_LIBZ)
  1226. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX)
  1227. _add_if("IDN" HAVE_LIBIDN)
  1228. # TODO SSP1 (WinSSL) check is missing
  1229. _add_if("SSPI" USE_WINDOWS_SSPI)
  1230. _add_if("GSS-API" HAVE_GSS_API)
  1231. # TODO SSP1 missing for SPNEGO
  1232. _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1233. (HAVE_GSS_API OR USE_WINDOWS_SSPI))
  1234. _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1235. (HAVE_GSS_API OR USE_WINDOWS_SSPI))
  1236. # NTLM support requires crypto function adaptions from various SSL libs
  1237. # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS, DARWINSSL
  1238. if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR
  1239. USE_WINDOWS_SSPI OR GNUTLS_ENABLED OR NSS_ENABLED OR DARWINSSL_ENABLED))
  1240. _add_if("NTLM" 1)
  1241. # TODO missing option (autoconf: --enable-ntlm-wb)
  1242. _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
  1243. endif()
  1244. # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
  1245. _add_if("TLS-SRP" USE_TLS_SRP)
  1246. # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
  1247. _add_if("HTTP2" USE_NGHTTP2)
  1248. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1249. message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
  1250. # Clear list and try to detect available protocols
  1251. set(_items)
  1252. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1253. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
  1254. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1255. _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
  1256. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1257. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1258. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1259. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1260. # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
  1261. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1262. ((USE_OPENLDAP AND SSL_ENABLED) OR
  1263. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1264. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1265. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1266. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1267. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1268. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
  1269. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1270. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
  1271. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1272. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
  1273. _add_if("SCP" USE_LIBSSH2)
  1274. _add_if("SFTP" USE_LIBSSH2)
  1275. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1276. _add_if("RTMP" USE_LIBRTMP)
  1277. list(SORT _items)
  1278. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1279. message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
  1280. # curl-config needs the following options to be set.
  1281. set(CC "${CMAKE_C_COMPILER}")
  1282. # TODO probably put a -D... options here?
  1283. set(CONFIGURE_OPTIONS "")
  1284. # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
  1285. set(CPPFLAG_CURL_STATICLIB "")
  1286. # TODO need to set this (see CURL_CHECK_CA_BUNDLE in acinclude.m4)
  1287. set(CURL_CA_BUNDLE "")
  1288. set(CURLVERSION "${CURL_VERSION}")
  1289. set(ENABLE_SHARED "yes")
  1290. if(CURL_STATICLIB)
  1291. # Broken: LIBCURL_LIBS below; .a lib is not built
  1292. #message(WARNING "Static linking is broken!")
  1293. set_property(
  1294. TARGET libcurl
  1295. APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB=1
  1296. )
  1297. set(ENABLE_STATIC "yes")
  1298. else()
  1299. set(ENABLE_STATIC "no")
  1300. endif()
  1301. set(exec_prefix "\${prefix}")
  1302. set(includedir "\${prefix}/include")
  1303. set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  1304. set(LIBCURL_LIBS "")
  1305. set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
  1306. # TODO CURL_LIBS also contains absolute paths which don't work with static -l...
  1307. foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
  1308. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
  1309. endforeach()
  1310. # "a" (Linux) or "lib" (Windows)
  1311. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1312. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1313. # Set this to "yes" to append all libraries on which -lcurl is dependent
  1314. set(REQUIRE_LIB_DEPS "no")
  1315. # SUPPORT_FEATURES
  1316. # SUPPORT_PROTOCOLS
  1317. set(VERSIONNUM "${CURL_VERSION_NUM}")
  1318. # Finally generate a "curl-config" matching this config
  1319. #configure_file("${CURL_SOURCE_DIR}/curl-config.in"
  1320. # "${CURL_BINARY_DIR}/curl-config" @ONLY)
  1321. #install(FILES "${CMAKE_BINARY_DIR}/curl-config"
  1322. # DESTINATION bin
  1323. # PERMISSIONS
  1324. # OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1325. # GROUP_READ GROUP_EXECUTE
  1326. # WORLD_READ WORLD_EXECUTE)
  1327. # Finally generate a pkg-config file matching this config
  1328. #configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
  1329. # "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
  1330. #install(FILES "${CMAKE_BINARY_DIR}/libcurl.pc"
  1331. # DESTINATION lib/pkgconfig)
  1332. # This needs to be run very last so other parts of the scripts can take advantage of this.
  1333. if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
  1334. 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")
  1335. endif()
  1336. # Installation.
  1337. # First, install generated curlbuild.h
  1338. #install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/curl/curlbuild.h"
  1339. # DESTINATION include/curl )
  1340. # Next, install other headers excluding curlbuild.h
  1341. #install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  1342. # DESTINATION include
  1343. # FILES_MATCHING PATTERN "*.h"
  1344. # PATTERN "curlbuild.h" EXCLUDE)
  1345. # Workaround for MSVS10 to avoid the Dialog Hell
  1346. # FIXME: This could be removed with future version of CMake.
  1347. if(MSVC_VERSION EQUAL 1600)
  1348. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  1349. if(EXISTS "${CURL_SLN_FILENAME}")
  1350. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  1351. endif()
  1352. endif()