CMakeLists.txt 77 KB

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