CMakeLists.txt 72 KB

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