CMakeLists.txt 85 KB

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