CMakeLists.txt 85 KB

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