CMakeLists.txt 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.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. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. # by Tetetest and Sukender (Benoit Neil)
  25. # Note: By default this CMake build script detects the version of some
  26. # dependencies using `check_symbol_exists`. Those checks do not work
  27. # in the case that both CURL and its dependency are included as
  28. # sub-projects in a larger build using `FetchContent`. To support
  29. # that case, additional variables may be defined by the parent
  30. # project, ideally in the "extra" find package redirect file:
  31. # https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package
  32. #
  33. # The following variables are available:
  34. # HAVE_SSL_SET0_WBIO: `SSL_set0_wbio` present in OpenSSL/wolfSSL
  35. # HAVE_OPENSSL_SRP: `SSL_CTX_set_srp_username` present in OpenSSL/wolfSSL
  36. # HAVE_GNUTLS_SRP: `gnutls_srp_verifier` present in GnuTLS
  37. # HAVE_SSL_CTX_SET_QUIC_METHOD: `SSL_CTX_set_quic_method` present in OpenSSL/wolfSSL
  38. # HAVE_QUICHE_CONN_SET_QLOG_FD: `quiche_conn_set_qlog_fd` present in QUICHE
  39. # HAVE_ECH: ECH API checks for OpenSSL, BoringSSL or wolfSSL
  40. #
  41. # For each of the above variables, if the variable is DEFINED (either
  42. # to ON or OFF), the symbol detection will be skipped. If the
  43. # variable is NOT DEFINED, the symbol detection will be performed.
  44. cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
  45. message(STATUS "Using CMake version ${CMAKE_VERSION}")
  46. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
  47. include(Utilities)
  48. include(Macros)
  49. include(CMakeDependentOption)
  50. include(CheckCCompilerFlag)
  51. project(CURL C)
  52. file(STRINGS ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS REGEX "#define LIBCURL_VERSION( |_NUM )")
  53. string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
  54. CURL_VERSION ${CURL_VERSION_H_CONTENTS})
  55. string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
  56. string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
  57. CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
  58. string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
  59. # Setup package meta-data
  60. # set(PACKAGE "curl")
  61. message(STATUS "curl version=[${CURL_VERSION}]")
  62. # set(PACKAGE_TARNAME "curl")
  63. # set(PACKAGE_NAME "curl")
  64. # set(PACKAGE_VERSION "-")
  65. # set(PACKAGE_STRING "curl-")
  66. # set(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.se/mail/")
  67. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  68. if(CMAKE_C_COMPILER_TARGET)
  69. set(OS "\"${CMAKE_C_COMPILER_TARGET}\"")
  70. else()
  71. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  72. endif()
  73. include_directories(${CURL_SOURCE_DIR}/include)
  74. set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
  75. option(CURL_WERROR "Turn compiler warnings into errors" OFF)
  76. option(PICKY_COMPILER "Enable picky compiler options" ON)
  77. option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
  78. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  79. option(BUILD_STATIC_LIBS "Build static libraries" OFF)
  80. option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
  81. option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
  82. option(CURL_DISABLE_INSTALL "Set to ON to disable installation targets" OFF)
  83. if(WIN32)
  84. option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
  85. option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
  86. set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
  87. if(CURL_TARGET_WINDOWS_VERSION)
  88. add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
  89. list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
  90. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
  91. endif()
  92. if(ENABLE_UNICODE)
  93. add_definitions(-DUNICODE -D_UNICODE)
  94. if(MINGW)
  95. add_compile_options(-municode)
  96. endif()
  97. endif()
  98. endif()
  99. option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)
  100. cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
  101. ON "NOT ENABLE_ARES"
  102. OFF)
  103. include(PickyWarnings)
  104. option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
  105. option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" ${ENABLE_DEBUG})
  106. if(ENABLE_DEBUG)
  107. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS DEBUGBUILD)
  108. endif()
  109. if(ENABLE_CURLDEBUG)
  110. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
  111. endif()
  112. # For debug libs and exes, add "-d" postfix
  113. if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
  114. set(CMAKE_DEBUG_POSTFIX "-d")
  115. endif()
  116. set(LIB_STATIC "libcurl_static")
  117. set(LIB_SHARED "libcurl_shared")
  118. if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
  119. set(BUILD_STATIC_LIBS ON)
  120. endif()
  121. if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS)
  122. set(BUILD_STATIC_CURL ON)
  123. elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS)
  124. set(BUILD_STATIC_CURL OFF)
  125. endif()
  126. # lib flavour selected for curl tool
  127. if(BUILD_STATIC_CURL)
  128. set(LIB_SELECTED_FOR_EXE ${LIB_STATIC})
  129. else()
  130. set(LIB_SELECTED_FOR_EXE ${LIB_SHARED})
  131. endif()
  132. # lib flavour selected for example and test programs.
  133. if(BUILD_SHARED_LIBS)
  134. set(LIB_SELECTED ${LIB_SHARED})
  135. else()
  136. set(LIB_SELECTED ${LIB_STATIC})
  137. endif()
  138. # initialize CURL_LIBS
  139. set(CURL_LIBS "")
  140. set(LIBCURL_PC_REQUIRES_PRIVATE "")
  141. if(ENABLE_ARES)
  142. set(USE_ARES 1)
  143. find_package(CARES REQUIRED)
  144. list(APPEND CURL_LIBS ${CARES_LIBRARY})
  145. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libcares")
  146. endif()
  147. include(CurlSymbolHiding)
  148. option(CURL_ENABLE_EXPORT_TARGET "to enable cmake export target" ON)
  149. mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
  150. option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF)
  151. mark_as_advanced(CURL_DISABLE_ALTSVC)
  152. option(CURL_DISABLE_SRP "disables TLS-SRP support" OFF)
  153. mark_as_advanced(CURL_DISABLE_SRP)
  154. option(CURL_DISABLE_COOKIES "disables cookies support" OFF)
  155. mark_as_advanced(CURL_DISABLE_COOKIES)
  156. option(CURL_DISABLE_BASIC_AUTH "disables Basic authentication" OFF)
  157. mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
  158. option(CURL_DISABLE_BEARER_AUTH "disables Bearer authentication" OFF)
  159. mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
  160. option(CURL_DISABLE_DIGEST_AUTH "disables Digest authentication" OFF)
  161. mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
  162. option(CURL_DISABLE_KERBEROS_AUTH "disables Kerberos authentication" OFF)
  163. mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
  164. option(CURL_DISABLE_NEGOTIATE_AUTH "disables negotiate authentication" OFF)
  165. mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
  166. option(CURL_DISABLE_AWS "disables AWS-SIG4" OFF)
  167. mark_as_advanced(CURL_DISABLE_AWS)
  168. option(CURL_DISABLE_DICT "disables DICT" OFF)
  169. mark_as_advanced(CURL_DISABLE_DICT)
  170. option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF)
  171. mark_as_advanced(CURL_DISABLE_DOH)
  172. option(CURL_DISABLE_FILE "disables FILE" OFF)
  173. mark_as_advanced(CURL_DISABLE_FILE)
  174. cmake_dependent_option(CURL_DISABLE_FORM_API "disables form api" OFF
  175. "NOT CURL_DISABLE_MIME" ON)
  176. mark_as_advanced(CURL_DISABLE_FORM_API)
  177. option(CURL_DISABLE_FTP "disables FTP" OFF)
  178. mark_as_advanced(CURL_DISABLE_FTP)
  179. option(CURL_DISABLE_GETOPTIONS "disables curl_easy_options API for existing options to curl_easy_setopt" OFF)
  180. mark_as_advanced(CURL_DISABLE_GETOPTIONS)
  181. option(CURL_DISABLE_GOPHER "disables Gopher" OFF)
  182. mark_as_advanced(CURL_DISABLE_GOPHER)
  183. option(CURL_DISABLE_HEADERS_API "disables headers-api support" OFF)
  184. mark_as_advanced(CURL_DISABLE_HEADERS_API)
  185. option(CURL_DISABLE_HSTS "disables HSTS support" OFF)
  186. mark_as_advanced(CURL_DISABLE_HSTS)
  187. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  188. mark_as_advanced(CURL_DISABLE_HTTP)
  189. option(CURL_DISABLE_HTTP_AUTH "disables all HTTP authentication methods" OFF)
  190. mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
  191. option(CURL_DISABLE_IMAP "disables IMAP" OFF)
  192. mark_as_advanced(CURL_DISABLE_IMAP)
  193. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  194. mark_as_advanced(CURL_DISABLE_LDAP)
  195. option(CURL_DISABLE_LDAPS "disables LDAPS" OFF)
  196. mark_as_advanced(CURL_DISABLE_LDAPS)
  197. option(CURL_DISABLE_LIBCURL_OPTION "disables --libcurl option from the curl tool" OFF)
  198. mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
  199. option(CURL_DISABLE_MIME "disables MIME support" OFF)
  200. mark_as_advanced(CURL_DISABLE_MIME)
  201. option(CURL_DISABLE_MQTT "disables MQTT" OFF)
  202. mark_as_advanced(CURL_DISABLE_BINDLOCAL)
  203. option(CURL_DISABLE_BINDLOCAL "disables local binding support" OFF)
  204. mark_as_advanced(CURL_DISABLE_MQTT)
  205. option(CURL_DISABLE_NETRC "disables netrc parser" OFF)
  206. mark_as_advanced(CURL_DISABLE_NETRC)
  207. option(CURL_DISABLE_NTLM "disables NTLM support" OFF)
  208. mark_as_advanced(CURL_DISABLE_NTLM)
  209. option(CURL_DISABLE_PARSEDATE "disables date parsing" OFF)
  210. mark_as_advanced(CURL_DISABLE_PARSEDATE)
  211. option(CURL_DISABLE_POP3 "disables POP3" OFF)
  212. mark_as_advanced(CURL_DISABLE_POP3)
  213. option(CURL_DISABLE_PROGRESS_METER "disables built-in progress meter" OFF)
  214. mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
  215. option(CURL_DISABLE_PROXY "disables proxy support" OFF)
  216. mark_as_advanced(CURL_DISABLE_PROXY)
  217. option(CURL_DISABLE_RTSP "disables RTSP" OFF)
  218. mark_as_advanced(CURL_DISABLE_RTSP)
  219. option(CURL_DISABLE_SHUFFLE_DNS "disables shuffle DNS feature" OFF)
  220. mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
  221. option(CURL_DISABLE_SMB "disables SMB" OFF)
  222. mark_as_advanced(CURL_DISABLE_SMB)
  223. option(CURL_DISABLE_SMTP "disables SMTP" OFF)
  224. mark_as_advanced(CURL_DISABLE_SMTP)
  225. option(CURL_DISABLE_SOCKETPAIR "disables use of socketpair for curl_multi_poll" OFF)
  226. mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
  227. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  228. mark_as_advanced(CURL_DISABLE_TELNET)
  229. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  230. mark_as_advanced(CURL_DISABLE_TFTP)
  231. option(CURL_DISABLE_VERBOSE_STRINGS "disables verbose strings" OFF)
  232. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  233. # Corresponds to HTTP_ONLY in lib/curl_setup.h
  234. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  235. mark_as_advanced(HTTP_ONLY)
  236. if(HTTP_ONLY)
  237. set(CURL_DISABLE_DICT ON)
  238. set(CURL_DISABLE_FILE ON)
  239. set(CURL_DISABLE_FTP ON)
  240. set(CURL_DISABLE_GOPHER ON)
  241. set(CURL_DISABLE_IMAP ON)
  242. set(CURL_DISABLE_LDAP ON)
  243. set(CURL_DISABLE_LDAPS ON)
  244. set(CURL_DISABLE_MQTT ON)
  245. set(CURL_DISABLE_POP3 ON)
  246. set(CURL_DISABLE_RTSP ON)
  247. set(CURL_DISABLE_SMB ON)
  248. set(CURL_DISABLE_SMTP ON)
  249. set(CURL_DISABLE_TELNET ON)
  250. set(CURL_DISABLE_TFTP ON)
  251. endif()
  252. if(WINDOWS_STORE)
  253. set(CURL_DISABLE_TELNET ON) # telnet code needs fixing to compile for UWP.
  254. endif()
  255. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
  256. mark_as_advanced(ENABLE_IPV6)
  257. if(ENABLE_IPV6 AND NOT WIN32)
  258. include(CheckStructHasMember)
  259. check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
  260. HAVE_SOCKADDR_IN6_SIN6_ADDR)
  261. check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
  262. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
  263. if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
  264. message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
  265. # Force the feature off as this name is used as guard macro...
  266. set(ENABLE_IPV6 OFF
  267. CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
  268. endif()
  269. if(APPLE AND NOT ENABLE_ARES)
  270. set(use_core_foundation_and_core_services ON)
  271. find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
  272. if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
  273. message(FATAL_ERROR "SystemConfiguration framework not found")
  274. endif()
  275. list(APPEND CURL_LIBS "-framework SystemConfiguration")
  276. endif()
  277. endif()
  278. if(ENABLE_IPV6)
  279. set(USE_IPV6 ON)
  280. endif()
  281. find_package(Perl)
  282. option(BUILD_LIBCURL_DOCS "to build libcurl man pages" ON)
  283. option(BUILD_MISC_DOCS "to build misc man pages (e.g. curl-config and mk-ca-bundle)" ON)
  284. option(ENABLE_CURL_MANUAL "to build the man page for curl and enable its -M/--manual option" ON)
  285. if(ENABLE_CURL_MANUAL OR BUILD_LIBCURL_DOCS)
  286. if(PERL_FOUND)
  287. set(HAVE_MANUAL_TOOLS ON)
  288. endif()
  289. if(NOT HAVE_MANUAL_TOOLS)
  290. message(WARNING "Perl not found. Will not build manuals.")
  291. endif()
  292. endif()
  293. if(CURL_STATIC_CRT)
  294. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  295. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  296. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  297. endif()
  298. # Disable warnings on Borland to avoid changing 3rd party code.
  299. if(BORLAND)
  300. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  301. endif()
  302. # If we are on AIX, do the _ALL_SOURCE magic
  303. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  304. set(_ALL_SOURCE 1)
  305. endif()
  306. # If we are on Haiku, make sure that the network library is brought in.
  307. if(${CMAKE_SYSTEM_NAME} MATCHES Haiku)
  308. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnetwork")
  309. endif()
  310. # Include all the necessary files for macros
  311. include(CMakePushCheckState)
  312. include(CheckFunctionExists)
  313. include(CheckIncludeFile)
  314. include(CheckIncludeFiles)
  315. include(CheckLibraryExists)
  316. include(CheckSymbolExists)
  317. include(CheckTypeSize)
  318. include(CheckCSourceCompiles)
  319. # On windows preload settings
  320. if(WIN32)
  321. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  322. endif()
  323. if(ENABLE_THREADED_RESOLVER)
  324. if(WIN32)
  325. set(USE_THREADS_WIN32 ON)
  326. else()
  327. find_package(Threads REQUIRED)
  328. set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
  329. set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
  330. set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
  331. endif()
  332. endif()
  333. # Check for all needed libraries
  334. check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
  335. if(HAVE_LIBSOCKET)
  336. set(CURL_LIBS "socket;${CURL_LIBS}")
  337. endif()
  338. check_function_exists(gethostname HAVE_GETHOSTNAME)
  339. if(WIN32)
  340. list(APPEND CURL_LIBS "ws2_32" "bcrypt")
  341. endif()
  342. # check SSL libraries
  343. option(CURL_ENABLE_SSL "Enable SSL support" ON)
  344. if(CURL_DEFAULT_SSL_BACKEND)
  345. set(valid_default_ssl_backend FALSE)
  346. endif()
  347. if(APPLE)
  348. cmake_dependent_option(CURL_USE_SECTRANSP "Enable Apple OS native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  349. endif()
  350. if(WIN32)
  351. cmake_dependent_option(CURL_USE_SCHANNEL "Enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  352. option(CURL_WINDOWS_SSPI "Enable SSPI on Windows" ${CURL_USE_SCHANNEL})
  353. endif()
  354. cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  355. cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  356. cmake_dependent_option(CURL_USE_WOLFSSL "Enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  357. cmake_dependent_option(CURL_USE_GNUTLS "Enable GnuTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  358. set(openssl_default ON)
  359. if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_WOLFSSL)
  360. set(openssl_default OFF)
  361. endif()
  362. cmake_dependent_option(CURL_USE_OPENSSL "Enable OpenSSL for SSL/TLS" ${openssl_default} CURL_ENABLE_SSL OFF)
  363. option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF)
  364. count_true(enabled_ssl_options_count
  365. CURL_USE_SCHANNEL
  366. CURL_USE_SECTRANSP
  367. CURL_USE_OPENSSL
  368. CURL_USE_MBEDTLS
  369. CURL_USE_BEARSSL
  370. CURL_USE_WOLFSSL
  371. )
  372. if(enabled_ssl_options_count GREATER "1")
  373. set(CURL_WITH_MULTI_SSL ON)
  374. endif()
  375. if(CURL_USE_SCHANNEL)
  376. set(SSL_ENABLED ON)
  377. set(USE_SCHANNEL ON) # Windows native SSL/TLS support
  378. set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI
  379. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "schannel")
  380. set(valid_default_ssl_backend TRUE)
  381. endif()
  382. endif()
  383. if(CURL_WINDOWS_SSPI)
  384. set(USE_WINDOWS_SSPI ON)
  385. endif()
  386. if(CURL_USE_SECTRANSP)
  387. set(use_core_foundation_and_core_services ON)
  388. find_library(SECURITY_FRAMEWORK "Security")
  389. if(NOT SECURITY_FRAMEWORK)
  390. message(FATAL_ERROR "Security framework not found")
  391. endif()
  392. set(SSL_ENABLED ON)
  393. set(USE_SECTRANSP ON)
  394. list(APPEND CURL_LIBS "-framework Security")
  395. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport")
  396. set(valid_default_ssl_backend TRUE)
  397. endif()
  398. endif()
  399. if(use_core_foundation_and_core_services)
  400. find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
  401. find_library(CORESERVICES_FRAMEWORK "CoreServices")
  402. if(NOT COREFOUNDATION_FRAMEWORK)
  403. message(FATAL_ERROR "CoreFoundation framework not found")
  404. endif()
  405. if(NOT CORESERVICES_FRAMEWORK)
  406. message(FATAL_ERROR "CoreServices framework not found")
  407. endif()
  408. list(APPEND CURL_LIBS "-framework CoreFoundation" "-framework CoreServices")
  409. endif()
  410. if(CURL_USE_OPENSSL)
  411. find_package(OpenSSL REQUIRED)
  412. set(SSL_ENABLED ON)
  413. set(USE_OPENSSL ON)
  414. # Depend on OpenSSL via imported targets if supported by the running
  415. # version of CMake. This allows our dependents to get our dependencies
  416. # transitively.
  417. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  418. list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
  419. else()
  420. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  421. include_directories(${OPENSSL_INCLUDE_DIR})
  422. endif()
  423. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "openssl")
  424. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl")
  425. set(valid_default_ssl_backend TRUE)
  426. endif()
  427. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  428. if(NOT DEFINED HAVE_BORINGSSL)
  429. check_symbol_exists(OPENSSL_IS_BORINGSSL "openssl/base.h" HAVE_BORINGSSL)
  430. endif()
  431. if(NOT DEFINED HAVE_AWSLC)
  432. check_symbol_exists(OPENSSL_IS_AWSLC "openssl/base.h" HAVE_AWSLC)
  433. endif()
  434. endif()
  435. if(CURL_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. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "mbedtls")
  441. include_directories(${MBEDTLS_INCLUDE_DIRS})
  442. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "mbedtls")
  443. set(valid_default_ssl_backend TRUE)
  444. endif()
  445. endif()
  446. if(CURL_USE_BEARSSL)
  447. find_package(BearSSL REQUIRED)
  448. set(SSL_ENABLED ON)
  449. set(USE_BEARSSL ON)
  450. list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
  451. include_directories(${BEARSSL_INCLUDE_DIRS})
  452. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "bearssl")
  453. set(valid_default_ssl_backend TRUE)
  454. endif()
  455. endif()
  456. if(CURL_USE_WOLFSSL)
  457. find_package(WolfSSL REQUIRED)
  458. set(SSL_ENABLED ON)
  459. set(USE_WOLFSSL ON)
  460. list(APPEND CURL_LIBS ${WolfSSL_LIBRARIES})
  461. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "wolfssl")
  462. include_directories(${WolfSSL_INCLUDE_DIRS})
  463. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "wolfssl")
  464. set(valid_default_ssl_backend TRUE)
  465. endif()
  466. endif()
  467. if(CURL_USE_GNUTLS)
  468. find_package(GnuTLS REQUIRED)
  469. set(SSL_ENABLED ON)
  470. set(USE_GNUTLS ON)
  471. list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES} "nettle")
  472. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "gnutls")
  473. include_directories(${GNUTLS_INCLUDE_DIRS})
  474. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls")
  475. set(valid_default_ssl_backend TRUE)
  476. endif()
  477. if(NOT DEFINED HAVE_GNUTLS_SRP AND NOT CURL_DISABLE_SRP)
  478. cmake_push_check_state()
  479. set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
  480. set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
  481. check_symbol_exists(gnutls_srp_verifier "gnutls/gnutls.h" HAVE_GNUTLS_SRP)
  482. cmake_pop_check_state()
  483. endif()
  484. endif()
  485. if(CURL_DEFAULT_SSL_BACKEND AND NOT valid_default_ssl_backend)
  486. message(FATAL_ERROR "CURL_DEFAULT_SSL_BACKEND '${CURL_DEFAULT_SSL_BACKEND}' not enabled.")
  487. endif()
  488. # Keep ZLIB detection after TLS detection,
  489. # and before calling openssl_check_symbol_exists().
  490. set(HAVE_LIBZ OFF)
  491. set(USE_ZLIB OFF)
  492. optional_dependency(ZLIB)
  493. if(ZLIB_FOUND)
  494. set(HAVE_LIBZ ON)
  495. set(USE_ZLIB ON)
  496. # Depend on ZLIB via imported targets if supported by the running
  497. # version of CMake. This allows our dependents to get our dependencies
  498. # transitively.
  499. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  500. list(APPEND CURL_LIBS ZLIB::ZLIB)
  501. else()
  502. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  503. include_directories(${ZLIB_INCLUDE_DIRS})
  504. endif()
  505. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "zlib")
  506. list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
  507. endif()
  508. option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
  509. set(HAVE_BROTLI OFF)
  510. if(CURL_BROTLI)
  511. find_package(Brotli REQUIRED)
  512. if(BROTLI_FOUND)
  513. set(HAVE_BROTLI ON)
  514. list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
  515. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libbrotlidec")
  516. include_directories(${BROTLI_INCLUDE_DIRS})
  517. list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
  518. endif()
  519. endif()
  520. option(CURL_ZSTD "Set to ON to enable building curl with zstd support." OFF)
  521. set(HAVE_ZSTD OFF)
  522. if(CURL_ZSTD)
  523. find_package(Zstd REQUIRED)
  524. if(Zstd_FOUND AND NOT Zstd_VERSION VERSION_LESS "1.0.0")
  525. set(HAVE_ZSTD ON)
  526. list(APPEND CURL_LIBS ${Zstd_LIBRARIES})
  527. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libzstd")
  528. include_directories(${Zstd_INCLUDE_DIRS})
  529. else()
  530. message(WARNING "zstd v1.0.0 or newer is required, disabling zstd support.")
  531. endif()
  532. endif()
  533. # Check symbol in an OpenSSL-like TLS backend, or in EXTRA_LIBS depending on it.
  534. macro(openssl_check_symbol_exists SYMBOL FILES VARIABLE EXTRA_LIBS)
  535. cmake_push_check_state()
  536. if(USE_OPENSSL)
  537. set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
  538. set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
  539. if(HAVE_LIBZ)
  540. list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
  541. endif()
  542. if(WIN32)
  543. list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
  544. list(APPEND CMAKE_REQUIRED_LIBRARIES "bcrypt") # for OpenSSL/LibreSSL
  545. endif()
  546. elseif(USE_WOLFSSL)
  547. set(CMAKE_REQUIRED_INCLUDES "${WolfSSL_INCLUDE_DIRS}")
  548. set(CMAKE_REQUIRED_LIBRARIES "${WolfSSL_LIBRARIES}")
  549. if(HAVE_LIBZ)
  550. list(APPEND CMAKE_REQUIRED_INCLUDES "${ZLIB_INCLUDE_DIRS}") # Public wolfSSL headers require zlib headers
  551. list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
  552. endif()
  553. if(WIN32)
  554. list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32" "crypt32")
  555. endif()
  556. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_UINTPTR_T) # to pull in stdint.h (as of wolfSSL v5.5.4)
  557. endif()
  558. if(NOT "${EXTRA_LIBS}" STREQUAL "")
  559. list(APPEND CMAKE_REQUIRED_LIBRARIES "${EXTRA_LIBS}")
  560. endif()
  561. check_symbol_exists("${SYMBOL}" "${FILES}" "${VARIABLE}")
  562. cmake_pop_check_state()
  563. endmacro()
  564. # Ensure that the OpenSSL fork actually supports QUIC.
  565. macro(openssl_check_quic)
  566. if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD)
  567. if(USE_OPENSSL)
  568. openssl_check_symbol_exists(SSL_CTX_set_quic_method "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD "")
  569. elseif(USE_WOLFSSL)
  570. openssl_check_symbol_exists(wolfSSL_set_quic_method "wolfssl/options.h;wolfssl/openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD "")
  571. endif()
  572. endif()
  573. if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD)
  574. message(FATAL_ERROR "QUIC support is missing in OpenSSL fork. Try setting -DOPENSSL_ROOT_DIR")
  575. endif()
  576. endmacro()
  577. if(USE_OPENSSL OR USE_WOLFSSL)
  578. if(NOT DEFINED HAVE_SSL_SET0_WBIO)
  579. openssl_check_symbol_exists(SSL_set0_wbio "openssl/ssl.h" HAVE_SSL_SET0_WBIO "")
  580. endif()
  581. if(NOT DEFINED HAVE_OPENSSL_SRP AND NOT CURL_DISABLE_SRP)
  582. openssl_check_symbol_exists(SSL_CTX_set_srp_username "openssl/ssl.h" HAVE_OPENSSL_SRP "")
  583. endif()
  584. endif()
  585. option(USE_HTTPSRR "Enable HTTPS RR support for ECH (experimental)" OFF)
  586. option(USE_ECH "Enable ECH support" OFF)
  587. if(USE_ECH)
  588. if(USE_OPENSSL OR USE_WOLFSSL)
  589. # Be sure that the TLS library actually supports ECH.
  590. if(NOT DEFINED HAVE_ECH)
  591. if(USE_OPENSSL AND HAVE_BORINGSSL)
  592. openssl_check_symbol_exists(SSL_set1_ech_config_list "openssl/ssl.h" HAVE_ECH "")
  593. elseif(USE_OPENSSL)
  594. openssl_check_symbol_exists(SSL_ech_set1_echconfig "openssl/ech.h" HAVE_ECH "")
  595. elseif(USE_WOLFSSL)
  596. openssl_check_symbol_exists(wolfSSL_CTX_GenerateEchConfig "wolfssl/options.h;wolfssl/ssl.h" HAVE_ECH "")
  597. endif()
  598. endif()
  599. if(NOT HAVE_ECH)
  600. message(FATAL_ERROR "ECH support missing in OpenSSL/BoringSSL/wolfSSL")
  601. else()
  602. message(STATUS "ECH enabled.")
  603. endif()
  604. else()
  605. message(FATAL_ERROR "ECH requires ECH-enablded OpenSSL, BoringSSL or wolfSSL")
  606. endif()
  607. endif()
  608. option(USE_NGHTTP2 "Use nghttp2 library" OFF)
  609. if(USE_NGHTTP2)
  610. find_package(NGHTTP2 REQUIRED)
  611. include_directories(${NGHTTP2_INCLUDE_DIRS})
  612. list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
  613. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp2")
  614. endif()
  615. option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF)
  616. if(USE_NGTCP2)
  617. if(USE_OPENSSL OR USE_WOLFSSL)
  618. if(USE_WOLFSSL)
  619. find_package(NGTCP2 REQUIRED wolfSSL)
  620. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_wolfssl")
  621. elseif(HAVE_BORINGSSL OR HAVE_AWSLC)
  622. find_package(NGTCP2 REQUIRED BoringSSL)
  623. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_boringssl")
  624. else()
  625. find_package(NGTCP2 REQUIRED quictls)
  626. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_quictls")
  627. endif()
  628. openssl_check_quic()
  629. elseif(USE_GNUTLS)
  630. find_package(NGTCP2 REQUIRED GnuTLS)
  631. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_gnutls")
  632. else()
  633. message(FATAL_ERROR "ngtcp2 requires OpenSSL, wolfSSL or GnuTLS")
  634. endif()
  635. set(USE_NGTCP2 ON)
  636. include_directories(${NGTCP2_INCLUDE_DIRS})
  637. list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES})
  638. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2")
  639. find_package(NGHTTP3 REQUIRED)
  640. set(USE_NGHTTP3 ON)
  641. include_directories(${NGHTTP3_INCLUDE_DIRS})
  642. list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
  643. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp3")
  644. endif()
  645. option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF)
  646. if(USE_QUICHE)
  647. if(USE_NGTCP2)
  648. message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
  649. endif()
  650. find_package(QUICHE REQUIRED)
  651. if(NOT HAVE_BORINGSSL)
  652. message(FATAL_ERROR "quiche requires BoringSSL")
  653. endif()
  654. openssl_check_quic()
  655. set(USE_QUICHE ON)
  656. include_directories(${QUICHE_INCLUDE_DIRS})
  657. list(APPEND CURL_LIBS ${QUICHE_LIBRARIES})
  658. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "quiche")
  659. if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD)
  660. cmake_push_check_state()
  661. set(CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}")
  662. set(CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}")
  663. check_symbol_exists(quiche_conn_set_qlog_fd "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD)
  664. cmake_pop_check_state()
  665. endif()
  666. endif()
  667. option(USE_MSH3 "Use msquic library for HTTP/3 support" OFF)
  668. if(USE_MSH3)
  669. if(USE_NGTCP2 OR USE_QUICHE)
  670. message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
  671. endif()
  672. set(USE_MSH3 ON)
  673. include_directories(${MSH3_INCLUDE_DIRS})
  674. list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
  675. endif()
  676. option(USE_OPENSSL_QUIC "Use openssl and nghttp3 libraries for HTTP/3 support" OFF)
  677. if(USE_OPENSSL_QUIC)
  678. if(USE_NGTCP2 OR USE_QUICHE OR USE_MSH3)
  679. message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
  680. endif()
  681. find_package(OpenSSL 3.2.0 REQUIRED)
  682. find_package(NGHTTP3 REQUIRED)
  683. set(USE_NGHTTP3 ON)
  684. include_directories(${NGHTTP3_INCLUDE_DIRS})
  685. list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
  686. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp3")
  687. endif()
  688. if(USE_MBEDTLS OR
  689. USE_BEARSSL OR
  690. USE_SECTRANSP)
  691. message(WARNING "A selected TLS library does not support TLS 1.3.")
  692. endif()
  693. if(CURL_WITH_MULTI_SSL AND (USE_NGTCP2 OR USE_QUICHE OR USE_MSH3 OR USE_OPENSSL_QUIC))
  694. message(FATAL_ERROR "MultiSSL cannot be enabled with HTTP/3 and vice versa.")
  695. endif()
  696. if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP))
  697. set(USE_TLS_SRP 1)
  698. endif()
  699. if(NOT CURL_DISABLE_LDAP)
  700. if(WIN32 AND NOT WINDOWS_STORE)
  701. option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
  702. if(USE_WIN32_LDAP)
  703. list(APPEND CURL_LIBS "wldap32")
  704. if(NOT CURL_DISABLE_LDAPS)
  705. set(HAVE_LDAP_SSL ON)
  706. endif()
  707. endif()
  708. endif()
  709. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  710. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  711. # Now that we know, we're not using windows LDAP...
  712. if(NOT USE_WIN32_LDAP)
  713. # Check for LDAP
  714. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  715. check_library_exists("${CMAKE_LDAP_LIB}" "ldap_init" "" HAVE_LIBLDAP)
  716. if(HAVE_LIBLDAP)
  717. check_library_exists("${CMAKE_LDAP_LIB};${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
  718. else()
  719. check_library_exists("${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
  720. endif()
  721. set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
  722. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  723. if(CMAKE_LDAP_INCLUDE_DIR)
  724. list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  725. endif()
  726. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  727. check_include_file_concat("lber.h" HAVE_LBER_H)
  728. if(NOT HAVE_LDAP_H)
  729. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  730. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  731. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  732. elseif(NOT HAVE_LIBLDAP)
  733. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  734. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  735. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  736. else()
  737. if(CMAKE_LDAP_INCLUDE_DIR)
  738. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  739. endif()
  740. set(NEED_LBER_H ON)
  741. set(_HEADER_LIST)
  742. if(WIN32)
  743. list(APPEND _HEADER_LIST "windows.h")
  744. endif()
  745. if(HAVE_SYS_TYPES_H)
  746. list(APPEND _HEADER_LIST "sys/types.h")
  747. endif()
  748. list(APPEND _HEADER_LIST "ldap.h")
  749. set(_INCLUDE_STRING "")
  750. foreach(_HEADER ${_HEADER_LIST})
  751. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  752. endforeach()
  753. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DLDAP_DEPRECATED=1)
  754. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  755. set(CURL_LIBS "${CMAKE_LDAP_LIB};${CURL_LIBS}")
  756. if(HAVE_LIBLBER)
  757. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  758. set(CURL_LIBS "${CMAKE_LBER_LIB};${CURL_LIBS}")
  759. endif()
  760. check_c_source_compiles("
  761. ${_INCLUDE_STRING}
  762. int main(int argc, char ** argv)
  763. {
  764. BerValue *bvp = NULL;
  765. BerElement *bep = ber_init(bvp);
  766. ber_free(bep, 1);
  767. return 0;
  768. }" NOT_NEED_LBER_H)
  769. if(NOT_NEED_LBER_H)
  770. set(NEED_LBER_H OFF)
  771. else()
  772. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  773. endif()
  774. check_function_exists(ldap_url_parse HAVE_LDAP_URL_PARSE)
  775. check_function_exists(ldap_init_fd HAVE_LDAP_INIT_FD)
  776. unset(CMAKE_REQUIRED_LIBRARIES)
  777. check_include_file("ldap_ssl.h" HAVE_LDAP_SSL_H)
  778. if(HAVE_LDAP_INIT_FD)
  779. set(USE_OPENLDAP ON)
  780. add_definitions("-DLDAP_DEPRECATED=1")
  781. endif()
  782. if(NOT CURL_DISABLE_LDAPS)
  783. set(HAVE_LDAP_SSL ON)
  784. endif()
  785. endif()
  786. endif()
  787. endif()
  788. # No ldap, no ldaps.
  789. if(CURL_DISABLE_LDAP)
  790. if(NOT CURL_DISABLE_LDAPS)
  791. message(STATUS "LDAP needs to be enabled to support LDAPS")
  792. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  793. endif()
  794. endif()
  795. # Check for idn2
  796. option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
  797. if(USE_LIBIDN2)
  798. check_library_exists("idn2" "idn2_lookup_ul" "" HAVE_LIBIDN2)
  799. if(HAVE_LIBIDN2)
  800. set(CURL_LIBS "idn2;${CURL_LIBS}")
  801. set(LIBCURL_PC_REQUIRES_PRIVATE "libidn2;${LIBCURL_PC_REQUIRES_PRIVATE}")
  802. check_include_file_concat("idn2.h" HAVE_IDN2_H)
  803. endif()
  804. else()
  805. set(HAVE_LIBIDN2 OFF)
  806. endif()
  807. if(WIN32)
  808. option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF)
  809. if(USE_WIN32_IDN)
  810. list(APPEND CURL_LIBS "normaliz")
  811. endif()
  812. endif()
  813. if(APPLE)
  814. option(USE_APPLE_IDN "Use Apple built-in IDN support" OFF)
  815. if(USE_APPLE_IDN)
  816. cmake_push_check_state()
  817. set(CMAKE_REQUIRED_LIBRARIES "icucore")
  818. check_symbol_exists("uidna_openUTS46" "unicode/uidna.h" HAVE_APPLE_IDN)
  819. cmake_pop_check_state()
  820. if(HAVE_APPLE_IDN)
  821. list(APPEND CURL_LIBS "icucore")
  822. else()
  823. set(USE_APPLE_IDN OFF)
  824. endif()
  825. endif()
  826. endif()
  827. # libpsl
  828. option(CURL_USE_LIBPSL "Use libpsl" ON)
  829. mark_as_advanced(CURL_USE_LIBPSL)
  830. set(USE_LIBPSL OFF)
  831. if(CURL_USE_LIBPSL)
  832. find_package(LibPSL)
  833. if(LIBPSL_FOUND)
  834. list(APPEND CURL_LIBS ${LIBPSL_LIBRARY})
  835. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libpsl")
  836. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIR}")
  837. include_directories("${LIBPSL_INCLUDE_DIR}")
  838. set(USE_LIBPSL ON)
  839. endif()
  840. endif()
  841. # libssh2
  842. option(CURL_USE_LIBSSH2 "Use libssh2" ON)
  843. mark_as_advanced(CURL_USE_LIBSSH2)
  844. set(USE_LIBSSH2 OFF)
  845. if(CURL_USE_LIBSSH2)
  846. find_package(LibSSH2)
  847. if(LIBSSH2_FOUND)
  848. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  849. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh2")
  850. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  851. include_directories("${LIBSSH2_INCLUDE_DIR}")
  852. set(USE_LIBSSH2 ON)
  853. endif()
  854. endif()
  855. # libssh
  856. option(CURL_USE_LIBSSH "Use libssh" OFF)
  857. mark_as_advanced(CURL_USE_LIBSSH)
  858. if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
  859. find_package(libssh CONFIG)
  860. if(libssh_FOUND)
  861. message(STATUS "Found libssh ${libssh_VERSION}")
  862. # Use imported target for include and library paths.
  863. list(APPEND CURL_LIBS ssh)
  864. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh")
  865. set(USE_LIBSSH ON)
  866. endif()
  867. endif()
  868. option(CURL_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
  869. mark_as_advanced(CURL_USE_GSSAPI)
  870. if(CURL_USE_GSSAPI)
  871. find_package(GSS)
  872. set(HAVE_GSSAPI ${GSS_FOUND})
  873. if(GSS_FOUND)
  874. message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
  875. list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
  876. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  877. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  878. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  879. if(NOT GSS_FLAVOUR STREQUAL "Heimdal")
  880. # MIT
  881. set(_INCLUDE_LIST "")
  882. if(HAVE_GSSAPI_GSSAPI_H)
  883. list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
  884. endif()
  885. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  886. list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
  887. endif()
  888. if(HAVE_GSSAPI_GSSAPI_KRB5_H)
  889. list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
  890. endif()
  891. string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
  892. string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
  893. foreach(_dir ${GSS_LINK_DIRECTORIES})
  894. set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
  895. endforeach()
  896. if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  897. set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
  898. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  899. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  900. unset(CMAKE_REQUIRED_LIBRARIES)
  901. endif()
  902. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  903. set(HAVE_OLD_GSSMIT ON)
  904. endif()
  905. endif()
  906. include_directories(${GSS_INCLUDE_DIR})
  907. link_directories(${GSS_LINK_DIRECTORIES})
  908. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
  909. string(REPLACE ";" " " GSS_LINKER_FLAGS "${GSS_LINKER_FLAGS}")
  910. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  911. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  912. list(APPEND CURL_LIBS ${GSS_LIBRARIES})
  913. else()
  914. message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
  915. endif()
  916. endif()
  917. option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF)
  918. if(USE_LIBRTMP)
  919. cmake_push_check_state()
  920. set(_extra_libs "rtmp")
  921. if(WIN32)
  922. list(APPEND _extra_libs "winmm")
  923. endif()
  924. openssl_check_symbol_exists("RTMP_Init" "librtmp/rtmp.h" HAVE_LIBRTMP "${_extra_libs}")
  925. cmake_pop_check_state()
  926. if(HAVE_LIBRTMP)
  927. list(APPEND CURL_LIBS "rtmp")
  928. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "librtmp")
  929. if(WIN32)
  930. list(APPEND CURL_LIBS "winmm")
  931. endif()
  932. else()
  933. message(WARNING "librtmp requested, but not found or missing OpenSSL. Skipping.")
  934. set(USE_LIBRTMP OFF)
  935. endif()
  936. endif()
  937. option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
  938. if(ENABLE_UNIX_SOCKETS)
  939. include(CheckStructHasMember)
  940. if(WIN32)
  941. set(USE_UNIX_SOCKETS ON)
  942. else()
  943. check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
  944. endif()
  945. else()
  946. unset(USE_UNIX_SOCKETS CACHE)
  947. endif()
  948. #
  949. # CA handling
  950. #
  951. set(CURL_CA_BUNDLE "auto" CACHE STRING
  952. "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  953. set(CURL_CA_FALLBACK OFF CACHE BOOL
  954. "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
  955. set(CURL_CA_PATH "auto" CACHE STRING
  956. "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  957. if("${CURL_CA_BUNDLE}" STREQUAL "")
  958. message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
  959. elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
  960. unset(CURL_CA_BUNDLE CACHE)
  961. elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
  962. unset(CURL_CA_BUNDLE CACHE)
  963. if(NOT CMAKE_CROSSCOMPILING)
  964. set(CURL_CA_BUNDLE_AUTODETECT TRUE)
  965. endif()
  966. else()
  967. set(CURL_CA_BUNDLE_SET TRUE)
  968. endif()
  969. if("${CURL_CA_PATH}" STREQUAL "")
  970. message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
  971. elseif("${CURL_CA_PATH}" STREQUAL "none")
  972. unset(CURL_CA_PATH CACHE)
  973. elseif("${CURL_CA_PATH}" STREQUAL "auto")
  974. unset(CURL_CA_PATH CACHE)
  975. if(NOT CMAKE_CROSSCOMPILING)
  976. set(CURL_CA_PATH_AUTODETECT TRUE)
  977. endif()
  978. else()
  979. set(CURL_CA_PATH_SET TRUE)
  980. endif()
  981. if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
  982. # Skip autodetection of unset CA path because CA bundle is set explicitly
  983. elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
  984. # Skip autodetection of unset CA bundle because CA path is set explicitly
  985. elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
  986. # first try autodetecting a CA bundle, then a CA path
  987. if(CURL_CA_BUNDLE_AUTODETECT)
  988. set(SEARCH_CA_BUNDLE_PATHS
  989. /etc/ssl/certs/ca-certificates.crt
  990. /etc/pki/tls/certs/ca-bundle.crt
  991. /usr/share/ssl/certs/ca-bundle.crt
  992. /usr/local/share/certs/ca-root-nss.crt
  993. /etc/ssl/cert.pem)
  994. foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
  995. if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
  996. message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
  997. set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}" CACHE STRING
  998. "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  999. set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  1000. break()
  1001. endif()
  1002. endforeach()
  1003. endif()
  1004. if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
  1005. if(EXISTS "/etc/ssl/certs")
  1006. set(CURL_CA_PATH "/etc/ssl/certs" CACHE STRING
  1007. "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  1008. set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  1009. endif()
  1010. endif()
  1011. endif()
  1012. if(CURL_CA_PATH_SET AND
  1013. NOT USE_OPENSSL AND
  1014. NOT USE_WOLFSSL AND
  1015. NOT USE_GNUTLS AND
  1016. NOT USE_MBEDTLS)
  1017. message(STATUS
  1018. "CA path only supported by OpenSSL, wolfSSL, GnuTLS or mbedTLS. "
  1019. "Set CURL_CA_PATH=none or enable one of those TLS backends.")
  1020. endif()
  1021. # Check for header files
  1022. if(WIN32)
  1023. set(CURL_INCLUDES ${CURL_INCLUDES} "winsock2.h")
  1024. set(CURL_INCLUDES ${CURL_INCLUDES} "ws2tcpip.h")
  1025. set(CURL_INCLUDES ${CURL_INCLUDES} "windows.h")
  1026. endif()
  1027. if(WIN32)
  1028. # detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
  1029. curl_internal_test(HAVE_WIN32_WINNT)
  1030. if(HAVE_WIN32_WINNT)
  1031. string(REGEX MATCH ".*_WIN32_WINNT=0x[0-9a-fA-F]+" OUTPUT "${OUTPUT}")
  1032. string(REGEX REPLACE ".*_WIN32_WINNT=" "" OUTPUT "${OUTPUT}")
  1033. string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" OUTPUT "${OUTPUT}") # pad to 4 digits
  1034. string(TOLOWER "${OUTPUT}" HAVE_WIN32_WINNT)
  1035. message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
  1036. endif()
  1037. # avoid storing HAVE_WIN32_WINNT in CMake cache
  1038. unset(HAVE_WIN32_WINNT CACHE)
  1039. if(HAVE_WIN32_WINNT)
  1040. if(HAVE_WIN32_WINNT STRLESS "0x0501")
  1041. # Windows XP is required for freeaddrinfo, getaddrinfo
  1042. message(FATAL_ERROR "Building for Windows XP or newer is required.")
  1043. endif()
  1044. # pre-fill detection results based on target OS version
  1045. if(MINGW OR MSVC)
  1046. if(HAVE_WIN32_WINNT STRLESS "0x0600")
  1047. set(HAVE_INET_NTOP 0)
  1048. set(HAVE_INET_PTON 0)
  1049. else() # Windows Vista or newer
  1050. set(HAVE_INET_NTOP 1)
  1051. set(HAVE_INET_PTON 1)
  1052. endif()
  1053. unset(HAVE_INET_NTOP CACHE)
  1054. unset(HAVE_INET_PTON CACHE)
  1055. endif()
  1056. endif()
  1057. endif()
  1058. check_include_file_concat("sys/eventfd.h" HAVE_SYS_EVENTFD_H)
  1059. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  1060. check_include_file_concat("sys/wait.h" HAVE_SYS_WAIT_H)
  1061. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  1062. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  1063. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  1064. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  1065. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  1066. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  1067. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  1068. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  1069. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  1070. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  1071. check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
  1072. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  1073. check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
  1074. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  1075. check_include_file_concat("dirent.h" HAVE_DIRENT_H)
  1076. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  1077. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  1078. check_include_file_concat("io.h" HAVE_IO_H)
  1079. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  1080. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  1081. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  1082. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  1083. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  1084. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
  1085. check_include_file_concat("netinet/udp.h" HAVE_NETINET_UDP_H)
  1086. check_include_file("linux/tcp.h" HAVE_LINUX_TCP_H)
  1087. check_include_file_concat("poll.h" HAVE_POLL_H)
  1088. check_include_file_concat("pwd.h" HAVE_PWD_H)
  1089. check_include_file_concat("stdatomic.h" HAVE_STDATOMIC_H)
  1090. check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
  1091. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  1092. check_include_file_concat("stropts.h" HAVE_STROPTS_H)
  1093. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  1094. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  1095. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  1096. check_include_file_concat("utime.h" HAVE_UTIME_H)
  1097. check_type_size(size_t SIZEOF_SIZE_T)
  1098. check_type_size(ssize_t SIZEOF_SSIZE_T)
  1099. check_type_size("long long" SIZEOF_LONG_LONG)
  1100. check_type_size("long" SIZEOF_LONG)
  1101. check_type_size("int" SIZEOF_INT)
  1102. check_type_size("__int64" SIZEOF___INT64)
  1103. check_type_size("time_t" SIZEOF_TIME_T)
  1104. check_type_size("suseconds_t" SIZEOF_SUSECONDS_T)
  1105. if(NOT HAVE_SIZEOF_SSIZE_T)
  1106. if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  1107. set(ssize_t long)
  1108. endif()
  1109. if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  1110. set(ssize_t __int64)
  1111. endif()
  1112. endif()
  1113. # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
  1114. if(SIZEOF_LONG_LONG)
  1115. set(HAVE_LONGLONG 1)
  1116. endif()
  1117. if(SIZEOF_SUSECONDS_T)
  1118. set(HAVE_SUSECONDS_T 1)
  1119. endif()
  1120. if(NOT CMAKE_CROSSCOMPILING)
  1121. find_file(RANDOM_FILE urandom /dev)
  1122. mark_as_advanced(RANDOM_FILE)
  1123. endif()
  1124. # Check for some functions that are used
  1125. if(WIN32)
  1126. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  1127. elseif(HAVE_LIBSOCKET)
  1128. set(CMAKE_REQUIRED_LIBRARIES socket)
  1129. endif()
  1130. check_symbol_exists(fnmatch "${CURL_INCLUDES};fnmatch.h" HAVE_FNMATCH)
  1131. check_symbol_exists(basename "${CURL_INCLUDES};string.h" HAVE_BASENAME)
  1132. check_symbol_exists(opendir "${CURL_INCLUDES};dirent.h" HAVE_OPENDIR)
  1133. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  1134. check_symbol_exists(sched_yield "${CURL_INCLUDES};sched.h" HAVE_SCHED_YIELD)
  1135. check_symbol_exists(socketpair "${CURL_INCLUDES}" HAVE_SOCKETPAIR)
  1136. check_symbol_exists(recv "${CURL_INCLUDES}" HAVE_RECV)
  1137. check_symbol_exists(send "${CURL_INCLUDES}" HAVE_SEND)
  1138. check_symbol_exists(sendmsg "${CURL_INCLUDES}" HAVE_SENDMSG)
  1139. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  1140. check_symbol_exists(strdup "${CURL_INCLUDES};string.h" HAVE_STRDUP)
  1141. check_symbol_exists(strtok_r "${CURL_INCLUDES};string.h" HAVE_STRTOK_R)
  1142. check_symbol_exists(strcasecmp "${CURL_INCLUDES};string.h" HAVE_STRCASECMP)
  1143. check_symbol_exists(stricmp "${CURL_INCLUDES};string.h" HAVE_STRICMP)
  1144. check_symbol_exists(strcmpi "${CURL_INCLUDES};string.h" HAVE_STRCMPI)
  1145. check_symbol_exists(memrchr "${CURL_INCLUDES};string.h" HAVE_MEMRCHR)
  1146. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  1147. check_symbol_exists(arc4random "${CURL_INCLUDES};stdlib.h" HAVE_ARC4RANDOM)
  1148. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  1149. check_symbol_exists(getppid "${CURL_INCLUDES}" HAVE_GETPPID)
  1150. check_symbol_exists(utimes "${CURL_INCLUDES}" HAVE_UTIMES)
  1151. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  1152. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  1153. check_symbol_exists(sigsetjmp "${CURL_INCLUDES};setjmp.h" HAVE_SIGSETJMP)
  1154. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  1155. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  1156. check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
  1157. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  1158. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  1159. check_symbol_exists(gmtime_r "${CURL_INCLUDES};stdlib.h;time.h" HAVE_GMTIME_R)
  1160. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  1161. check_symbol_exists(signal "${CURL_INCLUDES};signal.h" HAVE_SIGNAL)
  1162. check_symbol_exists(strtoll "${CURL_INCLUDES};stdlib.h" HAVE_STRTOLL)
  1163. check_symbol_exists(strerror_r "${CURL_INCLUDES};stdlib.h;string.h" HAVE_STRERROR_R)
  1164. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  1165. check_symbol_exists(siginterrupt "${CURL_INCLUDES};signal.h" HAVE_SIGINTERRUPT)
  1166. check_symbol_exists(getaddrinfo "${CURL_INCLUDES};stdlib.h;string.h" HAVE_GETADDRINFO)
  1167. check_symbol_exists(getifaddrs "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS)
  1168. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  1169. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  1170. check_symbol_exists(eventfd "${CURL_INCLUDES};sys/eventfd.h" HAVE_EVENTFD)
  1171. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  1172. check_symbol_exists(_fseeki64 "${CURL_INCLUDES};stdio.h" HAVE__FSEEKI64)
  1173. check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
  1174. check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
  1175. check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
  1176. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  1177. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  1178. check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
  1179. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  1180. if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900))
  1181. # earlier MSVC compilers had faulty snprintf implementations
  1182. check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
  1183. endif()
  1184. check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
  1185. check_symbol_exists(inet_ntop "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP)
  1186. if(MSVC AND (MSVC_VERSION LESS_EQUAL 1600))
  1187. set(HAVE_INET_NTOP OFF)
  1188. endif()
  1189. check_symbol_exists(inet_pton "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON)
  1190. check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
  1191. if(HAVE_FSETXATTR)
  1192. foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
  1193. curl_internal_test(${CURL_TEST})
  1194. endforeach()
  1195. endif()
  1196. set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
  1197. check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T)
  1198. set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T})
  1199. set(CMAKE_EXTRA_INCLUDE_FILES "")
  1200. if(WIN32)
  1201. set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h")
  1202. check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY)
  1203. set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY})
  1204. set(CMAKE_EXTRA_INCLUDE_FILES "")
  1205. endif()
  1206. # Do curl specific tests
  1207. foreach(CURL_TEST
  1208. HAVE_FCNTL_O_NONBLOCK
  1209. HAVE_IOCTLSOCKET
  1210. HAVE_IOCTLSOCKET_CAMEL
  1211. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  1212. HAVE_IOCTLSOCKET_FIONBIO
  1213. HAVE_IOCTL_FIONBIO
  1214. HAVE_IOCTL_SIOCGIFADDR
  1215. HAVE_SETSOCKOPT_SO_NONBLOCK
  1216. HAVE_O_NONBLOCK
  1217. HAVE_GETHOSTBYNAME_R_3
  1218. HAVE_GETHOSTBYNAME_R_5
  1219. HAVE_GETHOSTBYNAME_R_6
  1220. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  1221. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  1222. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  1223. HAVE_IN_ADDR_T
  1224. HAVE_BOOL_T
  1225. STDC_HEADERS
  1226. HAVE_FILE_OFFSET_BITS
  1227. HAVE_ATOMIC
  1228. )
  1229. curl_internal_test(${CURL_TEST})
  1230. endforeach()
  1231. if(HAVE_FILE_OFFSET_BITS)
  1232. set(_FILE_OFFSET_BITS 64)
  1233. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  1234. endif()
  1235. check_type_size("off_t" SIZEOF_OFF_T)
  1236. # fseeko may not exist with _FILE_OFFSET_BITS=64 but can exist with
  1237. # _FILE_OFFSET_BITS unset or 32 (e.g. Android ARMv7 with NDK 26b and API level < 24)
  1238. # so we need to test fseeko after testing for _FILE_OFFSET_BITS
  1239. check_symbol_exists(fseeko "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
  1240. if(HAVE_FSEEKO)
  1241. set(HAVE_DECL_FSEEKO 1)
  1242. endif()
  1243. # include this header to get the type
  1244. set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
  1245. set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
  1246. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  1247. set(CMAKE_EXTRA_INCLUDE_FILES "curl/curl.h")
  1248. check_type_size("curl_socket_t" SIZEOF_CURL_SOCKET_T)
  1249. set(CMAKE_EXTRA_INCLUDE_FILES "")
  1250. if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
  1251. # on not-Windows and not-crosscompiling, check for writable argv[]
  1252. include(CheckCSourceRuns)
  1253. check_c_source_runs("
  1254. int main(int argc, char **argv)
  1255. {
  1256. (void)argc;
  1257. argv[0][0] = ' ';
  1258. return (argv[0][0] == ' ')?0:1;
  1259. }" HAVE_WRITABLE_ARGV)
  1260. endif()
  1261. set(CMAKE_REQUIRED_FLAGS)
  1262. option(ENABLE_WEBSOCKETS "Set to ON to enable EXPERIMENTAL websockets" OFF)
  1263. if(ENABLE_WEBSOCKETS)
  1264. if(${SIZEOF_CURL_OFF_T} GREATER "4")
  1265. set(USE_WEBSOCKETS ON)
  1266. else()
  1267. message(WARNING "curl_off_t is too small to enable WebSockets")
  1268. endif()
  1269. endif()
  1270. foreach(CURL_TEST
  1271. HAVE_GLIBC_STRERROR_R
  1272. HAVE_POSIX_STRERROR_R
  1273. )
  1274. curl_internal_test(${CURL_TEST})
  1275. endforeach()
  1276. # Check for reentrant
  1277. foreach(CURL_TEST
  1278. HAVE_GETHOSTBYNAME_R_3
  1279. HAVE_GETHOSTBYNAME_R_5
  1280. HAVE_GETHOSTBYNAME_R_6)
  1281. if(NOT ${CURL_TEST})
  1282. if(${CURL_TEST}_REENTRANT)
  1283. set(NEED_REENTRANT 1)
  1284. endif()
  1285. endif()
  1286. endforeach()
  1287. if(NEED_REENTRANT)
  1288. foreach(CURL_TEST
  1289. HAVE_GETHOSTBYNAME_R_3
  1290. HAVE_GETHOSTBYNAME_R_5
  1291. HAVE_GETHOSTBYNAME_R_6)
  1292. set(${CURL_TEST} 0)
  1293. if(${CURL_TEST}_REENTRANT)
  1294. set(${CURL_TEST} 1)
  1295. endif()
  1296. endforeach()
  1297. endif()
  1298. if(NOT WIN32)
  1299. # Check clock_gettime(CLOCK_MONOTONIC, x) support
  1300. curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
  1301. endif()
  1302. # Check compiler support of __builtin_available()
  1303. curl_internal_test(HAVE_BUILTIN_AVAILABLE)
  1304. # Some other minor tests
  1305. if(NOT HAVE_IN_ADDR_T)
  1306. set(in_addr_t "unsigned long")
  1307. endif()
  1308. # Check for nonblocking
  1309. set(HAVE_DISABLED_NONBLOCKING 1)
  1310. if(HAVE_FIONBIO OR
  1311. HAVE_IOCTLSOCKET OR
  1312. HAVE_IOCTLSOCKET_CASE OR
  1313. HAVE_O_NONBLOCK)
  1314. set(HAVE_DISABLED_NONBLOCKING)
  1315. endif()
  1316. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  1317. include(CheckCCompilerFlag)
  1318. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  1319. if(HAVE_C_FLAG_Wno_long_double)
  1320. # The Mac version of GCC warns about use of long double. Disable it.
  1321. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  1322. if(MPRINTF_COMPILE_FLAGS)
  1323. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  1324. else()
  1325. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  1326. endif()
  1327. set_source_files_properties(mprintf.c PROPERTIES
  1328. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  1329. endif()
  1330. endif()
  1331. include(CMake/OtherTests.cmake)
  1332. add_definitions(-DHAVE_CONFIG_H)
  1333. # For Windows, all compilers used by CMake should support large files
  1334. if(WIN32)
  1335. set(USE_WIN32_LARGE_FILES ON)
  1336. # Use the manifest embedded in the Windows Resource
  1337. set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
  1338. # We use crypto functions that are not available for UWP apps
  1339. if(NOT WINDOWS_STORE)
  1340. set(USE_WIN32_CRYPTO ON)
  1341. endif()
  1342. # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL
  1343. if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
  1344. list(APPEND CURL_LIBS "advapi32" "crypt32")
  1345. endif()
  1346. endif()
  1347. if(MSVC)
  1348. # Disable default manifest added by CMake
  1349. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
  1350. add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  1351. if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
  1352. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  1353. else()
  1354. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  1355. endif()
  1356. # Use multithreaded compilation on VS 2008+
  1357. if(MSVC_VERSION GREATER_EQUAL 1500)
  1358. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
  1359. endif()
  1360. endif()
  1361. if(CURL_WERROR)
  1362. if(MSVC_VERSION)
  1363. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
  1364. else()
  1365. # this assumes clang or gcc style options
  1366. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
  1367. endif()
  1368. endif()
  1369. if(CURL_LTO)
  1370. if(CMAKE_VERSION VERSION_LESS 3.9)
  1371. message(FATAL_ERROR "Requested LTO but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
  1372. endif()
  1373. cmake_policy(SET CMP0069 NEW)
  1374. include(CheckIPOSupported)
  1375. check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT CURL_LTO_ERROR LANGUAGES C)
  1376. if(CURL_HAS_LTO)
  1377. message(STATUS "LTO supported and enabled")
  1378. else()
  1379. message(FATAL_ERROR "LTO was requested - but compiler doesn't support it\n${CURL_LTO_ERROR}")
  1380. endif()
  1381. endif()
  1382. # Ugly (but functional) way to include "Makefile.inc" by transforming it
  1383. # (= regenerate it).
  1384. function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
  1385. file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
  1386. string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1387. string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1388. string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1389. string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1390. string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1391. string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
  1392. 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.
  1393. file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
  1394. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}")
  1395. endfunction()
  1396. include(GNUInstallDirs)
  1397. set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  1398. set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
  1399. set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
  1400. set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
  1401. set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
  1402. cmake_dependent_option(BUILD_TESTING "Build tests"
  1403. ON "PERL_FOUND;NOT CURL_DISABLE_TESTS"
  1404. OFF)
  1405. if(HAVE_MANUAL_TOOLS)
  1406. add_subdirectory(docs)
  1407. endif()
  1408. add_subdirectory(lib)
  1409. if(BUILD_CURL_EXE)
  1410. add_subdirectory(src)
  1411. endif()
  1412. option(BUILD_EXAMPLES "Build libcurl examples" OFF)
  1413. if(BUILD_EXAMPLES)
  1414. add_subdirectory(docs/examples)
  1415. endif()
  1416. if(BUILD_TESTING)
  1417. add_subdirectory(tests)
  1418. endif()
  1419. if(NOT CURL_DISABLE_INSTALL)
  1420. install(FILES "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl"
  1421. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1422. PERMISSIONS
  1423. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1424. GROUP_READ GROUP_EXECUTE
  1425. WORLD_READ WORLD_EXECUTE)
  1426. # Helper to populate a list (_items) with a label when conditions
  1427. # (the remaining args) are satisfied
  1428. macro(_add_if label)
  1429. # needs to be a macro to allow this indirection
  1430. if(${ARGN})
  1431. set(_items ${_items} "${label}")
  1432. endif()
  1433. endmacro()
  1434. # NTLM support requires crypto function adaptions from various SSL libs
  1435. if(NOT (CURL_DISABLE_NTLM) AND
  1436. (USE_OPENSSL OR USE_MBEDTLS OR USE_DARWINSSL OR USE_WIN32_CRYPTO OR USE_GNUTLS))
  1437. set(use_curl_ntlm_core ON)
  1438. endif()
  1439. # Clear list and try to detect available features
  1440. set(_items)
  1441. _add_if("SSL" SSL_ENABLED)
  1442. _add_if("IPv6" ENABLE_IPV6)
  1443. _add_if("UnixSockets" USE_UNIX_SOCKETS)
  1444. _add_if("libz" HAVE_LIBZ)
  1445. _add_if("brotli" HAVE_BROTLI)
  1446. _add_if("zstd" HAVE_ZSTD)
  1447. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
  1448. _add_if("IDN" HAVE_LIBIDN2 OR USE_WIN32_IDN OR USE_APPLE_IDN)
  1449. _add_if("Largefile" (SIZEOF_CURL_OFF_T GREATER 4) AND
  1450. ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
  1451. _add_if("SSPI" USE_WINDOWS_SSPI)
  1452. _add_if("GSS-API" HAVE_GSSAPI)
  1453. _add_if("alt-svc" NOT CURL_DISABLE_ALTSVC)
  1454. _add_if("HSTS" NOT CURL_DISABLE_HSTS)
  1455. _add_if("SPNEGO" NOT CURL_DISABLE_NEGOTIATE_AUTH AND
  1456. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1457. _add_if("Kerberos" NOT CURL_DISABLE_KERBEROS_AUTH AND
  1458. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1459. _add_if("NTLM" NOT (CURL_DISABLE_NTLM) AND
  1460. (use_curl_ntlm_core OR USE_WINDOWS_SSPI))
  1461. _add_if("TLS-SRP" USE_TLS_SRP)
  1462. _add_if("HTTP2" USE_NGHTTP2)
  1463. _add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE OR USE_OPENSSL_QUIC)
  1464. _add_if("MultiSSL" CURL_WITH_MULTI_SSL)
  1465. # TODO wolfSSL only support this from v5.0.0 onwards
  1466. _add_if("HTTPS-proxy" SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS
  1467. OR USE_SCHANNEL OR USE_RUSTLS OR USE_BEARSSL OR
  1468. USE_MBEDTLS OR USE_SECTRANSP))
  1469. _add_if("unicode" ENABLE_UNICODE)
  1470. _add_if("threadsafe" HAVE_ATOMIC OR
  1471. (USE_THREADS_POSIX AND HAVE_PTHREAD_H) OR
  1472. (WIN32 AND HAVE_WIN32_WINNT GREATER_EQUAL 0x600))
  1473. _add_if("PSL" USE_LIBPSL)
  1474. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1475. message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
  1476. # Clear list and try to detect available protocols
  1477. set(_items)
  1478. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1479. _add_if("IPFS" NOT CURL_DISABLE_HTTP)
  1480. _add_if("IPNS" NOT CURL_DISABLE_HTTP)
  1481. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
  1482. _add_if("ECH" HAVE_ECH)
  1483. _add_if("HTTPSRR" HAVE_ECH)
  1484. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1485. _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
  1486. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1487. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1488. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1489. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1490. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1491. ((USE_OPENLDAP AND SSL_ENABLED) OR
  1492. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1493. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1494. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1495. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1496. _add_if("GOPHERS" NOT CURL_DISABLE_GOPHER AND SSL_ENABLED)
  1497. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1498. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
  1499. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1500. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
  1501. _add_if("SMB" NOT CURL_DISABLE_SMB AND
  1502. use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
  1503. _add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND
  1504. use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
  1505. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1506. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
  1507. _add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH)
  1508. _add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH)
  1509. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1510. _add_if("RTMP" USE_LIBRTMP)
  1511. _add_if("MQTT" NOT CURL_DISABLE_MQTT)
  1512. _add_if("WS" USE_WEBSOCKETS)
  1513. _add_if("WSS" USE_WEBSOCKETS AND SSL_ENABLED)
  1514. if(_items)
  1515. list(SORT _items)
  1516. endif()
  1517. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1518. message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
  1519. # Clear list and collect SSL backends
  1520. set(_items)
  1521. _add_if("Schannel" SSL_ENABLED AND USE_SCHANNEL)
  1522. _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
  1523. _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
  1524. _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
  1525. _add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL)
  1526. _add_if("wolfSSL" SSL_ENABLED AND USE_WOLFSSL)
  1527. _add_if("GnuTLS" SSL_ENABLED AND USE_GNUTLS)
  1528. if(_items)
  1529. list(SORT _items)
  1530. endif()
  1531. string(REPLACE ";" " " SSL_BACKENDS "${_items}")
  1532. message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
  1533. if(CURL_DEFAULT_SSL_BACKEND)
  1534. message(STATUS "Default SSL backend: ${CURL_DEFAULT_SSL_BACKEND}")
  1535. endif()
  1536. # curl-config needs the following options to be set.
  1537. set(CC "${CMAKE_C_COMPILER}")
  1538. # TODO probably put a -D... options here?
  1539. set(CONFIGURE_OPTIONS "")
  1540. set(CURLVERSION "${CURL_VERSION}")
  1541. set(exec_prefix "\${prefix}")
  1542. set(includedir "\${prefix}/include")
  1543. set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  1544. set(LIBCURL_LIBS "")
  1545. set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
  1546. # For processing full path libraries into -L and -l ld options,
  1547. # the directories that go with the -L option are cached, so they
  1548. # only get added once per such directory.
  1549. set(_libcurl_libs_dirs)
  1550. # To avoid getting unnecessary -L options for known system directories,
  1551. # _libcurl_libs_dirs is seeded with them.
  1552. foreach(_libdir ${CMAKE_SYSTEM_PREFIX_PATH})
  1553. if(_libdir MATCHES "/$")
  1554. set(_libdir "${_libdir}lib")
  1555. else()
  1556. set(_libdir "${_libdir}/lib")
  1557. endif()
  1558. if(IS_DIRECTORY "${_libdir}")
  1559. list(APPEND _libcurl_libs_dirs "${_libdir}")
  1560. endif()
  1561. if(DEFINED CMAKE_LIBRARY_ARCHITECTURE)
  1562. set(_libdir "${_libdir}/${CMAKE_LIBRARY_ARCHITECTURE}")
  1563. if(IS_DIRECTORY "${_libdir}")
  1564. list(APPEND _libcurl_libs_dirs "${_libdir}")
  1565. endif()
  1566. endif()
  1567. endforeach()
  1568. foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
  1569. if(TARGET "${_lib}")
  1570. set(_libname "${_lib}")
  1571. get_target_property(_imported "${_libname}" IMPORTED)
  1572. if(NOT _imported)
  1573. # Reading the LOCATION property on non-imported target will error out.
  1574. # Assume the user won't need this information in the .pc file.
  1575. continue()
  1576. endif()
  1577. get_target_property(_lib "${_libname}" LOCATION)
  1578. if(NOT _lib)
  1579. message(WARNING "Bad lib in library list: ${_libname}")
  1580. continue()
  1581. endif()
  1582. endif()
  1583. if(_lib MATCHES "^-")
  1584. set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
  1585. elseif(_lib MATCHES ".*/.*")
  1586. # This gets a bit more complex, because we want to specify the
  1587. # directory separately, and only once per directory
  1588. string(REGEX REPLACE "^(.*)/[^/]*$" "\\1" _libdir "${_lib}")
  1589. string(REGEX REPLACE "^.*/([^/.]*).*$" "\\1" _libname "${_lib}")
  1590. if(_libname MATCHES "^lib")
  1591. list(FIND _libcurl_libs_dirs "${_libdir}" _libdir_index)
  1592. if(_libdir_index LESS 0)
  1593. list(APPEND _libcurl_libs_dirs "${_libdir}")
  1594. set(LIBCURL_LIBS "${LIBCURL_LIBS} -L${_libdir}")
  1595. endif()
  1596. string(REGEX REPLACE "^lib" "" _libname "${_libname}")
  1597. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_libname}")
  1598. else()
  1599. set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
  1600. endif()
  1601. else()
  1602. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
  1603. endif()
  1604. endforeach()
  1605. # Export a .pc file for client projects not using CMake
  1606. if(LIBCURL_PC_REQUIRES_PRIVATE)
  1607. string(REPLACE ";" "," LIBCURL_PC_REQUIRES_PRIVATE "${LIBCURL_PC_REQUIRES_PRIVATE}")
  1608. endif()
  1609. # Merge pkg-config private fields into public ones when static-only
  1610. if(BUILD_SHARED_LIBS)
  1611. set(ENABLE_SHARED "yes")
  1612. set(LIBCURL_PC_REQUIRES "")
  1613. set(LIBCURL_NO_SHARED "")
  1614. set(CPPFLAG_CURL_STATICLIB "")
  1615. else()
  1616. set(ENABLE_SHARED "no")
  1617. set(LIBCURL_PC_REQUIRES "${LIBCURL_PC_REQUIRES_PRIVATE}")
  1618. set(LIBCURL_NO_SHARED "${LIBCURL_LIBS}")
  1619. set(CPPFLAG_CURL_STATICLIB "-DCURL_STATICLIB")
  1620. endif()
  1621. if(BUILD_STATIC_LIBS)
  1622. set(ENABLE_STATIC "yes")
  1623. else()
  1624. set(ENABLE_STATIC "no")
  1625. endif()
  1626. # "a" (Linux) or "lib" (Windows)
  1627. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1628. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1629. # Set this to "yes" to append all libraries on which -lcurl is dependent
  1630. set(REQUIRE_LIB_DEPS "no")
  1631. # SUPPORT_FEATURES
  1632. # SUPPORT_PROTOCOLS
  1633. set(VERSIONNUM "${CURL_VERSION_NUM}")
  1634. # Finally generate a "curl-config" matching this config
  1635. # Use:
  1636. # * ENABLE_SHARED
  1637. # * ENABLE_STATIC
  1638. configure_file("${CURL_SOURCE_DIR}/curl-config.in"
  1639. "${CURL_BINARY_DIR}/curl-config" @ONLY)
  1640. install(FILES "${CURL_BINARY_DIR}/curl-config"
  1641. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1642. PERMISSIONS
  1643. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1644. GROUP_READ GROUP_EXECUTE
  1645. WORLD_READ WORLD_EXECUTE)
  1646. # Finally generate a pkg-config file matching this config
  1647. configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
  1648. "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
  1649. install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
  1650. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1651. # install headers
  1652. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  1653. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  1654. FILES_MATCHING PATTERN "*.h")
  1655. include(CMakePackageConfigHelpers)
  1656. write_basic_package_version_file(
  1657. "${version_config}"
  1658. VERSION ${CURL_VERSION}
  1659. COMPATIBILITY SameMajorVersion
  1660. )
  1661. file(READ "${version_config}" generated_version_config)
  1662. file(WRITE "${version_config}" "
  1663. if(NOT PACKAGE_FIND_VERSION_RANGE AND PACKAGE_FIND_VERSION_MAJOR STREQUAL \"7\")
  1664. # Version 8 satisfies version 7... requirements
  1665. set(PACKAGE_FIND_VERSION_MAJOR 8)
  1666. set(PACKAGE_FIND_VERSION_COUNT 1)
  1667. endif()
  1668. ${generated_version_config}"
  1669. )
  1670. # Use:
  1671. # * TARGETS_EXPORT_NAME
  1672. # * PROJECT_NAME
  1673. configure_package_config_file(CMake/curl-config.cmake.in
  1674. "${project_config}"
  1675. INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1676. PATH_VARS CMAKE_INSTALL_INCLUDEDIR
  1677. )
  1678. if(CURL_ENABLE_EXPORT_TARGET)
  1679. install(EXPORT "${TARGETS_EXPORT_NAME}"
  1680. NAMESPACE "${PROJECT_NAME}::"
  1681. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1682. )
  1683. endif()
  1684. install(FILES ${version_config} ${project_config}
  1685. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1686. )
  1687. # Workaround for MSVS10 to avoid the Dialog Hell
  1688. # FIXME: This could be removed with future version of CMake.
  1689. if(MSVC_VERSION EQUAL 1600)
  1690. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  1691. if(EXISTS "${CURL_SLN_FILENAME}")
  1692. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  1693. endif()
  1694. endif()
  1695. if(NOT TARGET curl_uninstall)
  1696. configure_file(
  1697. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
  1698. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
  1699. IMMEDIATE @ONLY)
  1700. add_custom_target(curl_uninstall
  1701. COMMAND ${CMAKE_COMMAND} -P
  1702. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
  1703. endif()
  1704. endif()