CMakeLists.txt 66 KB

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