CMakeLists.txt 80 KB

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