CMakeLists.txt 53 KB

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