CMakeLists.txt 76 KB

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