2
0

CMakeLists.txt 82 KB

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