CMakeLists.txt 85 KB

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