CMakeLists.txt 76 KB

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