2
0

CMakeLists.txt 69 KB

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