CMakeLists.txt 67 KB

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