2
0

CMakeLists.txt 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327
  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 in
  27. # the case that both CURL and its dependency are included as sub-projects
  28. # in a larger build using `FetchContent`. To support that case, additional
  29. # variables may be defined by the parent project, ideally in the "extra"
  30. # 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 is skipped. If the variable is
  43. # NOT DEFINED, the symbol detection is performed.
  44. cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
  45. message(STATUS "Using CMake version ${CMAKE_VERSION}")
  46. # Collect command-line arguments for buildinfo.txt.
  47. # Must reside at the top of the script to work as expected.
  48. set(_cmake_args "")
  49. if(NOT "$ENV{CURL_BUILDINFO}$ENV{CURL_CI}$ENV{CI}" STREQUAL "")
  50. get_cmake_property(_cache_vars CACHE_VARIABLES)
  51. foreach(_cache_var IN ITEMS ${_cache_vars})
  52. get_property(_cache_var_helpstring CACHE ${_cache_var} PROPERTY HELPSTRING)
  53. if(_cache_var_helpstring STREQUAL "No help, variable specified on the command line.")
  54. get_property(_cache_var_type CACHE ${_cache_var} PROPERTY TYPE)
  55. get_property(_cache_var_value CACHE ${_cache_var} PROPERTY VALUE)
  56. if(_cache_var_type STREQUAL "UNINITIALIZED")
  57. set(_cache_var_type)
  58. else()
  59. set(_cache_var_type ":${_cache_var_type}")
  60. endif()
  61. set(_cmake_args "${_cmake_args} -D${_cache_var}${_cache_var_type}=\"${_cache_var_value}\"")
  62. endif()
  63. endforeach()
  64. endif()
  65. function(curl_dumpvars) # Dump all defined variables with their values
  66. message("::group::CMake Variable Dump")
  67. get_cmake_property(_vars VARIABLES)
  68. foreach(_var ${_vars})
  69. message("${_var} = ${${_var}}")
  70. endforeach()
  71. message("::endgroup::")
  72. endfunction()
  73. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
  74. include(Utilities)
  75. include(Macros)
  76. include(CMakeDependentOption)
  77. include(CheckCCompilerFlag)
  78. file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/curl/curlver.h" _curl_version_h_contents REGEX "#define LIBCURL_VERSION( |_NUM )")
  79. string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*" _curl_version ${_curl_version_h_contents})
  80. string(REGEX REPLACE "[^\"]+\"" "" _curl_version ${_curl_version})
  81. string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+" _curl_version_num ${_curl_version_h_contents})
  82. string(REGEX REPLACE "[^0]+0x" "" _curl_version_num ${_curl_version_num})
  83. unset(_curl_version_h_contents)
  84. message(STATUS "curl version=[${_curl_version}]")
  85. string(REGEX REPLACE "([0-9]+\.[0-9]+\.[0-9]+).+" "\\1" _curl_version_sem "${_curl_version}")
  86. project(CURL
  87. VERSION "${_curl_version_sem}"
  88. LANGUAGES C)
  89. unset(_target_flags)
  90. if(APPLE)
  91. set(_target_flags "${_target_flags} APPLE")
  92. endif()
  93. if(UNIX)
  94. set(_target_flags "${_target_flags} UNIX")
  95. endif()
  96. if(BSD)
  97. set(_target_flags "${_target_flags} BSD")
  98. endif()
  99. if(WIN32)
  100. set(_target_flags "${_target_flags} WIN32")
  101. endif()
  102. if(CYGWIN)
  103. set(_target_flags "${_target_flags} CYGWIN")
  104. endif()
  105. if(MSYS)
  106. set(_target_flags "${_target_flags} MSYS")
  107. endif()
  108. if(CMAKE_COMPILER_IS_GNUCC)
  109. set(_target_flags "${_target_flags} GCC")
  110. endif()
  111. if(MINGW)
  112. set(_target_flags "${_target_flags} MINGW")
  113. endif()
  114. if(MSVC)
  115. set(_target_flags "${_target_flags} MSVC")
  116. endif()
  117. if(VCPKG_TOOLCHAIN)
  118. set(_target_flags "${_target_flags} VCPKG")
  119. endif()
  120. if(CMAKE_CROSSCOMPILING)
  121. set(_target_flags "${_target_flags} CROSS")
  122. endif()
  123. message(STATUS "CMake platform flags:${_target_flags}")
  124. if(CMAKE_CROSSCOMPILING)
  125. message(STATUS "Cross-compiling: "
  126. "${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR} -> "
  127. "${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}")
  128. endif()
  129. if(CMAKE_C_COMPILER_TARGET)
  130. set(CURL_OS "\"${CMAKE_C_COMPILER_TARGET}\"")
  131. else()
  132. set(CURL_OS "\"${CMAKE_SYSTEM_NAME}\"")
  133. endif()
  134. include_directories("${PROJECT_SOURCE_DIR}/include")
  135. if(NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE)
  136. set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
  137. endif()
  138. # Having CMAKE_TRY_COMPILE_TARGET_TYPE set to STATIC_LIBRARY breaks certain
  139. # 'check_function_exists()' detections (possibly more), by detecting
  140. # non-existing features. This happens by default when using 'ios.toolchain.cmake'.
  141. # Work it around by setting this value to `EXECUTABLE`.
  142. if(CMAKE_TRY_COMPILE_TARGET_TYPE STREQUAL "STATIC_LIBRARY")
  143. message(STATUS "CMAKE_TRY_COMPILE_TARGET_TYPE was found set to STATIC_LIBRARY. "
  144. "Overriding with EXECUTABLE for feature detections to work.")
  145. set(_cmake_try_compile_target_type_save ${CMAKE_TRY_COMPILE_TARGET_TYPE})
  146. set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE")
  147. endif()
  148. option(CURL_WERROR "Turn compiler warnings into errors" OFF)
  149. option(PICKY_COMPILER "Enable picky compiler options" ON)
  150. option(BUILD_CURL_EXE "Build curl executable" ON)
  151. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  152. option(BUILD_STATIC_LIBS "Build static libraries" OFF)
  153. option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
  154. option(ENABLE_ARES "Enable c-ares support" OFF)
  155. option(CURL_DISABLE_INSTALL "Disable installation targets" OFF)
  156. if(WIN32)
  157. option(CURL_STATIC_CRT "Build libcurl with static CRT with MSVC (/MT)" OFF)
  158. if(CURL_STATIC_CRT AND MSVC)
  159. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  160. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  161. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  162. endif()
  163. option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF)
  164. if(ENABLE_UNICODE)
  165. add_definitions("-DUNICODE" "-D_UNICODE")
  166. if(MINGW)
  167. add_compile_options("-municode")
  168. endif()
  169. endif()
  170. list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN") # Apply to all feature checks
  171. set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
  172. if(CURL_TARGET_WINDOWS_VERSION)
  173. add_definitions("-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
  174. list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") # Apply to all feature checks
  175. endif()
  176. # Detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
  177. curl_internal_test(HAVE_WIN32_WINNT)
  178. if(HAVE_WIN32_WINNT)
  179. string(REGEX MATCH ".*_WIN32_WINNT=0x[0-9a-fA-F]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
  180. string(REGEX REPLACE ".*_WIN32_WINNT=" "" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
  181. string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}") # pad to 4 digits
  182. string(TOLOWER "${CURL_TEST_OUTPUT}" HAVE_WIN32_WINNT)
  183. message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
  184. endif()
  185. # Avoid storing HAVE_WIN32_WINNT in CMake cache
  186. unset(HAVE_WIN32_WINNT CACHE)
  187. endif()
  188. option(CURL_LTO "Enable compiler Link Time Optimizations" OFF)
  189. cmake_dependent_option(ENABLE_THREADED_RESOLVER "Enable threaded DNS lookup"
  190. ON "NOT ENABLE_ARES"
  191. OFF)
  192. include(PickyWarnings)
  193. if(CMAKE_SYSTEM_NAME MATCHES "Linux")
  194. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE") # Required for sendmmsg()
  195. endif()
  196. option(ENABLE_DEBUG "Enable curl debug features (for developing curl itself)" OFF)
  197. if(ENABLE_DEBUG)
  198. message(WARNING "This curl build is Debug-enabled, do not use in production.")
  199. endif()
  200. option(ENABLE_CURLDEBUG "Enable TrackMemory debug feature" ${ENABLE_DEBUG})
  201. if(MSVC)
  202. set(ENABLE_CURLDEBUG OFF) # FIXME: TrackMemory + MSVC fails test 558 and 1330. Tested with static build, Debug mode.
  203. endif()
  204. if(ENABLE_DEBUG)
  205. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "DEBUGBUILD")
  206. endif()
  207. if(ENABLE_CURLDEBUG)
  208. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "CURLDEBUG")
  209. endif()
  210. # For debug libs and exes, add "-d" postfix
  211. if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
  212. set(CMAKE_DEBUG_POSTFIX "-d")
  213. endif()
  214. set(LIB_STATIC "libcurl_static")
  215. set(LIB_SHARED "libcurl_shared")
  216. if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
  217. set(BUILD_STATIC_LIBS ON)
  218. endif()
  219. if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS)
  220. set(BUILD_STATIC_CURL ON)
  221. elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS)
  222. set(BUILD_STATIC_CURL OFF)
  223. endif()
  224. # Lib flavour selected for curl tool
  225. if(BUILD_STATIC_CURL)
  226. set(LIB_SELECTED_FOR_EXE ${LIB_STATIC})
  227. else()
  228. set(LIB_SELECTED_FOR_EXE ${LIB_SHARED})
  229. endif()
  230. # Lib flavour selected for example and test programs.
  231. if(BUILD_SHARED_LIBS)
  232. set(LIB_SELECTED ${LIB_SHARED})
  233. else()
  234. set(LIB_SELECTED ${LIB_STATIC})
  235. endif()
  236. # Override to force-disable or force-enable the use of pkg-config.
  237. if(UNIX OR VCPKG_TOOLCHAIN OR (MINGW AND NOT CMAKE_CROSSCOMPILING)) # Keep in sync with CMake/curl-config.cmake.in
  238. set(_curl_use_pkgconfig_default ON)
  239. else()
  240. set(_curl_use_pkgconfig_default OFF)
  241. endif()
  242. option(CURL_USE_PKGCONFIG "Enable pkg-config to detect dependencies" ${_curl_use_pkgconfig_default})
  243. # Initialize variables collecting dependency libs, paths, pkg-config names.
  244. set(CURL_LIBS "")
  245. set(CURL_LIBDIRS "")
  246. set(LIBCURL_PC_REQUIRES_PRIVATE "")
  247. if(ENABLE_ARES)
  248. set(USE_ARES 1)
  249. find_package(Cares REQUIRED)
  250. list(APPEND CURL_LIBS ${CARES_LIBRARIES})
  251. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libcares")
  252. add_definitions("-DCARES_NO_DEPRECATED") # Ignore c-ares deprecation warnings
  253. endif()
  254. include(CurlSymbolHiding)
  255. option(CURL_ENABLE_EXPORT_TARGET "Enable CMake export target" ON)
  256. mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
  257. option(CURL_DISABLE_ALTSVC "Disable alt-svc support" OFF)
  258. mark_as_advanced(CURL_DISABLE_ALTSVC)
  259. option(CURL_DISABLE_SRP "Disable TLS-SRP support" OFF)
  260. mark_as_advanced(CURL_DISABLE_SRP)
  261. option(CURL_DISABLE_COOKIES "Disable cookies support" OFF)
  262. mark_as_advanced(CURL_DISABLE_COOKIES)
  263. option(CURL_DISABLE_BASIC_AUTH "Disable Basic authentication" OFF)
  264. mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
  265. option(CURL_DISABLE_BEARER_AUTH "Disable Bearer authentication" OFF)
  266. mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
  267. option(CURL_DISABLE_DIGEST_AUTH "Disable Digest authentication" OFF)
  268. mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
  269. option(CURL_DISABLE_KERBEROS_AUTH "Disable Kerberos authentication" OFF)
  270. mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
  271. option(CURL_DISABLE_NEGOTIATE_AUTH "Disable negotiate authentication" OFF)
  272. mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
  273. option(CURL_DISABLE_AWS "Disable aws-sigv4" OFF)
  274. mark_as_advanced(CURL_DISABLE_AWS)
  275. option(CURL_DISABLE_DICT "Disable DICT" OFF)
  276. mark_as_advanced(CURL_DISABLE_DICT)
  277. option(CURL_DISABLE_DOH "Disable DNS-over-HTTPS" OFF)
  278. mark_as_advanced(CURL_DISABLE_DOH)
  279. option(CURL_DISABLE_FILE "Disable FILE" OFF)
  280. mark_as_advanced(CURL_DISABLE_FILE)
  281. option(CURL_DISABLE_FTP "Disable FTP" OFF)
  282. mark_as_advanced(CURL_DISABLE_FTP)
  283. option(CURL_DISABLE_GETOPTIONS "Disable curl_easy_options API for existing options to curl_easy_setopt" OFF)
  284. mark_as_advanced(CURL_DISABLE_GETOPTIONS)
  285. option(CURL_DISABLE_GOPHER "Disable Gopher" OFF)
  286. mark_as_advanced(CURL_DISABLE_GOPHER)
  287. option(CURL_DISABLE_HEADERS_API "Disable headers-api support" OFF)
  288. mark_as_advanced(CURL_DISABLE_HEADERS_API)
  289. option(CURL_DISABLE_HSTS "Disable HSTS support" OFF)
  290. mark_as_advanced(CURL_DISABLE_HSTS)
  291. option(CURL_DISABLE_HTTP "Disable HTTP" OFF)
  292. mark_as_advanced(CURL_DISABLE_HTTP)
  293. option(CURL_DISABLE_HTTP_AUTH "Disable all HTTP authentication methods" OFF)
  294. mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
  295. option(CURL_DISABLE_IMAP "Disable IMAP" OFF)
  296. mark_as_advanced(CURL_DISABLE_IMAP)
  297. option(CURL_DISABLE_LDAP "Disable LDAP" OFF)
  298. mark_as_advanced(CURL_DISABLE_LDAP)
  299. option(CURL_DISABLE_LDAPS "Disable LDAPS" ${CURL_DISABLE_LDAP})
  300. mark_as_advanced(CURL_DISABLE_LDAPS)
  301. option(CURL_DISABLE_LIBCURL_OPTION "Disable --libcurl option from the curl tool" OFF)
  302. mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
  303. option(CURL_DISABLE_MIME "Disable MIME support" OFF)
  304. mark_as_advanced(CURL_DISABLE_MIME)
  305. cmake_dependent_option(CURL_DISABLE_FORM_API "Disable form-api"
  306. OFF "NOT CURL_DISABLE_MIME"
  307. ON)
  308. mark_as_advanced(CURL_DISABLE_FORM_API)
  309. option(CURL_DISABLE_MQTT "Disable MQTT" OFF)
  310. mark_as_advanced(CURL_DISABLE_MQTT)
  311. option(CURL_DISABLE_BINDLOCAL "Disable local binding support" OFF)
  312. mark_as_advanced(CURL_DISABLE_BINDLOCAL)
  313. option(CURL_DISABLE_NETRC "Disable netrc parser" OFF)
  314. mark_as_advanced(CURL_DISABLE_NETRC)
  315. option(CURL_DISABLE_NTLM "Disable NTLM support" OFF)
  316. mark_as_advanced(CURL_DISABLE_NTLM)
  317. option(CURL_DISABLE_PARSEDATE "Disable date parsing" OFF)
  318. mark_as_advanced(CURL_DISABLE_PARSEDATE)
  319. option(CURL_DISABLE_POP3 "Disable POP3" OFF)
  320. mark_as_advanced(CURL_DISABLE_POP3)
  321. option(CURL_DISABLE_PROGRESS_METER "Disable built-in progress meter" OFF)
  322. mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
  323. option(CURL_DISABLE_PROXY "Disable proxy support" OFF)
  324. mark_as_advanced(CURL_DISABLE_PROXY)
  325. option(CURL_DISABLE_IPFS "Disable IPFS" OFF)
  326. mark_as_advanced(CURL_DISABLE_IPFS)
  327. option(CURL_DISABLE_RTSP "Disable RTSP" OFF)
  328. mark_as_advanced(CURL_DISABLE_SHA512_256)
  329. option(CURL_DISABLE_SHA512_256 "Disable SHA-512/256 hash algorithm" OFF)
  330. mark_as_advanced(CURL_DISABLE_RTSP)
  331. option(CURL_DISABLE_SHUFFLE_DNS "Disable shuffle DNS feature" OFF)
  332. mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
  333. option(CURL_DISABLE_SMB "Disable SMB" OFF)
  334. mark_as_advanced(CURL_DISABLE_SMB)
  335. option(CURL_DISABLE_SMTP "Disable SMTP" OFF)
  336. mark_as_advanced(CURL_DISABLE_SMTP)
  337. option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll" OFF)
  338. mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
  339. option(CURL_DISABLE_WEBSOCKETS "Disable WebSocket" OFF)
  340. mark_as_advanced(CURL_DISABLE_WEBSOCKETS)
  341. option(CURL_DISABLE_TELNET "Disable Telnet" OFF)
  342. mark_as_advanced(CURL_DISABLE_TELNET)
  343. option(CURL_DISABLE_TFTP "Disable TFTP" OFF)
  344. mark_as_advanced(CURL_DISABLE_TFTP)
  345. option(CURL_DISABLE_VERBOSE_STRINGS "Disable verbose strings" OFF)
  346. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  347. if(CURL_DISABLE_HTTP)
  348. set(CURL_DISABLE_IPFS ON)
  349. set(CURL_DISABLE_RTSP ON)
  350. set(CURL_DISABLE_ALTSVC ON)
  351. set(CURL_DISABLE_HSTS ON)
  352. endif()
  353. # Corresponds to HTTP_ONLY in lib/curl_setup.h
  354. option(HTTP_ONLY "Disable all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  355. mark_as_advanced(HTTP_ONLY)
  356. if(HTTP_ONLY)
  357. set(CURL_DISABLE_DICT ON)
  358. set(CURL_DISABLE_FILE ON)
  359. set(CURL_DISABLE_FTP ON)
  360. set(CURL_DISABLE_GOPHER ON)
  361. set(CURL_DISABLE_IMAP ON)
  362. set(CURL_DISABLE_LDAP ON)
  363. set(CURL_DISABLE_LDAPS ON)
  364. set(CURL_DISABLE_MQTT ON)
  365. set(CURL_DISABLE_POP3 ON)
  366. set(CURL_DISABLE_IPFS ON)
  367. set(CURL_DISABLE_RTSP ON)
  368. set(CURL_DISABLE_SMB ON)
  369. set(CURL_DISABLE_SMTP ON)
  370. set(CURL_DISABLE_TELNET ON)
  371. set(CURL_DISABLE_TFTP ON)
  372. endif()
  373. if(WINDOWS_STORE)
  374. set(CURL_DISABLE_TELNET ON) # telnet code needs fixing to compile for UWP.
  375. endif()
  376. option(ENABLE_IPV6 "Enable IPv6 support" ON)
  377. mark_as_advanced(ENABLE_IPV6)
  378. if(ENABLE_IPV6 AND NOT WIN32)
  379. include(CheckStructHasMember)
  380. check_struct_has_member("struct sockaddr_in6" "sin6_addr" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_ADDR)
  381. check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
  382. if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
  383. message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
  384. # Force the feature off as this name is used as guard macro...
  385. set(ENABLE_IPV6 OFF CACHE BOOL "Enable IPv6 support" FORCE)
  386. endif()
  387. if(APPLE AND NOT ENABLE_ARES)
  388. set(_use_core_foundation_and_core_services ON)
  389. find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
  390. mark_as_advanced(SYSTEMCONFIGURATION_FRAMEWORK)
  391. if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
  392. message(FATAL_ERROR "SystemConfiguration framework not found")
  393. endif()
  394. list(APPEND CURL_LIBS "-framework SystemConfiguration")
  395. endif()
  396. endif()
  397. if(ENABLE_IPV6)
  398. set(USE_IPV6 ON)
  399. endif()
  400. find_package(Perl)
  401. option(BUILD_LIBCURL_DOCS "Build libcurl man pages" ON)
  402. option(BUILD_MISC_DOCS "Build misc man pages (e.g. curl-config and mk-ca-bundle)" ON)
  403. option(ENABLE_CURL_MANUAL "Build the man page for curl and enable its -M/--manual option" ON)
  404. if(ENABLE_CURL_MANUAL OR BUILD_LIBCURL_DOCS)
  405. if(PERL_FOUND)
  406. set(HAVE_MANUAL_TOOLS ON)
  407. endif()
  408. if(NOT HAVE_MANUAL_TOOLS)
  409. message(WARNING "Perl not found. Will not build manuals.")
  410. endif()
  411. endif()
  412. # Disable warnings on Borland to avoid changing 3rd party code.
  413. if(BORLAND)
  414. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  415. endif()
  416. # If we are on AIX, do the _ALL_SOURCE magic
  417. if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
  418. add_definitions("-D_ALL_SOURCE")
  419. endif()
  420. # If we are on Haiku, make sure that the network library is brought in.
  421. if(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
  422. list(APPEND CURL_LIBS "network")
  423. endif()
  424. # Include all the necessary files for macros
  425. include(CMakePushCheckState)
  426. include(CheckFunctionExists)
  427. include(CheckIncludeFile)
  428. include(CheckIncludeFiles)
  429. include(CheckLibraryExists)
  430. include(CheckSymbolExists)
  431. include(CheckTypeSize)
  432. include(CheckCSourceCompiles)
  433. # Preload settings on Windows
  434. if(WIN32)
  435. include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake")
  436. elseif(APPLE)
  437. # Fast-track predictable feature detections
  438. set(HAVE_EVENTFD 0)
  439. set(HAVE_GETPASS_R 0)
  440. set(HAVE_SENDMMSG 0)
  441. endif()
  442. if(ENABLE_THREADED_RESOLVER)
  443. if(WIN32)
  444. set(USE_THREADS_WIN32 ON)
  445. else()
  446. find_package(Threads REQUIRED)
  447. set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
  448. set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
  449. list(APPEND CURL_LIBS ${CMAKE_THREAD_LIBS_INIT})
  450. endif()
  451. endif()
  452. # Check for all needed libraries
  453. if(NOT WIN32 AND NOT APPLE)
  454. check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
  455. if(HAVE_LIBSOCKET)
  456. set(CURL_LIBS "socket;${CURL_LIBS}")
  457. endif()
  458. endif()
  459. check_function_exists("gethostname" HAVE_GETHOSTNAME)
  460. if(WIN32)
  461. list(APPEND CURL_LIBS "ws2_32" "bcrypt")
  462. endif()
  463. # Check SSL libraries
  464. option(CURL_ENABLE_SSL "Enable SSL support" ON)
  465. if(CURL_DEFAULT_SSL_BACKEND)
  466. set(_valid_default_ssl_backend FALSE)
  467. endif()
  468. if(APPLE)
  469. cmake_dependent_option(CURL_USE_SECTRANSP "Enable Apple OS native SSL/TLS (Secure Transport)" OFF CURL_ENABLE_SSL OFF)
  470. endif()
  471. if(WIN32)
  472. cmake_dependent_option(CURL_USE_SCHANNEL "Enable Windows native SSL/TLS (Schannel)" OFF CURL_ENABLE_SSL OFF)
  473. option(CURL_WINDOWS_SSPI "Enable SSPI on Windows" ${CURL_USE_SCHANNEL})
  474. endif()
  475. cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  476. cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  477. cmake_dependent_option(CURL_USE_WOLFSSL "Enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  478. cmake_dependent_option(CURL_USE_GNUTLS "Enable GnuTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  479. cmake_dependent_option(CURL_USE_RUSTLS "Enable Rustls for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  480. if(WIN32 OR
  481. CURL_USE_SECTRANSP OR
  482. CURL_USE_SCHANNEL OR
  483. CURL_USE_MBEDTLS OR
  484. CURL_USE_BEARSSL OR
  485. CURL_USE_WOLFSSL OR
  486. CURL_USE_GNUTLS OR
  487. CURL_USE_RUSTLS)
  488. set(_openssl_default OFF)
  489. else()
  490. set(_openssl_default ON)
  491. endif()
  492. cmake_dependent_option(CURL_USE_OPENSSL "Enable OpenSSL for SSL/TLS" ${_openssl_default} CURL_ENABLE_SSL OFF)
  493. option(USE_OPENSSL_QUIC "Use OpenSSL and nghttp3 libraries for HTTP/3 support" OFF)
  494. if(USE_OPENSSL_QUIC AND NOT CURL_USE_OPENSSL)
  495. message(WARNING "OpenSSL QUIC has been requested, but without enabling OpenSSL. Will not enable QUIC.")
  496. set(USE_OPENSSL_QUIC OFF)
  497. endif()
  498. option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF)
  499. count_true(_enabled_ssl_options_count
  500. CURL_USE_SCHANNEL
  501. CURL_USE_SECTRANSP
  502. CURL_USE_OPENSSL
  503. CURL_USE_MBEDTLS
  504. CURL_USE_BEARSSL
  505. CURL_USE_WOLFSSL
  506. CURL_USE_GNUTLS
  507. CURL_USE_RUSTLS
  508. )
  509. if(_enabled_ssl_options_count GREATER 1)
  510. set(CURL_WITH_MULTI_SSL ON)
  511. elseif(_enabled_ssl_options_count EQUAL 0)
  512. set(CURL_DISABLE_HSTS ON)
  513. endif()
  514. if(CURL_USE_SCHANNEL)
  515. set(_ssl_enabled ON)
  516. set(USE_SCHANNEL ON) # Windows native SSL/TLS support
  517. set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI
  518. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "schannel")
  519. set(_valid_default_ssl_backend TRUE)
  520. endif()
  521. endif()
  522. if(CURL_WINDOWS_SSPI)
  523. set(USE_WINDOWS_SSPI ON)
  524. endif()
  525. if(CURL_USE_SECTRANSP)
  526. set(_use_core_foundation_and_core_services ON)
  527. find_library(SECURITY_FRAMEWORK "Security")
  528. mark_as_advanced(SECURITY_FRAMEWORK)
  529. if(NOT SECURITY_FRAMEWORK)
  530. message(FATAL_ERROR "Security framework not found")
  531. endif()
  532. set(_ssl_enabled ON)
  533. set(USE_SECTRANSP ON)
  534. list(APPEND CURL_LIBS "-framework Security")
  535. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport")
  536. set(_valid_default_ssl_backend TRUE)
  537. endif()
  538. message(WARNING "Secure Transport does not support TLS 1.3.")
  539. endif()
  540. if(_use_core_foundation_and_core_services)
  541. find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
  542. mark_as_advanced(COREFOUNDATION_FRAMEWORK)
  543. find_library(CORESERVICES_FRAMEWORK "CoreServices")
  544. mark_as_advanced(CORESERVICES_FRAMEWORK)
  545. if(NOT COREFOUNDATION_FRAMEWORK)
  546. message(FATAL_ERROR "CoreFoundation framework not found")
  547. endif()
  548. if(NOT CORESERVICES_FRAMEWORK)
  549. message(FATAL_ERROR "CoreServices framework not found")
  550. endif()
  551. list(APPEND CURL_LIBS "-framework CoreFoundation" "-framework CoreServices")
  552. endif()
  553. if(CURL_USE_OPENSSL)
  554. find_package(OpenSSL REQUIRED)
  555. set(_ssl_enabled ON)
  556. set(USE_OPENSSL ON)
  557. # Depend on OpenSSL via imported targets. This allows our dependents to
  558. # get our dependencies transitively.
  559. list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
  560. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "openssl")
  561. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl")
  562. set(_valid_default_ssl_backend TRUE)
  563. endif()
  564. set(_curl_ca_bundle_supported TRUE)
  565. cmake_push_check_state()
  566. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  567. if(NOT DEFINED HAVE_BORINGSSL)
  568. check_symbol_exists("OPENSSL_IS_BORINGSSL" "openssl/base.h" HAVE_BORINGSSL)
  569. endif()
  570. if(NOT DEFINED HAVE_AWSLC)
  571. check_symbol_exists("OPENSSL_IS_AWSLC" "openssl/base.h" HAVE_AWSLC)
  572. endif()
  573. cmake_pop_check_state()
  574. endif()
  575. if(CURL_USE_MBEDTLS)
  576. find_package(MbedTLS REQUIRED)
  577. set(_ssl_enabled ON)
  578. set(USE_MBEDTLS ON)
  579. list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
  580. list(APPEND CURL_LIBDIRS ${MBEDTLS_LIBRARY_DIRS})
  581. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${MBEDTLS_PC_REQUIRES})
  582. include_directories(SYSTEM ${MBEDTLS_INCLUDE_DIRS})
  583. link_directories(${MBEDTLS_LIBRARY_DIRS})
  584. if(MBEDTLS_CFLAGS)
  585. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MBEDTLS_CFLAGS}")
  586. endif()
  587. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "mbedtls")
  588. set(_valid_default_ssl_backend TRUE)
  589. endif()
  590. set(_curl_ca_bundle_supported TRUE)
  591. endif()
  592. if(CURL_USE_BEARSSL)
  593. find_package(BearSSL REQUIRED)
  594. set(_ssl_enabled ON)
  595. set(USE_BEARSSL ON)
  596. list(APPEND CURL_LIBS ${BEARSSL_LIBRARIES})
  597. include_directories(SYSTEM ${BEARSSL_INCLUDE_DIRS})
  598. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "bearssl")
  599. set(_valid_default_ssl_backend TRUE)
  600. endif()
  601. set(_curl_ca_bundle_supported TRUE)
  602. message(WARNING "BearSSL does not support TLS 1.3.")
  603. endif()
  604. if(CURL_USE_WOLFSSL)
  605. find_package(WolfSSL REQUIRED)
  606. set(_ssl_enabled ON)
  607. set(USE_WOLFSSL ON)
  608. list(APPEND CURL_LIBS ${WOLFSSL_LIBRARIES})
  609. list(APPEND CURL_LIBDIRS ${WOLFSSL_LIBRARY_DIRS})
  610. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "wolfssl")
  611. include_directories(SYSTEM ${WOLFSSL_INCLUDE_DIRS})
  612. link_directories(${WOLFSSL_LIBRARY_DIRS})
  613. if(WOLFSSL_CFLAGS)
  614. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WOLFSSL_CFLAGS}")
  615. endif()
  616. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "wolfssl")
  617. set(_valid_default_ssl_backend TRUE)
  618. endif()
  619. set(_curl_ca_bundle_supported TRUE)
  620. endif()
  621. if(CURL_USE_GNUTLS)
  622. if(CURL_USE_PKGCONFIG)
  623. find_package(PkgConfig QUIET)
  624. pkg_check_modules(GNUTLS "gnutls")
  625. if(GNUTLS_FOUND)
  626. set(GNUTLS_LIBRARIES ${GNUTLS_LINK_LIBRARIES})
  627. endif()
  628. endif()
  629. if(NOT GNUTLS_FOUND)
  630. find_package(GnuTLS REQUIRED)
  631. endif()
  632. find_package(Nettle REQUIRED)
  633. set(_ssl_enabled ON)
  634. set(USE_GNUTLS ON)
  635. list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES} ${NETTLE_LIBRARIES})
  636. list(APPEND CURL_LIBDIRS ${NETTLE_LIBRARY_DIRS})
  637. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "gnutls" "nettle")
  638. include_directories(SYSTEM ${GNUTLS_INCLUDE_DIRS} ${NETTLE_INCLUDE_DIRS})
  639. link_directories(${NETTLE_LIBRARY_DIRS})
  640. if(NETTLE_CFLAGS)
  641. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NETTLE_CFLAGS}")
  642. endif()
  643. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls")
  644. set(_valid_default_ssl_backend TRUE)
  645. endif()
  646. set(_curl_ca_bundle_supported TRUE)
  647. if(NOT DEFINED HAVE_GNUTLS_SRP AND NOT CURL_DISABLE_SRP)
  648. cmake_push_check_state()
  649. set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
  650. set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
  651. check_symbol_exists("gnutls_srp_verifier" "gnutls/gnutls.h" HAVE_GNUTLS_SRP)
  652. cmake_pop_check_state()
  653. endif()
  654. endif()
  655. if(CURL_USE_RUSTLS)
  656. find_package(Rustls REQUIRED)
  657. set(_ssl_enabled ON)
  658. set(USE_RUSTLS ON)
  659. list(APPEND CURL_LIBS ${RUSTLS_LIBRARIES})
  660. list(APPEND CURL_LIBDIRS ${RUSTLS_LIBRARY_DIRS})
  661. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${RUSTLS_PC_REQUIRES})
  662. include_directories(SYSTEM ${RUSTLS_INCLUDE_DIRS})
  663. link_directories(${RUSTLS_LIBRARY_DIRS})
  664. if(RUSTLS_CFLAGS)
  665. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${RUSTLS_CFLAGS}")
  666. endif()
  667. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "rustls")
  668. set(_valid_default_ssl_backend TRUE)
  669. endif()
  670. set(_curl_ca_bundle_supported TRUE)
  671. endif()
  672. if(CURL_DEFAULT_SSL_BACKEND AND NOT _valid_default_ssl_backend)
  673. message(FATAL_ERROR "CURL_DEFAULT_SSL_BACKEND '${CURL_DEFAULT_SSL_BACKEND}' not enabled.")
  674. endif()
  675. # Keep ZLIB detection after TLS detection,
  676. # and before calling openssl_check_symbol_exists().
  677. set(HAVE_LIBZ OFF)
  678. curl_dependency_option(ZLIB)
  679. if(ZLIB_FOUND)
  680. set(HAVE_LIBZ ON)
  681. # Depend on ZLIB via imported targets. This allows our dependents to
  682. # get our dependencies transitively.
  683. list(APPEND CURL_LIBS ZLIB::ZLIB)
  684. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "zlib")
  685. endif()
  686. option(CURL_BROTLI "Use brotli" OFF)
  687. set(HAVE_BROTLI OFF)
  688. if(CURL_BROTLI)
  689. find_package(Brotli REQUIRED)
  690. if(BROTLI_FOUND)
  691. set(HAVE_BROTLI ON)
  692. list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
  693. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libbrotlidec")
  694. include_directories(SYSTEM ${BROTLI_INCLUDE_DIRS})
  695. endif()
  696. endif()
  697. option(CURL_ZSTD "Use zstd" OFF)
  698. set(HAVE_ZSTD OFF)
  699. if(CURL_ZSTD)
  700. find_package(Zstd REQUIRED)
  701. if(ZSTD_FOUND AND NOT ZSTD_VERSION VERSION_LESS 1.0.0)
  702. set(HAVE_ZSTD ON)
  703. list(APPEND CURL_LIBS ${ZSTD_LIBRARIES})
  704. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libzstd")
  705. include_directories(SYSTEM ${ZSTD_INCLUDE_DIRS})
  706. else()
  707. message(WARNING "zstd v1.0.0 or newer is required, disabling zstd support.")
  708. endif()
  709. endif()
  710. # Check symbol in an OpenSSL-like TLS backend, or in _extra_libs depending on it.
  711. macro(openssl_check_symbol_exists _symbol _files _variable _extra_libs)
  712. cmake_push_check_state()
  713. if(USE_OPENSSL)
  714. set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
  715. set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
  716. if(HAVE_LIBZ)
  717. list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
  718. endif()
  719. if(WIN32)
  720. list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
  721. list(APPEND CMAKE_REQUIRED_LIBRARIES "bcrypt") # for OpenSSL/LibreSSL
  722. endif()
  723. elseif(USE_WOLFSSL)
  724. set(CMAKE_REQUIRED_INCLUDES "${WOLFSSL_INCLUDE_DIRS}")
  725. set(CMAKE_REQUIRED_LIBRARIES "${WOLFSSL_LIBRARIES}")
  726. curl_required_libpaths("${WOLFSSL_LIBRARY_DIRS}")
  727. if(HAVE_LIBZ)
  728. list(APPEND CMAKE_REQUIRED_INCLUDES "${ZLIB_INCLUDE_DIRS}") # Public wolfSSL headers require zlib headers
  729. list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
  730. endif()
  731. if(WIN32)
  732. list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32" "crypt32")
  733. endif()
  734. list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_UINTPTR_T") # to pull in stdint.h (as of wolfSSL v5.5.4)
  735. endif()
  736. list(APPEND CMAKE_REQUIRED_LIBRARIES "${_extra_libs}")
  737. check_symbol_exists("${_symbol}" "${_files}" "${_variable}")
  738. cmake_pop_check_state()
  739. endmacro()
  740. # Ensure that the OpenSSL fork actually supports QUIC.
  741. macro(openssl_check_quic)
  742. if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD)
  743. if(USE_OPENSSL)
  744. openssl_check_symbol_exists("SSL_CTX_set_quic_method" "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD "")
  745. elseif(USE_WOLFSSL)
  746. openssl_check_symbol_exists("wolfSSL_set_quic_method" "wolfssl/options.h;wolfssl/openssl/ssl.h"
  747. HAVE_SSL_CTX_SET_QUIC_METHOD "")
  748. endif()
  749. endif()
  750. if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD)
  751. message(FATAL_ERROR "QUIC support is missing in OpenSSL fork. Try setting -DOPENSSL_ROOT_DIR")
  752. endif()
  753. endmacro()
  754. if(USE_WOLFSSL)
  755. openssl_check_symbol_exists("wolfSSL_DES_ecb_encrypt" "wolfssl/openssl/des.h" HAVE_WOLFSSL_DES_ECB_ENCRYPT "")
  756. openssl_check_symbol_exists("wolfSSL_BIO_new" "wolfssl/ssl.h" HAVE_WOLFSSL_BIO "")
  757. openssl_check_symbol_exists("wolfSSL_BIO_set_shutdown" "wolfssl/ssl.h" HAVE_WOLFSSL_FULL_BIO "")
  758. endif()
  759. if(USE_OPENSSL OR USE_WOLFSSL)
  760. if(NOT DEFINED HAVE_SSL_SET0_WBIO)
  761. openssl_check_symbol_exists("SSL_set0_wbio" "openssl/ssl.h" HAVE_SSL_SET0_WBIO "")
  762. endif()
  763. if(NOT DEFINED HAVE_OPENSSL_SRP AND NOT CURL_DISABLE_SRP)
  764. openssl_check_symbol_exists("SSL_CTX_set_srp_username" "openssl/ssl.h" HAVE_OPENSSL_SRP "")
  765. endif()
  766. endif()
  767. option(USE_HTTPSRR "Enable HTTPS RR support for ECH (experimental)" OFF)
  768. option(USE_ECH "Enable ECH support" OFF)
  769. if(USE_ECH)
  770. if(USE_OPENSSL OR USE_WOLFSSL)
  771. # Be sure that the TLS library actually supports ECH.
  772. if(NOT DEFINED HAVE_ECH)
  773. if(USE_OPENSSL AND (HAVE_BORINGSSL OR HAVE_AWSLC))
  774. openssl_check_symbol_exists("SSL_set1_ech_config_list" "openssl/ssl.h" HAVE_ECH "")
  775. elseif(USE_OPENSSL)
  776. openssl_check_symbol_exists("SSL_ech_set1_echconfig" "openssl/ech.h" HAVE_ECH "")
  777. elseif(USE_WOLFSSL)
  778. openssl_check_symbol_exists("wolfSSL_CTX_GenerateEchConfig" "wolfssl/options.h;wolfssl/ssl.h" HAVE_ECH "")
  779. endif()
  780. endif()
  781. if(NOT HAVE_ECH)
  782. message(FATAL_ERROR "ECH support missing in OpenSSL/BoringSSL/AWS-LC/wolfSSL")
  783. else()
  784. message(STATUS "ECH enabled.")
  785. endif()
  786. else()
  787. message(FATAL_ERROR "ECH requires ECH-enablded OpenSSL, BoringSSL, AWS-LC or wolfSSL")
  788. endif()
  789. endif()
  790. option(USE_NGHTTP2 "Use nghttp2 library" ON)
  791. if(USE_NGHTTP2)
  792. find_package(NGHTTP2)
  793. if(NGHTTP2_FOUND)
  794. include_directories(SYSTEM ${NGHTTP2_INCLUDE_DIRS})
  795. list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
  796. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp2")
  797. else()
  798. set(USE_NGHTTP2 OFF)
  799. endif()
  800. endif()
  801. option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF)
  802. if(USE_NGTCP2)
  803. if(USE_OPENSSL OR USE_WOLFSSL)
  804. if(USE_WOLFSSL)
  805. find_package(NGTCP2 REQUIRED "wolfSSL")
  806. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_wolfssl")
  807. elseif(HAVE_BORINGSSL OR HAVE_AWSLC)
  808. find_package(NGTCP2 REQUIRED "BoringSSL")
  809. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_boringssl")
  810. else()
  811. find_package(NGTCP2 REQUIRED "quictls")
  812. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_quictls")
  813. endif()
  814. openssl_check_quic()
  815. elseif(USE_GNUTLS)
  816. find_package(NGTCP2 REQUIRED "GnuTLS")
  817. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2_crypto_gnutls")
  818. else()
  819. message(FATAL_ERROR "ngtcp2 requires OpenSSL, wolfSSL or GnuTLS")
  820. endif()
  821. include_directories(SYSTEM ${NGTCP2_INCLUDE_DIRS})
  822. list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES})
  823. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libngtcp2")
  824. find_package(NGHTTP3 REQUIRED)
  825. set(USE_NGHTTP3 ON)
  826. include_directories(SYSTEM ${NGHTTP3_INCLUDE_DIRS})
  827. list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
  828. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp3")
  829. endif()
  830. option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF)
  831. if(USE_QUICHE)
  832. if(USE_NGTCP2)
  833. message(FATAL_ERROR "Only one HTTP/3 backend can be selected")
  834. endif()
  835. find_package(Quiche REQUIRED)
  836. if(NOT HAVE_BORINGSSL)
  837. message(FATAL_ERROR "quiche requires BoringSSL")
  838. endif()
  839. openssl_check_quic()
  840. list(APPEND CURL_LIBS ${QUICHE_LIBRARIES})
  841. list(APPEND CURL_LIBDIRS ${QUICHE_LIBRARY_DIRS})
  842. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "quiche")
  843. include_directories(SYSTEM ${QUICHE_INCLUDE_DIRS})
  844. link_directories(${QUICHE_LIBRARY_DIRS})
  845. if(QUICHE_CFLAGS)
  846. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${QUICHE_CFLAGS}")
  847. endif()
  848. if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD)
  849. cmake_push_check_state()
  850. set(CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}")
  851. set(CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}")
  852. check_symbol_exists("quiche_conn_set_qlog_fd" "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD)
  853. cmake_pop_check_state()
  854. endif()
  855. endif()
  856. option(USE_MSH3 "Use msh3/msquic library for HTTP/3 support" OFF)
  857. if(USE_MSH3)
  858. if(USE_NGTCP2 OR USE_QUICHE)
  859. message(FATAL_ERROR "Only one HTTP/3 backend can be selected")
  860. endif()
  861. if(NOT WIN32)
  862. if(NOT USE_OPENSSL)
  863. message(FATAL_ERROR "msh3/msquic requires OpenSSL fork with QUIC API")
  864. endif()
  865. openssl_check_quic()
  866. endif()
  867. find_package(MSH3 REQUIRED)
  868. list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
  869. list(APPEND CURL_LIBDIRS ${MSH3_LIBRARY_DIRS})
  870. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${MSH3_PC_REQUIRES})
  871. include_directories(SYSTEM ${MSH3_INCLUDE_DIRS})
  872. link_directories(${MSH3_LIBRARY_DIRS})
  873. if(MSH3_CFLAGS)
  874. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSH3_CFLAGS}")
  875. endif()
  876. endif()
  877. if(USE_OPENSSL_QUIC)
  878. if(USE_NGTCP2 OR USE_QUICHE OR USE_MSH3)
  879. message(FATAL_ERROR "Only one HTTP/3 backend can be selected")
  880. endif()
  881. find_package(OpenSSL 3.3.0 REQUIRED)
  882. find_package(NGHTTP3 REQUIRED)
  883. set(USE_NGHTTP3 ON)
  884. include_directories(SYSTEM ${NGHTTP3_INCLUDE_DIRS})
  885. list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
  886. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp3")
  887. endif()
  888. if(CURL_WITH_MULTI_SSL AND (USE_NGTCP2 OR USE_QUICHE OR USE_MSH3 OR USE_OPENSSL_QUIC))
  889. message(FATAL_ERROR "MultiSSL cannot be enabled with HTTP/3 and vice versa.")
  890. endif()
  891. if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP))
  892. set(USE_TLS_SRP 1)
  893. endif()
  894. if(NOT CURL_DISABLE_LDAP)
  895. if(WIN32 AND NOT WINDOWS_STORE)
  896. option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
  897. if(USE_WIN32_LDAP)
  898. list(APPEND CURL_LIBS "wldap32")
  899. if(NOT CURL_DISABLE_LDAPS)
  900. set(HAVE_LDAP_SSL ON)
  901. endif()
  902. endif()
  903. endif()
  904. # Now that we know, we are not using Windows LDAP...
  905. if(NOT USE_WIN32_LDAP)
  906. if(NOT DEFINED LDAP_LIBRARY)
  907. set(LDAP_LIBRARY "ldap" CACHE STRING "Name or full path to ldap library")
  908. endif()
  909. if(NOT DEFINED LDAP_LBER_LIBRARY)
  910. set(LDAP_LBER_LIBRARY "lber" CACHE STRING "Name or full path to lber library")
  911. endif()
  912. if(NOT DEFINED LDAP_INCLUDE_DIR)
  913. set(LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  914. endif()
  915. # Check for LDAP
  916. cmake_push_check_state()
  917. if(USE_OPENSSL)
  918. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  919. endif()
  920. check_library_exists("${LDAP_LIBRARY}" "ldap_init" "" HAVE_LIBLDAP)
  921. if(HAVE_LIBLDAP)
  922. check_library_exists("${LDAP_LIBRARY};${LDAP_LBER_LIBRARY}" "ber_init" "" HAVE_LIBLBER)
  923. else()
  924. check_library_exists("${LDAP_LBER_LIBRARY}" "ber_init" "" HAVE_LIBLBER)
  925. endif()
  926. if(LDAP_INCLUDE_DIR)
  927. list(APPEND CMAKE_REQUIRED_INCLUDES ${LDAP_INCLUDE_DIR})
  928. endif()
  929. unset(_include_list)
  930. check_include_file("lber.h" HAVE_LBER_H)
  931. if(HAVE_LBER_H)
  932. list(APPEND _include_list "lber.h")
  933. endif()
  934. check_include_files("${_include_list};ldap.h" HAVE_LDAP_H)
  935. unset(_include_list)
  936. if(NOT HAVE_LDAP_H)
  937. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  938. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  939. elseif(NOT HAVE_LIBLDAP)
  940. message(STATUS "LDAP library '${LDAP_LIBRARY}' not found CURL_DISABLE_LDAP set ON")
  941. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  942. else()
  943. if(LDAP_INCLUDE_DIR)
  944. include_directories(SYSTEM ${LDAP_INCLUDE_DIR})
  945. endif()
  946. list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1")
  947. list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LIBRARY})
  948. set(CURL_LIBS "${LDAP_LIBRARY};${CURL_LIBS}")
  949. # FIXME: uncomment once pkg-config-based detection landed: https://github.com/curl/curl/pull/15273
  950. # set(LIBCURL_PC_REQUIRES_PRIVATE "${LDAP_PC_REQUIRES};${LIBCURL_PC_REQUIRES_PRIVATE}")
  951. if(HAVE_LIBLBER)
  952. list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LBER_LIBRARY})
  953. set(CURL_LIBS "${LDAP_LBER_LIBRARY};${CURL_LIBS}")
  954. endif()
  955. check_function_exists("ldap_url_parse" HAVE_LDAP_URL_PARSE)
  956. check_function_exists("ldap_init_fd" HAVE_LDAP_INIT_FD)
  957. check_include_file("ldap_ssl.h" HAVE_LDAP_SSL_H)
  958. if(HAVE_LDAP_INIT_FD)
  959. set(USE_OPENLDAP ON)
  960. add_definitions("-DLDAP_DEPRECATED=1")
  961. endif()
  962. if(NOT CURL_DISABLE_LDAPS)
  963. set(HAVE_LDAP_SSL ON)
  964. endif()
  965. endif()
  966. cmake_pop_check_state()
  967. endif()
  968. endif()
  969. # No ldap, no ldaps.
  970. if(CURL_DISABLE_LDAP)
  971. if(NOT CURL_DISABLE_LDAPS)
  972. message(STATUS "LDAP needs to be enabled to support LDAPS")
  973. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  974. endif()
  975. endif()
  976. if(WIN32)
  977. option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF)
  978. if(USE_WIN32_IDN)
  979. list(APPEND CURL_LIBS "normaliz")
  980. endif()
  981. else()
  982. set(USE_WIN32_IDN OFF)
  983. endif()
  984. if(APPLE)
  985. option(USE_APPLE_IDN "Use Apple built-in IDN support" OFF)
  986. if(USE_APPLE_IDN)
  987. cmake_push_check_state()
  988. set(CMAKE_REQUIRED_LIBRARIES "icucore")
  989. check_symbol_exists("uidna_openUTS46" "unicode/uidna.h" HAVE_APPLE_IDN)
  990. cmake_pop_check_state()
  991. if(HAVE_APPLE_IDN)
  992. list(APPEND CURL_LIBS "icucore" "iconv")
  993. else()
  994. set(USE_APPLE_IDN OFF)
  995. endif()
  996. endif()
  997. else()
  998. set(USE_APPLE_IDN OFF)
  999. endif()
  1000. # Check for libidn2
  1001. option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
  1002. set(HAVE_IDN2_H OFF)
  1003. set(HAVE_LIBIDN2 OFF)
  1004. if(USE_LIBIDN2 AND NOT USE_APPLE_IDN AND NOT USE_WIN32_IDN)
  1005. find_package(Libidn2)
  1006. if(LIBIDN2_FOUND)
  1007. set(CURL_LIBS "${LIBIDN2_LIBRARIES};${CURL_LIBS}")
  1008. list(APPEND CURL_LIBDIRS ${LIBIDN2_LIBRARY_DIRS})
  1009. set(LIBCURL_PC_REQUIRES_PRIVATE "libidn2;${LIBCURL_PC_REQUIRES_PRIVATE}")
  1010. include_directories(SYSTEM ${LIBIDN2_INCLUDE_DIRS})
  1011. link_directories(${LIBIDN2_LIBRARY_DIRS})
  1012. if(LIBIDN2_CFLAGS)
  1013. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBIDN2_CFLAGS}")
  1014. endif()
  1015. set(HAVE_IDN2_H 1)
  1016. set(HAVE_LIBIDN2 1)
  1017. endif()
  1018. endif()
  1019. # libpsl
  1020. option(CURL_USE_LIBPSL "Use libpsl" ON)
  1021. mark_as_advanced(CURL_USE_LIBPSL)
  1022. set(USE_LIBPSL OFF)
  1023. if(CURL_USE_LIBPSL)
  1024. find_package(Libpsl) # TODO: add REQUIRED to match autotools
  1025. if(LIBPSL_FOUND)
  1026. list(APPEND CURL_LIBS ${LIBPSL_LIBRARIES})
  1027. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libpsl")
  1028. include_directories(SYSTEM ${LIBPSL_INCLUDE_DIRS})
  1029. set(USE_LIBPSL ON)
  1030. else()
  1031. message(WARNING "libpsl is enabled, but not found.")
  1032. endif()
  1033. endif()
  1034. # libssh2
  1035. option(CURL_USE_LIBSSH2 "Use libssh2" ON)
  1036. mark_as_advanced(CURL_USE_LIBSSH2)
  1037. set(USE_LIBSSH2 OFF)
  1038. if(CURL_USE_LIBSSH2)
  1039. find_package(Libssh2)
  1040. if(LIBSSH2_FOUND)
  1041. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARIES})
  1042. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh2")
  1043. include_directories(SYSTEM ${LIBSSH2_INCLUDE_DIRS})
  1044. set(USE_LIBSSH2 ON)
  1045. endif()
  1046. endif()
  1047. # libssh
  1048. option(CURL_USE_LIBSSH "Use libssh" OFF)
  1049. mark_as_advanced(CURL_USE_LIBSSH)
  1050. if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
  1051. find_package(Libssh REQUIRED)
  1052. if(LIBSSH_FOUND)
  1053. list(APPEND CURL_LIBS ${LIBSSH_LIBRARIES})
  1054. list(APPEND CURL_LIBDIRS ${LIBSSH_LIBRARY_DIRS})
  1055. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh")
  1056. include_directories(SYSTEM ${LIBSSH_INCLUDE_DIRS})
  1057. link_directories(${LIBSSH_LIBRARY_DIRS})
  1058. if(LIBSSH_CFLAGS)
  1059. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBSSH_CFLAGS}")
  1060. endif()
  1061. set(USE_LIBSSH ON)
  1062. endif()
  1063. endif()
  1064. # wolfSSH
  1065. option(CURL_USE_WOLFSSH "Use wolfSSH" OFF)
  1066. mark_as_advanced(CURL_USE_WOLFSSH)
  1067. set(USE_WOLFSSH OFF)
  1068. if(NOT USE_LIBSSH2 AND NOT USE_LIBSSH AND CURL_USE_WOLFSSH)
  1069. if(USE_WOLFSSL)
  1070. find_package(WolfSSH)
  1071. if(WOLFSSH_FOUND)
  1072. list(APPEND CURL_LIBS ${WOLFSSH_LIBRARIES})
  1073. include_directories(SYSTEM ${WOLFSSH_INCLUDE_DIRS})
  1074. set(USE_WOLFSSH ON)
  1075. endif()
  1076. else()
  1077. message(WARNING "wolfSSH requires wolfSSL. Skipping.")
  1078. endif()
  1079. endif()
  1080. option(CURL_USE_GSASL "Use libgsasl" OFF)
  1081. mark_as_advanced(CURL_USE_GSASL)
  1082. if(CURL_USE_GSASL)
  1083. find_package(Libgsasl REQUIRED)
  1084. if(LIBGSASL_FOUND)
  1085. list(APPEND CURL_LIBS ${LIBGSASL_LIBRARIES})
  1086. list(APPEND CURL_LIBDIRS ${LIBGSASL_LIBRARY_DIRS})
  1087. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libgsasl")
  1088. include_directories(SYSTEM ${LIBGSASL_INCLUDE_DIRS})
  1089. link_directories(${LIBGSASL_LIBRARY_DIRS})
  1090. if(LIBGSASL_CFLAGS)
  1091. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBGSASL_CFLAGS}")
  1092. endif()
  1093. set(USE_GSASL ON)
  1094. endif()
  1095. endif()
  1096. option(CURL_USE_GSSAPI "Use GSSAPI implementation" OFF)
  1097. mark_as_advanced(CURL_USE_GSSAPI)
  1098. if(CURL_USE_GSSAPI)
  1099. find_package(GSS)
  1100. set(HAVE_GSSAPI ${GSS_FOUND})
  1101. if(GSS_FOUND)
  1102. if(GSS_FLAVOUR STREQUAL "GNU")
  1103. set(HAVE_GSSGNU 1)
  1104. else()
  1105. cmake_push_check_state()
  1106. list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRS})
  1107. set(_include_list "")
  1108. check_include_file("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  1109. if(HAVE_GSSAPI_GSSAPI_H)
  1110. list(APPEND _include_list "gssapi/gssapi.h")
  1111. endif()
  1112. check_include_files("${_include_list};gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  1113. if(GSS_FLAVOUR STREQUAL "MIT")
  1114. check_include_files("${_include_list};gssapi/gssapi_krb5.h" _have_gssapi_gssapi_krb5_h)
  1115. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  1116. list(APPEND _include_list "gssapi/gssapi_generic.h")
  1117. endif()
  1118. if(_have_gssapi_gssapi_krb5_h)
  1119. list(APPEND _include_list "gssapi/gssapi_krb5.h")
  1120. endif()
  1121. if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  1122. set(CMAKE_REQUIRED_FLAGS ${GSS_CFLAGS})
  1123. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  1124. curl_required_libpaths("${GSS_LIBRARY_DIRS}")
  1125. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" "${_include_list}" HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  1126. endif()
  1127. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  1128. set(HAVE_OLD_GSSMIT ON)
  1129. endif()
  1130. endif()
  1131. unset(_include_list)
  1132. cmake_pop_check_state()
  1133. endif()
  1134. list(APPEND CURL_LIBS ${GSS_LIBRARIES})
  1135. list(APPEND CURL_LIBDIRS ${GSS_LIBRARY_DIRS})
  1136. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${GSS_PC_REQUIRES})
  1137. include_directories(SYSTEM ${GSS_INCLUDE_DIRS})
  1138. link_directories(${GSS_LIBRARY_DIRS})
  1139. if(GSS_CFLAGS)
  1140. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_CFLAGS}")
  1141. endif()
  1142. else()
  1143. message(WARNING "GSSAPI has been requested, but no supporting libraries found. Skipping.")
  1144. endif()
  1145. endif()
  1146. # libuv
  1147. option(CURL_USE_LIBUV "Use libuv for event-based tests" OFF)
  1148. if(CURL_USE_LIBUV)
  1149. if(NOT ENABLE_DEBUG)
  1150. message(FATAL_ERROR "Using libuv without debug support enabled is useless")
  1151. endif()
  1152. find_package(Libuv REQUIRED)
  1153. if(LIBUV_FOUND)
  1154. list(APPEND CURL_LIBS ${LIBUV_LIBRARIES})
  1155. list(APPEND CURL_LIBDIRS ${LIBUV_LIBRARY_DIRS})
  1156. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libuv")
  1157. include_directories(SYSTEM ${LIBUV_INCLUDE_DIRS})
  1158. link_directories(${LIBUV_LIBRARY_DIRS})
  1159. if(LIBUV_CFLAGS)
  1160. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUV_CFLAGS}")
  1161. endif()
  1162. set(USE_LIBUV ON)
  1163. set(HAVE_UV_H ON)
  1164. endif()
  1165. endif()
  1166. option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF)
  1167. if(USE_LIBRTMP)
  1168. set(_extra_libs "rtmp")
  1169. if(WIN32)
  1170. list(APPEND _extra_libs "winmm")
  1171. endif()
  1172. openssl_check_symbol_exists("RTMP_Init" "librtmp/rtmp.h" HAVE_LIBRTMP "${_extra_libs}")
  1173. if(HAVE_LIBRTMP)
  1174. list(APPEND CURL_LIBS "rtmp")
  1175. list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "librtmp")
  1176. if(WIN32)
  1177. list(APPEND CURL_LIBS "winmm")
  1178. endif()
  1179. else()
  1180. message(WARNING "librtmp has been requested, but not found or missing OpenSSL. Skipping.")
  1181. set(USE_LIBRTMP OFF)
  1182. endif()
  1183. endif()
  1184. option(ENABLE_UNIX_SOCKETS "Enable Unix domain sockets support" ON)
  1185. if(ENABLE_UNIX_SOCKETS)
  1186. if(WIN32)
  1187. set(USE_UNIX_SOCKETS ON)
  1188. else()
  1189. include(CheckStructHasMember)
  1190. check_struct_has_member("struct sockaddr_un" "sun_path" "sys/un.h" USE_UNIX_SOCKETS)
  1191. endif()
  1192. else()
  1193. unset(USE_UNIX_SOCKETS CACHE)
  1194. endif()
  1195. #
  1196. # CA handling
  1197. #
  1198. if(_curl_ca_bundle_supported)
  1199. set(CURL_CA_BUNDLE "auto" CACHE
  1200. STRING "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  1201. set(CURL_CA_FALLBACK OFF CACHE BOOL
  1202. "Use built-in CA store of TLS backend. Defaults to OFF")
  1203. set(CURL_CA_PATH "auto" CACHE
  1204. STRING "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  1205. set(CURL_CA_EMBED "" CACHE
  1206. STRING "Path to the CA bundle to embed in the curl tool.")
  1207. if(CURL_CA_BUNDLE STREQUAL "")
  1208. message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
  1209. elseif(CURL_CA_BUNDLE STREQUAL "none")
  1210. unset(CURL_CA_BUNDLE CACHE)
  1211. elseif(CURL_CA_BUNDLE STREQUAL "auto")
  1212. unset(CURL_CA_BUNDLE CACHE)
  1213. if(NOT CMAKE_CROSSCOMPILING AND NOT WIN32)
  1214. set(_curl_ca_bundle_autodetect TRUE)
  1215. endif()
  1216. else()
  1217. set(CURL_CA_BUNDLE_SET TRUE)
  1218. endif()
  1219. mark_as_advanced(CURL_CA_BUNDLE_SET)
  1220. if(CURL_CA_PATH STREQUAL "")
  1221. message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
  1222. elseif(CURL_CA_PATH STREQUAL "none")
  1223. unset(CURL_CA_PATH CACHE)
  1224. elseif(CURL_CA_PATH STREQUAL "auto")
  1225. unset(CURL_CA_PATH CACHE)
  1226. if(NOT CMAKE_CROSSCOMPILING AND NOT WIN32)
  1227. set(_curl_ca_path_autodetect TRUE)
  1228. endif()
  1229. else()
  1230. set(CURL_CA_PATH_SET TRUE)
  1231. endif()
  1232. mark_as_advanced(CURL_CA_PATH_SET)
  1233. if(CURL_CA_BUNDLE_SET AND _curl_ca_path_autodetect)
  1234. # Skip auto-detection of unset CA path because CA bundle is set explicitly
  1235. elseif(CURL_CA_PATH_SET AND _curl_ca_bundle_autodetect)
  1236. # Skip auto-detection of unset CA bundle because CA path is set explicitly
  1237. elseif(_curl_ca_bundle_autodetect OR _curl_ca_path_autodetect)
  1238. # First try auto-detecting a CA bundle, then a CA path
  1239. if(_curl_ca_bundle_autodetect)
  1240. foreach(_search_ca_bundle_path IN ITEMS
  1241. "/etc/ssl/certs/ca-certificates.crt"
  1242. "/etc/pki/tls/certs/ca-bundle.crt"
  1243. "/usr/share/ssl/certs/ca-bundle.crt"
  1244. "/usr/local/share/certs/ca-root-nss.crt"
  1245. "/etc/ssl/cert.pem")
  1246. if(EXISTS "${_search_ca_bundle_path}")
  1247. message(STATUS "Found CA bundle: ${_search_ca_bundle_path}")
  1248. set(CURL_CA_BUNDLE "${_search_ca_bundle_path}" CACHE
  1249. STRING "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  1250. set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  1251. break()
  1252. endif()
  1253. endforeach()
  1254. endif()
  1255. if(_curl_ca_path_autodetect AND NOT CURL_CA_PATH_SET)
  1256. set(_search_ca_path "/etc/ssl/certs")
  1257. file(GLOB _curl_ca_files_found "${_search_ca_path}/[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].0")
  1258. if(_curl_ca_files_found)
  1259. unset(_curl_ca_files_found)
  1260. message(STATUS "Found CA path: ${_search_ca_path}")
  1261. set(CURL_CA_PATH "${_search_ca_path}" CACHE
  1262. STRING "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  1263. set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  1264. endif()
  1265. endif()
  1266. endif()
  1267. set(CURL_CA_EMBED_SET FALSE)
  1268. if(BUILD_CURL_EXE AND NOT CURL_CA_EMBED STREQUAL "")
  1269. if(EXISTS "${CURL_CA_EMBED}")
  1270. set(CURL_CA_EMBED_SET TRUE)
  1271. message(STATUS "Found CA bundle to embed: ${CURL_CA_EMBED}")
  1272. else()
  1273. message(FATAL_ERROR "CA bundle to embed is missing: '${CURL_CA_EMBED}'")
  1274. endif()
  1275. endif()
  1276. endif()
  1277. if(WIN32)
  1278. option(CURL_DISABLE_CA_SEARCH "Disable unsafe CA bundle search in PATH on Windows" OFF)
  1279. option(CURL_CA_SEARCH_SAFE "Enable safe CA bundle search (within the curl tool directory) on Windows" OFF)
  1280. endif()
  1281. # Check for header files
  1282. if(WIN32)
  1283. list(APPEND CURL_INCLUDES "winsock2.h")
  1284. list(APPEND CURL_INCLUDES "ws2tcpip.h")
  1285. if(HAVE_WIN32_WINNT)
  1286. if(HAVE_WIN32_WINNT LESS 0x0501)
  1287. # Windows XP is required for freeaddrinfo, getaddrinfo
  1288. message(FATAL_ERROR "Building for Windows XP or newer is required.")
  1289. endif()
  1290. # Pre-fill detection results based on target OS version
  1291. if(MINGW OR MSVC)
  1292. if(HAVE_WIN32_WINNT LESS 0x0600)
  1293. set(HAVE_INET_NTOP 0)
  1294. set(HAVE_INET_PTON 0)
  1295. else() # Windows Vista or newer
  1296. set(HAVE_INET_NTOP 1)
  1297. set(HAVE_INET_PTON 1)
  1298. endif()
  1299. unset(HAVE_INET_NTOP CACHE)
  1300. unset(HAVE_INET_PTON CACHE)
  1301. endif()
  1302. endif()
  1303. endif()
  1304. # Detect headers
  1305. # Use check_include_file_concat() for headers required by subsequent
  1306. # check_include_file_concat() or check_symbol_exists() detections.
  1307. # Order for these is significant.
  1308. check_include_file("sys/eventfd.h" HAVE_SYS_EVENTFD_H)
  1309. check_include_file("sys/filio.h" HAVE_SYS_FILIO_H)
  1310. check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
  1311. check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  1312. check_include_file("sys/param.h" HAVE_SYS_PARAM_H)
  1313. check_include_file("sys/poll.h" HAVE_SYS_POLL_H)
  1314. check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
  1315. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  1316. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  1317. check_include_file("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  1318. check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
  1319. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  1320. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  1321. check_include_file("sys/un.h" HAVE_SYS_UN_H)
  1322. check_include_file("sys/utime.h" HAVE_SYS_UTIME_H)
  1323. check_include_file("sys/xattr.h" HAVE_SYS_XATTR_H)
  1324. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  1325. check_include_file("dirent.h" HAVE_DIRENT_H)
  1326. check_include_file("fcntl.h" HAVE_FCNTL_H)
  1327. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  1328. check_include_file("io.h" HAVE_IO_H)
  1329. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  1330. check_include_file("linux/tcp.h" HAVE_LINUX_TCP_H)
  1331. check_include_file("locale.h" HAVE_LOCALE_H)
  1332. check_include_file("net/if.h" HAVE_NET_IF_H)
  1333. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  1334. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  1335. check_include_file("netinet/in6.h" HAVE_NETINET_IN6_H)
  1336. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H) # sys/types.h (e.g. Cygwin) netinet/in.h
  1337. check_include_file_concat("netinet/udp.h" HAVE_NETINET_UDP_H) # sys/types.h (e.g. Cygwin)
  1338. check_include_file("poll.h" HAVE_POLL_H)
  1339. check_include_file("pwd.h" HAVE_PWD_H)
  1340. check_include_file("stdatomic.h" HAVE_STDATOMIC_H)
  1341. check_include_file("stdbool.h" HAVE_STDBOOL_H)
  1342. check_include_file("strings.h" HAVE_STRINGS_H)
  1343. check_include_file("stropts.h" HAVE_STROPTS_H)
  1344. check_include_file("termio.h" HAVE_TERMIO_H)
  1345. check_include_file("termios.h" HAVE_TERMIOS_H)
  1346. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  1347. check_include_file("utime.h" HAVE_UTIME_H)
  1348. if(CMAKE_SYSTEM_NAME MATCHES "AmigaOS")
  1349. check_include_file_concat("proto/bsdsocket.h" HAVE_PROTO_BSDSOCKET_H)
  1350. endif()
  1351. # Pass these detection results to curl_internal_test() for use in CurlTests.c
  1352. # Add here all feature flags referenced from CurlTests.c
  1353. foreach(_variable IN ITEMS
  1354. HAVE_STDATOMIC_H
  1355. HAVE_STDBOOL_H
  1356. HAVE_STROPTS_H
  1357. HAVE_SYS_IOCTL_H
  1358. HAVE_SYS_SOCKET_H
  1359. HAVE_SYS_TYPES_H
  1360. HAVE_UNISTD_H
  1361. )
  1362. if(${_variable})
  1363. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${_variable}")
  1364. endif()
  1365. endforeach()
  1366. check_type_size("size_t" SIZEOF_SIZE_T)
  1367. check_type_size("ssize_t" SIZEOF_SSIZE_T)
  1368. check_type_size("long long" SIZEOF_LONG_LONG)
  1369. check_type_size("long" SIZEOF_LONG)
  1370. check_type_size("int" SIZEOF_INT)
  1371. check_type_size("__int64" SIZEOF___INT64)
  1372. check_type_size("time_t" SIZEOF_TIME_T)
  1373. check_type_size("suseconds_t" SIZEOF_SUSECONDS_T)
  1374. if(NOT HAVE_SIZEOF_SSIZE_T)
  1375. if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  1376. set(ssize_t "long")
  1377. endif()
  1378. if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  1379. set(ssize_t "__int64")
  1380. endif()
  1381. endif()
  1382. # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
  1383. if(SIZEOF_LONG_LONG)
  1384. set(HAVE_LONGLONG 1)
  1385. endif()
  1386. if(SIZEOF_SUSECONDS_T)
  1387. set(HAVE_SUSECONDS_T 1)
  1388. endif()
  1389. # Check for some functions that are used
  1390. if(WIN32)
  1391. list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32") # Apply to all feature checks
  1392. elseif(HAVE_LIBSOCKET)
  1393. list(APPEND CMAKE_REQUIRED_LIBRARIES "socket") # Apply to all feature checks
  1394. endif()
  1395. check_function_exists("fnmatch" HAVE_FNMATCH)
  1396. check_symbol_exists("basename" "${CURL_INCLUDES};string.h" HAVE_BASENAME) # libgen.h unistd.h
  1397. check_symbol_exists("opendir" "dirent.h" HAVE_OPENDIR)
  1398. check_function_exists("poll" HAVE_POLL) # poll.h
  1399. check_symbol_exists("socket" "${CURL_INCLUDES}" HAVE_SOCKET) # winsock2.h sys/socket.h
  1400. check_function_exists("sched_yield" HAVE_SCHED_YIELD)
  1401. check_symbol_exists("socketpair" "${CURL_INCLUDES}" HAVE_SOCKETPAIR) # sys/socket.h
  1402. check_symbol_exists("recv" "${CURL_INCLUDES}" HAVE_RECV) # proto/bsdsocket.h sys/types.h sys/socket.h
  1403. check_symbol_exists("send" "${CURL_INCLUDES}" HAVE_SEND) # proto/bsdsocket.h sys/types.h sys/socket.h
  1404. check_function_exists("sendmsg" HAVE_SENDMSG)
  1405. check_function_exists("sendmmsg" HAVE_SENDMMSG)
  1406. check_symbol_exists("select" "${CURL_INCLUDES}" HAVE_SELECT) # proto/bsdsocket.h sys/select.h sys/socket.h
  1407. check_symbol_exists("strdup" "string.h" HAVE_STRDUP)
  1408. check_symbol_exists("strtok_r" "string.h" HAVE_STRTOK_R)
  1409. check_symbol_exists("strcasecmp" "string.h" HAVE_STRCASECMP)
  1410. check_symbol_exists("stricmp" "string.h" HAVE_STRICMP)
  1411. check_symbol_exists("strcmpi" "string.h" HAVE_STRCMPI)
  1412. check_symbol_exists("memrchr" "string.h" HAVE_MEMRCHR)
  1413. check_symbol_exists("alarm" "unistd.h" HAVE_ALARM)
  1414. check_symbol_exists("fcntl" "fcntl.h" HAVE_FCNTL)
  1415. check_function_exists("getppid" HAVE_GETPPID)
  1416. check_function_exists("utimes" HAVE_UTIMES)
  1417. check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY) # sys/time.h
  1418. check_symbol_exists("closesocket" "${CURL_INCLUDES}" HAVE_CLOSESOCKET) # winsock2.h
  1419. check_symbol_exists("sigsetjmp" "setjmp.h" HAVE_SIGSETJMP)
  1420. check_function_exists("getpass_r" HAVE_GETPASS_R)
  1421. check_function_exists("getpwuid" HAVE_GETPWUID)
  1422. check_function_exists("getpwuid_r" HAVE_GETPWUID_R)
  1423. check_function_exists("geteuid" HAVE_GETEUID)
  1424. check_function_exists("utime" HAVE_UTIME)
  1425. check_symbol_exists("gmtime_r" "stdlib.h;time.h" HAVE_GMTIME_R)
  1426. check_symbol_exists("gethostbyname_r" "netdb.h" HAVE_GETHOSTBYNAME_R)
  1427. check_symbol_exists("signal" "signal.h" HAVE_SIGNAL)
  1428. check_symbol_exists("strtoll" "stdlib.h" HAVE_STRTOLL)
  1429. check_symbol_exists("strerror_r" "stdlib.h;string.h" HAVE_STRERROR_R)
  1430. check_symbol_exists("sigaction" "signal.h" HAVE_SIGACTION)
  1431. check_symbol_exists("siginterrupt" "signal.h" HAVE_SIGINTERRUPT)
  1432. check_symbol_exists("getaddrinfo" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_GETADDRINFO) # ws2tcpip.h sys/socket.h netdb.h
  1433. check_symbol_exists("getifaddrs" "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS) # ifaddrs.h
  1434. check_symbol_exists("freeaddrinfo" "${CURL_INCLUDES}" HAVE_FREEADDRINFO) # ws2tcpip.h sys/socket.h netdb.h
  1435. check_function_exists("pipe" HAVE_PIPE)
  1436. check_function_exists("eventfd" HAVE_EVENTFD)
  1437. check_symbol_exists("ftruncate" "unistd.h" HAVE_FTRUNCATE)
  1438. check_symbol_exists("getpeername" "${CURL_INCLUDES}" HAVE_GETPEERNAME) # winsock2.h unistd.h proto/bsdsocket.h
  1439. check_symbol_exists("getsockname" "${CURL_INCLUDES}" HAVE_GETSOCKNAME) # winsock2.h unistd.h proto/bsdsocket.h
  1440. check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # winsock2.h net/if.h
  1441. check_function_exists("getrlimit" HAVE_GETRLIMIT)
  1442. check_function_exists("setlocale" HAVE_SETLOCALE)
  1443. check_function_exists("setmode" HAVE_SETMODE)
  1444. check_function_exists("setrlimit" HAVE_SETRLIMIT)
  1445. if(WIN32 OR CYGWIN)
  1446. check_function_exists("_setmode" HAVE__SETMODE)
  1447. endif()
  1448. if(CMAKE_SYSTEM_NAME MATCHES "AmigaOS")
  1449. check_symbol_exists("CloseSocket" "${CURL_INCLUDES}" HAVE_CLOSESOCKET_CAMEL) # sys/socket.h proto/bsdsocket.h
  1450. endif()
  1451. if(NOT _ssl_enabled)
  1452. check_symbol_exists("arc4random" "${CURL_INCLUDES};stdlib.h" HAVE_ARC4RANDOM)
  1453. endif()
  1454. if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900))
  1455. # Earlier MSVC compilers had faulty snprintf implementations
  1456. check_function_exists("snprintf" HAVE_SNPRINTF)
  1457. endif()
  1458. if(APPLE)
  1459. check_function_exists("mach_absolute_time" HAVE_MACH_ABSOLUTE_TIME)
  1460. endif()
  1461. check_symbol_exists("inet_ntop" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP) # arpa/inet.h
  1462. if(MSVC AND (MSVC_VERSION LESS_EQUAL 1600))
  1463. set(HAVE_INET_NTOP OFF)
  1464. endif()
  1465. check_symbol_exists("inet_pton" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON) # arpa/inet.h
  1466. check_symbol_exists("fsetxattr" "sys/xattr.h" HAVE_FSETXATTR)
  1467. if(HAVE_FSETXATTR)
  1468. curl_internal_test(HAVE_FSETXATTR_5)
  1469. curl_internal_test(HAVE_FSETXATTR_6)
  1470. endif()
  1471. cmake_push_check_state()
  1472. if(WIN32)
  1473. set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h")
  1474. check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY)
  1475. set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY})
  1476. elseif(HAVE_SYS_SOCKET_H)
  1477. set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
  1478. check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T)
  1479. set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T})
  1480. endif()
  1481. cmake_pop_check_state()
  1482. # Do curl specific tests
  1483. foreach(_curl_test IN ITEMS
  1484. HAVE_FCNTL_O_NONBLOCK
  1485. HAVE_IOCTLSOCKET
  1486. HAVE_IOCTLSOCKET_CAMEL
  1487. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  1488. HAVE_IOCTLSOCKET_FIONBIO
  1489. HAVE_IOCTL_FIONBIO
  1490. HAVE_IOCTL_SIOCGIFADDR
  1491. HAVE_SETSOCKOPT_SO_NONBLOCK
  1492. HAVE_O_NONBLOCK
  1493. HAVE_GETHOSTBYNAME_R_3
  1494. HAVE_GETHOSTBYNAME_R_5
  1495. HAVE_GETHOSTBYNAME_R_6
  1496. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  1497. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  1498. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  1499. HAVE_IN_ADDR_T
  1500. HAVE_BOOL_T
  1501. STDC_HEADERS
  1502. HAVE_FILE_OFFSET_BITS
  1503. HAVE_ATOMIC
  1504. )
  1505. curl_internal_test(${_curl_test})
  1506. endforeach()
  1507. cmake_push_check_state()
  1508. if(HAVE_FILE_OFFSET_BITS)
  1509. set(_FILE_OFFSET_BITS 64)
  1510. set(CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
  1511. endif()
  1512. check_type_size("off_t" SIZEOF_OFF_T)
  1513. # fseeko may not exist with _FILE_OFFSET_BITS=64 but can exist with
  1514. # _FILE_OFFSET_BITS unset or 32 (e.g. Android ARMv7 with NDK 26b and API level < 24)
  1515. # so we need to test fseeko after testing for _FILE_OFFSET_BITS
  1516. check_symbol_exists("fseeko" "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
  1517. if(HAVE_FSEEKO)
  1518. set(HAVE_DECL_FSEEKO 1)
  1519. endif()
  1520. # Include this header to get the type
  1521. cmake_push_check_state()
  1522. set(CMAKE_REQUIRED_INCLUDES "${PROJECT_SOURCE_DIR}/include")
  1523. set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
  1524. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  1525. set(CMAKE_EXTRA_INCLUDE_FILES "curl/curl.h")
  1526. check_type_size("curl_socket_t" SIZEOF_CURL_SOCKET_T)
  1527. cmake_pop_check_state() # pop curl system headers
  1528. cmake_pop_check_state() # pop -D_FILE_OFFSET_BITS=64
  1529. if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
  1530. # On non-Windows and not cross-compiling, check for writable argv[]
  1531. include(CheckCSourceRuns)
  1532. check_c_source_runs("
  1533. int main(int argc, char **argv)
  1534. {
  1535. (void)argc;
  1536. argv[0][0] = ' ';
  1537. return (argv[0][0] == ' ')?0:1;
  1538. }" HAVE_WRITABLE_ARGV)
  1539. endif()
  1540. curl_internal_test(HAVE_GLIBC_STRERROR_R)
  1541. curl_internal_test(HAVE_POSIX_STRERROR_R)
  1542. # Check for reentrant
  1543. foreach(_curl_test IN ITEMS
  1544. HAVE_GETHOSTBYNAME_R_3
  1545. HAVE_GETHOSTBYNAME_R_5
  1546. HAVE_GETHOSTBYNAME_R_6)
  1547. if(NOT ${_curl_test})
  1548. if(${_curl_test}_REENTRANT)
  1549. set(NEED_REENTRANT 1)
  1550. endif()
  1551. endif()
  1552. endforeach()
  1553. if(NEED_REENTRANT)
  1554. foreach(_curl_test IN ITEMS
  1555. HAVE_GETHOSTBYNAME_R_3
  1556. HAVE_GETHOSTBYNAME_R_5
  1557. HAVE_GETHOSTBYNAME_R_6)
  1558. set(${_curl_test} 0)
  1559. if(${_curl_test}_REENTRANT)
  1560. set(${_curl_test} 1)
  1561. endif()
  1562. endforeach()
  1563. endif()
  1564. if(NOT WIN32)
  1565. curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC) # Check clock_gettime(CLOCK_MONOTONIC, x) support
  1566. endif()
  1567. if(APPLE)
  1568. curl_internal_test(HAVE_BUILTIN_AVAILABLE) # Check compiler support of __builtin_available()
  1569. endif()
  1570. # Some other minor tests
  1571. if(NOT HAVE_IN_ADDR_T)
  1572. set(in_addr_t "unsigned long")
  1573. endif()
  1574. # Check for nonblocking
  1575. set(HAVE_DISABLED_NONBLOCKING 1)
  1576. if(HAVE_FIONBIO OR
  1577. HAVE_IOCTLSOCKET OR
  1578. HAVE_IOCTLSOCKET_CASE OR
  1579. HAVE_O_NONBLOCK)
  1580. unset(HAVE_DISABLED_NONBLOCKING)
  1581. endif()
  1582. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  1583. include(CheckCCompilerFlag)
  1584. check_c_compiler_flag("-Wno-long-double" HAVE_C_FLAG_Wno_long_double)
  1585. if(HAVE_C_FLAG_Wno_long_double)
  1586. # The Mac version of GCC warns about use of long double. Disable it.
  1587. get_source_file_property(_mprintf_compile_flags "mprintf.c" COMPILE_FLAGS)
  1588. if(_mprintf_compile_flags)
  1589. set(_mprintf_compile_flags "${_mprintf_compile_flags} -Wno-long-double")
  1590. else()
  1591. set(_mprintf_compile_flags "-Wno-long-double")
  1592. endif()
  1593. set_source_files_properties("mprintf.c" PROPERTIES
  1594. COMPILE_FLAGS ${_mprintf_compile_flags})
  1595. endif()
  1596. endif()
  1597. if(_cmake_try_compile_target_type_save)
  1598. set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_cmake_try_compile_target_type_save})
  1599. unset(_cmake_try_compile_target_type_save)
  1600. endif()
  1601. include(CMake/OtherTests.cmake)
  1602. add_definitions("-DHAVE_CONFIG_H")
  1603. # For Windows, all compilers used by CMake should support large files
  1604. if(WIN32)
  1605. set(USE_WIN32_LARGE_FILES ON)
  1606. # Use the manifest embedded in the Windows Resource
  1607. set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
  1608. # We use crypto functions that are not available for UWP apps
  1609. if(NOT WINDOWS_STORE)
  1610. set(USE_WIN32_CRYPTO ON)
  1611. endif()
  1612. # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL
  1613. if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
  1614. list(APPEND CURL_LIBS "advapi32" "crypt32")
  1615. endif()
  1616. endif()
  1617. if(MSVC)
  1618. # Disable default manifest added by CMake
  1619. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
  1620. add_definitions("-D_CRT_SECURE_NO_DEPRECATE" "-D_CRT_NONSTDC_NO_DEPRECATE")
  1621. if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
  1622. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  1623. else()
  1624. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  1625. endif()
  1626. # Use multithreaded compilation on VS 2008+
  1627. if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1500)
  1628. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
  1629. endif()
  1630. endif()
  1631. if(CURL_WERROR)
  1632. if(MSVC)
  1633. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
  1634. else()
  1635. # This assumes clang or gcc style options
  1636. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
  1637. endif()
  1638. endif()
  1639. if(CURL_LTO)
  1640. if(CMAKE_VERSION VERSION_LESS 3.9)
  1641. message(FATAL_ERROR "LTO has been requested, but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
  1642. endif()
  1643. cmake_policy(SET CMP0069 NEW)
  1644. include(CheckIPOSupported)
  1645. check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT _lto_error LANGUAGES C)
  1646. if(CURL_HAS_LTO)
  1647. message(STATUS "LTO supported and enabled")
  1648. else()
  1649. message(FATAL_ERROR "LTO has been requested, but the compiler does not support it\n${_lto_error}")
  1650. endif()
  1651. endif()
  1652. # Ugly (but functional) way to include "Makefile.inc" by transforming it
  1653. # (= regenerate it).
  1654. function(transform_makefile_inc _input_file _output_file)
  1655. file(READ ${_input_file} _makefile_inc_text)
  1656. string(REPLACE "$(top_srcdir)" "\${PROJECT_SOURCE_DIR}" _makefile_inc_text ${_makefile_inc_text})
  1657. string(REPLACE "$(top_builddir)" "\${PROJECT_BINARY_DIR}" _makefile_inc_text ${_makefile_inc_text})
  1658. string(REGEX REPLACE "\\\\\n" "!π!α!" _makefile_inc_text ${_makefile_inc_text})
  1659. string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "set(\\1 \\2)" _makefile_inc_text ${_makefile_inc_text})
  1660. string(REPLACE "!π!α!" "\n" _makefile_inc_text ${_makefile_inc_text})
  1661. # Replace $() with ${}
  1662. string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" _makefile_inc_text ${_makefile_inc_text})
  1663. # Replace @@ with ${}, even if that may not be read by CMake scripts.
  1664. string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" _makefile_inc_text ${_makefile_inc_text})
  1665. file(WRITE ${_output_file} ${_makefile_inc_text})
  1666. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${_input_file}")
  1667. endfunction()
  1668. include(GNUInstallDirs)
  1669. set(_install_cmake_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
  1670. set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
  1671. set(_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
  1672. set(_project_config "${_generated_dir}/${PROJECT_NAME}Config.cmake")
  1673. set(_version_config "${_generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
  1674. option(BUILD_TESTING "Build tests" ON)
  1675. if(BUILD_TESTING AND PERL_FOUND AND NOT CURL_DISABLE_TESTS)
  1676. set(CURL_BUILD_TESTING ON)
  1677. else()
  1678. set(CURL_BUILD_TESTING OFF)
  1679. endif()
  1680. if(HAVE_MANUAL_TOOLS)
  1681. set(CURL_MANPAGE "${PROJECT_BINARY_DIR}/docs/cmdline-opts/curl.1")
  1682. set(CURL_ASCIIPAGE "${PROJECT_BINARY_DIR}/docs/cmdline-opts/curl.txt")
  1683. add_subdirectory(docs)
  1684. endif()
  1685. add_subdirectory(lib)
  1686. if(BUILD_CURL_EXE)
  1687. add_subdirectory(src)
  1688. endif()
  1689. option(BUILD_EXAMPLES "Build libcurl examples" ON)
  1690. if(BUILD_EXAMPLES)
  1691. add_subdirectory(docs/examples)
  1692. endif()
  1693. if(CURL_BUILD_TESTING)
  1694. add_subdirectory(tests)
  1695. endif()
  1696. # Helper to populate a list (_items) with a label when conditions
  1697. # (the remaining args) are satisfied
  1698. macro(_add_if _label)
  1699. # Needs to be a macro to allow this indirection
  1700. if(${ARGN})
  1701. set(_items ${_items} "${_label}")
  1702. endif()
  1703. endmacro()
  1704. # NTLM support requires crypto functions from various SSL libs.
  1705. # These conditions must match those in lib/curl_setup.h.
  1706. if(NOT CURL_DISABLE_NTLM AND
  1707. (USE_OPENSSL OR
  1708. USE_MBEDTLS OR
  1709. USE_GNUTLS OR
  1710. USE_SECTRANSP OR
  1711. USE_WIN32_CRYPTO OR
  1712. (USE_WOLFSSL AND HAVE_WOLFSSL_DES_ECB_ENCRYPT)))
  1713. set(_use_curl_ntlm_core ON)
  1714. endif()
  1715. # Clear list and try to detect available protocols
  1716. unset(_items)
  1717. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1718. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND _ssl_enabled)
  1719. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1720. _add_if("FTPS" NOT CURL_DISABLE_FTP AND _ssl_enabled)
  1721. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1722. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1723. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1724. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1725. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1726. ((USE_OPENLDAP AND _ssl_enabled) OR
  1727. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1728. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1729. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1730. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1731. _add_if("GOPHERS" NOT CURL_DISABLE_GOPHER AND _ssl_enabled)
  1732. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1733. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND _ssl_enabled)
  1734. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1735. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND _ssl_enabled)
  1736. _add_if("SMB" NOT CURL_DISABLE_SMB AND
  1737. _use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
  1738. _add_if("SMBS" NOT CURL_DISABLE_SMB AND _ssl_enabled AND
  1739. _use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
  1740. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1741. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND _ssl_enabled)
  1742. _add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH OR USE_WOLFSSH)
  1743. _add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH OR USE_WOLFSSH)
  1744. _add_if("IPFS" NOT CURL_DISABLE_IPFS)
  1745. _add_if("IPNS" NOT CURL_DISABLE_IPFS)
  1746. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1747. _add_if("RTMP" USE_LIBRTMP)
  1748. _add_if("MQTT" NOT CURL_DISABLE_MQTT)
  1749. _add_if("WS" NOT CURL_DISABLE_WEBSOCKETS)
  1750. _add_if("WSS" NOT CURL_DISABLE_WEBSOCKETS AND _ssl_enabled)
  1751. if(_items)
  1752. list(SORT _items)
  1753. endif()
  1754. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1755. string(TOLOWER "${SUPPORT_PROTOCOLS}" _support_protocols_lower)
  1756. message(STATUS "Protocols: ${_support_protocols_lower}")
  1757. # Clear list and try to detect available features
  1758. unset(_items)
  1759. _add_if("SSL" _ssl_enabled)
  1760. _add_if("IPv6" ENABLE_IPV6)
  1761. _add_if("UnixSockets" USE_UNIX_SOCKETS)
  1762. _add_if("libz" HAVE_LIBZ)
  1763. _add_if("brotli" HAVE_BROTLI)
  1764. _add_if("gsasl" USE_GSASL)
  1765. _add_if("zstd" HAVE_ZSTD)
  1766. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
  1767. _add_if("IDN" (HAVE_LIBIDN2 AND HAVE_IDN2_H) OR
  1768. USE_WIN32_IDN OR
  1769. USE_APPLE_IDN)
  1770. _add_if("Largefile" (SIZEOF_CURL_OFF_T GREATER 4) AND
  1771. ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
  1772. _add_if("SSPI" USE_WINDOWS_SSPI)
  1773. _add_if("GSS-API" HAVE_GSSAPI)
  1774. _add_if("alt-svc" NOT CURL_DISABLE_ALTSVC)
  1775. _add_if("HSTS" NOT CURL_DISABLE_HSTS)
  1776. _add_if("SPNEGO" NOT CURL_DISABLE_NEGOTIATE_AUTH AND
  1777. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1778. _add_if("Kerberos" NOT CURL_DISABLE_KERBEROS_AUTH AND
  1779. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1780. _add_if("NTLM" NOT (CURL_DISABLE_NTLM) AND
  1781. (_use_curl_ntlm_core OR USE_WINDOWS_SSPI))
  1782. _add_if("TLS-SRP" USE_TLS_SRP)
  1783. _add_if("HTTP2" USE_NGHTTP2)
  1784. _add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE OR USE_MSH3 OR USE_OPENSSL_QUIC)
  1785. _add_if("MultiSSL" CURL_WITH_MULTI_SSL)
  1786. _add_if("HTTPS-proxy" _ssl_enabled AND (USE_OPENSSL OR USE_GNUTLS
  1787. OR USE_SCHANNEL OR USE_RUSTLS OR USE_BEARSSL OR
  1788. USE_MBEDTLS OR USE_SECTRANSP OR
  1789. (USE_WOLFSSL AND HAVE_WOLFSSL_BIO)))
  1790. _add_if("Unicode" ENABLE_UNICODE)
  1791. _add_if("threadsafe" HAVE_ATOMIC OR
  1792. (USE_THREADS_POSIX AND HAVE_PTHREAD_H) OR
  1793. (WIN32 AND HAVE_WIN32_WINNT GREATER_EQUAL 0x0600))
  1794. _add_if("Debug" ENABLE_DEBUG)
  1795. _add_if("TrackMemory" ENABLE_CURLDEBUG)
  1796. _add_if("ECH" _ssl_enabled AND HAVE_ECH)
  1797. _add_if("PSL" USE_LIBPSL)
  1798. _add_if("CAcert" CURL_CA_EMBED_SET)
  1799. if(_items)
  1800. if(NOT CMAKE_VERSION VERSION_LESS 3.13)
  1801. list(SORT _items CASE INSENSITIVE)
  1802. else()
  1803. list(SORT _items)
  1804. endif()
  1805. endif()
  1806. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1807. message(STATUS "Features: ${SUPPORT_FEATURES}")
  1808. # Clear list and collect SSL backends
  1809. unset(_items)
  1810. _add_if("Schannel" _ssl_enabled AND USE_SCHANNEL)
  1811. _add_if("OpenSSL" _ssl_enabled AND USE_OPENSSL AND OPENSSL_VERSION VERSION_LESS 3.0.0)
  1812. _add_if("OpenSSL v3+" _ssl_enabled AND USE_OPENSSL AND NOT OPENSSL_VERSION VERSION_LESS 3.0.0)
  1813. _add_if("Secure Transport" _ssl_enabled AND USE_SECTRANSP)
  1814. _add_if("mbedTLS" _ssl_enabled AND USE_MBEDTLS)
  1815. _add_if("BearSSL" _ssl_enabled AND USE_BEARSSL)
  1816. _add_if("wolfSSL" _ssl_enabled AND USE_WOLFSSL)
  1817. _add_if("GnuTLS" _ssl_enabled AND USE_GNUTLS)
  1818. _add_if("rustls" _ssl_enabled AND USE_RUSTLS)
  1819. if(_items)
  1820. if(NOT CMAKE_VERSION VERSION_LESS 3.13)
  1821. list(SORT _items CASE INSENSITIVE)
  1822. else()
  1823. list(SORT _items)
  1824. endif()
  1825. endif()
  1826. string(REPLACE ";" " " SSL_BACKENDS "${_items}")
  1827. message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
  1828. if(CURL_DEFAULT_SSL_BACKEND)
  1829. message(STATUS "Default SSL backend: ${CURL_DEFAULT_SSL_BACKEND}")
  1830. endif()
  1831. if(NOT CURL_DISABLE_INSTALL)
  1832. # curl-config needs the following options to be set.
  1833. set(CC "${CMAKE_C_COMPILER}")
  1834. # TODO: probably put a -D... options here?
  1835. set(CONFIGURE_OPTIONS "")
  1836. set(CURLVERSION "${_curl_version}")
  1837. set(VERSIONNUM "${_curl_version_num}")
  1838. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1839. set(exec_prefix "\${prefix}")
  1840. if(IS_ABSOLUTE ${CMAKE_INSTALL_INCLUDEDIR})
  1841. set(includedir "${CMAKE_INSTALL_INCLUDEDIR}")
  1842. else()
  1843. set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
  1844. endif()
  1845. if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR})
  1846. set(libdir "${CMAKE_INSTALL_LIBDIR}")
  1847. else()
  1848. set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
  1849. endif()
  1850. # "a" (Linux) or "lib" (Windows)
  1851. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1852. set(_ldflags "")
  1853. set(LIBCURL_PC_LIBS_PRIVATE "")
  1854. # Avoid getting unnecessary -L options for known system directories.
  1855. unset(_sys_libdirs)
  1856. foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
  1857. if(_libdir MATCHES "/$")
  1858. set(_libdir "${_libdir}lib")
  1859. else()
  1860. set(_libdir "${_libdir}/lib")
  1861. endif()
  1862. if(IS_DIRECTORY "${_libdir}")
  1863. list(APPEND _sys_libdirs "${_libdir}")
  1864. endif()
  1865. if(DEFINED CMAKE_LIBRARY_ARCHITECTURE)
  1866. set(_libdir "${_libdir}/${CMAKE_LIBRARY_ARCHITECTURE}")
  1867. if(IS_DIRECTORY "${_libdir}")
  1868. list(APPEND _sys_libdirs "${_libdir}")
  1869. endif()
  1870. endif()
  1871. endforeach()
  1872. foreach(_libdir IN LISTS CURL_LIBDIRS)
  1873. list(FIND _sys_libdirs "${_libdir}" _libdir_index)
  1874. if(_libdir_index LESS 0)
  1875. list(APPEND _ldflags "-L${_libdir}")
  1876. endif()
  1877. endforeach()
  1878. unset(_implicit_libs)
  1879. if(NOT MINGW AND NOT UNIX)
  1880. set(_implicit_libs ${CMAKE_C_IMPLICIT_LINK_LIBRARIES})
  1881. endif()
  1882. foreach(_lib IN LISTS _implicit_libs CURL_LIBS)
  1883. if(TARGET "${_lib}")
  1884. set(_libname "${_lib}")
  1885. get_target_property(_imported "${_libname}" IMPORTED)
  1886. if(NOT _imported)
  1887. # Reading the LOCATION property on non-imported target will error out.
  1888. # Assume the user will not need this information in the .pc file.
  1889. continue()
  1890. endif()
  1891. get_target_property(_lib "${_libname}" LOCATION)
  1892. if(NOT _lib)
  1893. message(WARNING "Bad lib in library list: ${_libname}")
  1894. continue()
  1895. endif()
  1896. endif()
  1897. if(_lib MATCHES "^-") # '-framework <name>'
  1898. list(APPEND _ldflags "${_lib}")
  1899. elseif(_lib MATCHES ".*/.*")
  1900. # This gets a bit more complex, because we want to specify the
  1901. # directory separately, and only once per directory
  1902. get_filename_component(_libdir ${_lib} DIRECTORY)
  1903. get_filename_component(_libname ${_lib} NAME_WE)
  1904. if(_libname MATCHES "^lib")
  1905. list(FIND _sys_libdirs "${_libdir}" _libdir_index)
  1906. if(_libdir_index LESS 0)
  1907. list(APPEND _ldflags "-L${_libdir}")
  1908. endif()
  1909. string(REGEX REPLACE "^lib" "" _libname "${_libname}")
  1910. list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_libname}")
  1911. else()
  1912. list(APPEND LIBCURL_PC_LIBS_PRIVATE "${_lib}")
  1913. endif()
  1914. else()
  1915. list(APPEND LIBCURL_PC_LIBS_PRIVATE "-l${_lib}")
  1916. endif()
  1917. endforeach()
  1918. if(LIBCURL_PC_REQUIRES_PRIVATE)
  1919. string(REPLACE ";" "," LIBCURL_PC_REQUIRES_PRIVATE "${LIBCURL_PC_REQUIRES_PRIVATE}")
  1920. endif()
  1921. if(LIBCURL_PC_LIBS_PRIVATE)
  1922. string(REPLACE ";" " " LIBCURL_PC_LIBS_PRIVATE "${LIBCURL_PC_LIBS_PRIVATE}")
  1923. endif()
  1924. set(LIBCURL_PC_LDFLAGS_PRIVATE "${CMAKE_SHARED_LINKER_FLAGS}")
  1925. if(_ldflags)
  1926. list(REMOVE_DUPLICATES _ldflags)
  1927. string(REPLACE ";" " " _ldflags "${_ldflags}")
  1928. set(LIBCURL_PC_LDFLAGS_PRIVATE "${LIBCURL_PC_LDFLAGS_PRIVATE} ${_ldflags}")
  1929. string(STRIP "${LIBCURL_PC_LDFLAGS_PRIVATE}" LIBCURL_PC_LDFLAGS_PRIVATE)
  1930. endif()
  1931. set(LIBCURL_PC_CFLAGS_PRIVATE "-DCURL_STATICLIB")
  1932. # Merge pkg-config private fields into public ones when static-only
  1933. if(BUILD_SHARED_LIBS)
  1934. set(ENABLE_SHARED "yes")
  1935. set(LIBCURL_PC_REQUIRES "")
  1936. set(LIBCURL_PC_LIBS "")
  1937. set(LIBCURL_PC_CFLAGS "")
  1938. else()
  1939. set(ENABLE_SHARED "no")
  1940. set(LIBCURL_PC_REQUIRES "${LIBCURL_PC_REQUIRES_PRIVATE}")
  1941. set(LIBCURL_PC_LIBS "${LIBCURL_PC_LIBS_PRIVATE}")
  1942. set(LIBCURL_PC_CFLAGS "${LIBCURL_PC_CFLAGS_PRIVATE}")
  1943. endif()
  1944. if(BUILD_STATIC_LIBS)
  1945. set(ENABLE_STATIC "yes")
  1946. else()
  1947. set(ENABLE_STATIC "no")
  1948. endif()
  1949. # Generate a "curl-config" matching this config.
  1950. # Consumed variables:
  1951. # CC
  1952. # CONFIGURE_OPTIONS
  1953. # CURLVERSION
  1954. # CURL_CA_BUNDLE
  1955. # ENABLE_SHARED
  1956. # ENABLE_STATIC
  1957. # exec_prefix
  1958. # includedir
  1959. # LIBCURL_PC_CFLAGS
  1960. # LIBCURL_PC_LDFLAGS_PRIVATE
  1961. # LIBCURL_PC_LIBS_PRIVATE
  1962. # libdir
  1963. # libext
  1964. # prefix
  1965. # SSL_BACKENDS
  1966. # SUPPORT_FEATURES
  1967. # SUPPORT_PROTOCOLS
  1968. # VERSIONNUM
  1969. configure_file(
  1970. "${PROJECT_SOURCE_DIR}/curl-config.in"
  1971. "${PROJECT_BINARY_DIR}/curl-config" @ONLY)
  1972. install(FILES "${PROJECT_BINARY_DIR}/curl-config"
  1973. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1974. PERMISSIONS
  1975. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1976. GROUP_READ GROUP_EXECUTE
  1977. WORLD_READ WORLD_EXECUTE)
  1978. # Generate a pkg-config file matching this config.
  1979. # Consumed variables:
  1980. # CURLVERSION
  1981. # exec_prefix
  1982. # includedir
  1983. # LIBCURL_PC_CFLAGS
  1984. # LIBCURL_PC_CFLAGS_PRIVATE
  1985. # LIBCURL_PC_LDFLAGS_PRIVATE
  1986. # LIBCURL_PC_LIBS
  1987. # LIBCURL_PC_LIBS_PRIVATE
  1988. # LIBCURL_PC_REQUIRES
  1989. # LIBCURL_PC_REQUIRES_PRIVATE
  1990. # libdir
  1991. # prefix
  1992. # SUPPORT_FEATURES
  1993. # SUPPORT_PROTOCOLS
  1994. # Documentation:
  1995. # https://people.freedesktop.org/~dbn/pkg-config-guide.html
  1996. # https://manpages.debian.org/unstable/pkgconf/pkg-config.1.en.html
  1997. # https://manpages.debian.org/unstable/pkg-config/pkg-config.1.en.html
  1998. # https://www.msys2.org/docs/pkgconfig/
  1999. configure_file(
  2000. "${PROJECT_SOURCE_DIR}/libcurl.pc.in"
  2001. "${PROJECT_BINARY_DIR}/libcurl.pc" @ONLY)
  2002. install(FILES "${PROJECT_BINARY_DIR}/libcurl.pc"
  2003. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  2004. # Install headers
  2005. install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/curl"
  2006. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  2007. FILES_MATCHING PATTERN "*.h")
  2008. include(CMakePackageConfigHelpers)
  2009. write_basic_package_version_file(
  2010. "${_version_config}"
  2011. VERSION ${_curl_version}
  2012. COMPATIBILITY SameMajorVersion)
  2013. file(READ "${_version_config}" _generated_version_config)
  2014. file(WRITE "${_version_config}" "
  2015. if(NOT PACKAGE_FIND_VERSION_RANGE AND PACKAGE_FIND_VERSION_MAJOR STREQUAL \"7\")
  2016. # Version 8 satisfies version 7... requirements
  2017. set(PACKAGE_FIND_VERSION_MAJOR 8)
  2018. set(PACKAGE_FIND_VERSION_COUNT 1)
  2019. endif()
  2020. ${_generated_version_config}")
  2021. # Consumed custom variables:
  2022. # LIB_SELECTED
  2023. # TARGETS_EXPORT_NAME
  2024. # USE_OPENSSL
  2025. # HAVE_LIBZ
  2026. configure_package_config_file("CMake/curl-config.cmake.in"
  2027. "${_project_config}"
  2028. INSTALL_DESTINATION ${_install_cmake_dir}
  2029. PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
  2030. if(CURL_ENABLE_EXPORT_TARGET)
  2031. install(EXPORT "${TARGETS_EXPORT_NAME}"
  2032. NAMESPACE "${PROJECT_NAME}::"
  2033. DESTINATION ${_install_cmake_dir})
  2034. endif()
  2035. install(FILES ${_version_config} ${_project_config}
  2036. DESTINATION ${_install_cmake_dir})
  2037. # Workaround for MSVS10 to avoid the Dialog Hell
  2038. # FIXME: This could be removed with future version of CMake.
  2039. if(MSVC_VERSION EQUAL 1600)
  2040. set(_curl_sln_filename "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  2041. if(EXISTS "${_curl_sln_filename}")
  2042. file(APPEND "${_curl_sln_filename}" "\n# This should be regenerated!\n")
  2043. endif()
  2044. endif()
  2045. if(NOT TARGET curl_uninstall)
  2046. configure_file(
  2047. "${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in"
  2048. "${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake"
  2049. IMMEDIATE @ONLY)
  2050. add_custom_target(curl_uninstall
  2051. COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake")
  2052. endif()
  2053. install(FILES "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl"
  2054. DESTINATION ${CMAKE_INSTALL_BINDIR}
  2055. PERMISSIONS
  2056. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  2057. GROUP_READ GROUP_EXECUTE
  2058. WORLD_READ WORLD_EXECUTE)
  2059. # The `-DEV` part is important
  2060. string(REGEX REPLACE "([0-9]+\.[0-9]+)\.([0-9]+.*)" "\\2" CPACK_PACKAGE_VERSION_PATCH "${_curl_version}")
  2061. set(CPACK_GENERATOR "TGZ")
  2062. include(CPack)
  2063. endif()
  2064. # Save build info for test runner to pick up and log
  2065. if(CMAKE_OSX_SYSROOT)
  2066. set(_cmake_sysroot ${CMAKE_OSX_SYSROOT})
  2067. elseif(CMAKE_SYSROOT)
  2068. set(_cmake_sysroot ${CMAKE_SYSROOT})
  2069. endif()
  2070. set(_buildinfo "\
  2071. buildinfo.configure.tool: cmake
  2072. buildinfo.configure.command: ${CMAKE_COMMAND}
  2073. buildinfo.configure.version: ${CMAKE_VERSION}
  2074. buildinfo.configure.args:${_cmake_args}
  2075. buildinfo.configure.generator: ${CMAKE_GENERATOR}
  2076. buildinfo.configure.make: ${CMAKE_MAKE_PROGRAM}
  2077. buildinfo.host.cpu: ${CMAKE_HOST_SYSTEM_PROCESSOR}
  2078. buildinfo.host.os: ${CMAKE_HOST_SYSTEM_NAME}
  2079. buildinfo.target.cpu: ${CMAKE_SYSTEM_PROCESSOR}
  2080. buildinfo.target.os: ${CMAKE_SYSTEM_NAME}
  2081. buildinfo.target.flags:${_target_flags}
  2082. buildinfo.compiler: ${CMAKE_C_COMPILER_ID}
  2083. buildinfo.compiler.version: ${CMAKE_C_COMPILER_VERSION}
  2084. buildinfo.sysroot: ${_cmake_sysroot}
  2085. ")
  2086. file(WRITE "${PROJECT_BINARY_DIR}/buildinfo.txt" "# This is a generated file. Do not edit.\n${_buildinfo}")
  2087. if(NOT "$ENV{CURL_BUILDINFO}$ENV{CURL_CI}$ENV{CI}" STREQUAL "")
  2088. message(STATUS "\n${_buildinfo}")
  2089. endif()