CMakeLists.txt 78 KB

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