CMakeLists.txt 79 KB

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