CMakeLists.txt 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760
  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
  27. # in the case that both CURL and its dependency are included as
  28. # sub-projects in a larger build using `FetchContent`. To support
  29. # that case, additional variables may be defined by the parent
  30. # project, ideally in the "extra" 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. #
  40. # For each of the above variables, if the variable is DEFINED (either
  41. # to ON or OFF), the symbol detection will be skipped. If the
  42. # variable is NOT DEFINED, the symbol detection will be performed.
  43. cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
  44. message(STATUS "Using CMake version ${CMAKE_VERSION}")
  45. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
  46. include(Utilities)
  47. include(Macros)
  48. include(CMakeDependentOption)
  49. include(CheckCCompilerFlag)
  50. project(CURL C)
  51. file(STRINGS ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS REGEX "#define LIBCURL_VERSION( |_NUM )")
  52. string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
  53. CURL_VERSION ${CURL_VERSION_H_CONTENTS})
  54. string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
  55. string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
  56. CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
  57. string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
  58. # Setup package meta-data
  59. # SET(PACKAGE "curl")
  60. message(STATUS "curl version=[${CURL_VERSION}]")
  61. # SET(PACKAGE_TARNAME "curl")
  62. # SET(PACKAGE_NAME "curl")
  63. # SET(PACKAGE_VERSION "-")
  64. # SET(PACKAGE_STRING "curl-")
  65. # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.se/mail/")
  66. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  67. if(CMAKE_C_COMPILER_TARGET)
  68. set(OS "\"${CMAKE_C_COMPILER_TARGET}\"")
  69. else()
  70. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  71. endif()
  72. include_directories(${CURL_SOURCE_DIR}/include)
  73. set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
  74. option(CURL_WERROR "Turn compiler warnings into errors" OFF)
  75. option(PICKY_COMPILER "Enable picky compiler options" ON)
  76. option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
  77. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  78. option(BUILD_STATIC_LIBS "Build static libraries" OFF)
  79. option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
  80. option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
  81. option(CURL_DISABLE_INSTALL "Set to ON to disable installation targets" OFF)
  82. if(WIN32)
  83. option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
  84. option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
  85. set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
  86. if(CURL_TARGET_WINDOWS_VERSION)
  87. add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
  88. list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
  89. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
  90. endif()
  91. if(ENABLE_UNICODE)
  92. add_definitions(-DUNICODE -D_UNICODE)
  93. if(MINGW)
  94. add_compile_options(-municode)
  95. endif()
  96. endif()
  97. endif()
  98. option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)
  99. cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
  100. ON "NOT ENABLE_ARES"
  101. OFF)
  102. option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
  103. option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
  104. include(PickyWarnings)
  105. if(ENABLE_DEBUG)
  106. # DEBUGBUILD will be defined only for Debug builds
  107. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
  108. set(ENABLE_CURLDEBUG ON)
  109. endif()
  110. if(ENABLE_CURLDEBUG)
  111. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
  112. endif()
  113. # For debug libs and exes, add "-d" postfix
  114. if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
  115. set(CMAKE_DEBUG_POSTFIX "-d")
  116. endif()
  117. set(LIB_STATIC "libcurl_static")
  118. set(LIB_SHARED "libcurl_shared")
  119. if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
  120. set(BUILD_STATIC_LIBS ON)
  121. endif()
  122. if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS)
  123. set(BUILD_STATIC_CURL ON)
  124. elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS)
  125. set(BUILD_STATIC_CURL OFF)
  126. endif()
  127. # lib flavour selected for curl tool
  128. if(BUILD_STATIC_CURL)
  129. set(LIB_SELECTED_FOR_EXE ${LIB_STATIC})
  130. else()
  131. set(LIB_SELECTED_FOR_EXE ${LIB_SHARED})
  132. endif()
  133. # lib flavour selected for example and test programs.
  134. if(BUILD_SHARED_LIBS)
  135. set(LIB_SELECTED ${LIB_SHARED})
  136. else()
  137. set(LIB_SELECTED ${LIB_STATIC})
  138. endif()
  139. # initialize CURL_LIBS
  140. set(CURL_LIBS "")
  141. if(ENABLE_ARES)
  142. set(USE_ARES 1)
  143. find_package(CARES REQUIRED)
  144. list(APPEND CURL_LIBS ${CARES_LIBRARY})
  145. endif()
  146. include(CurlSymbolHiding)
  147. option(CURL_ENABLE_EXPORT_TARGET "to enable cmake export target" ON)
  148. mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
  149. option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF)
  150. mark_as_advanced(CURL_DISABLE_ALTSVC)
  151. option(CURL_DISABLE_SRP "disables TLS-SRP support" OFF)
  152. mark_as_advanced(CURL_DISABLE_SRP)
  153. option(CURL_DISABLE_COOKIES "disables cookies support" OFF)
  154. mark_as_advanced(CURL_DISABLE_COOKIES)
  155. option(CURL_DISABLE_BASIC_AUTH "disables Basic authentication" OFF)
  156. mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
  157. option(CURL_DISABLE_BEARER_AUTH "disables Bearer authentication" OFF)
  158. mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
  159. option(CURL_DISABLE_DIGEST_AUTH "disables Digest authentication" OFF)
  160. mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
  161. option(CURL_DISABLE_KERBEROS_AUTH "disables Kerberos authentication" OFF)
  162. mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
  163. option(CURL_DISABLE_NEGOTIATE_AUTH "disables negotiate authentication" OFF)
  164. mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
  165. option(CURL_DISABLE_AWS "disables AWS-SIG4" OFF)
  166. mark_as_advanced(CURL_DISABLE_AWS)
  167. option(CURL_DISABLE_DICT "disables DICT" OFF)
  168. mark_as_advanced(CURL_DISABLE_DICT)
  169. option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF)
  170. mark_as_advanced(CURL_DISABLE_DOH)
  171. option(CURL_DISABLE_FILE "disables FILE" OFF)
  172. mark_as_advanced(CURL_DISABLE_FILE)
  173. cmake_dependent_option(CURL_DISABLE_FORM_API "disables form api" OFF
  174. "NOT CURL_DISABLE_MIME" ON)
  175. mark_as_advanced(CURL_DISABLE_FORM_API)
  176. option(CURL_DISABLE_FTP "disables FTP" OFF)
  177. mark_as_advanced(CURL_DISABLE_FTP)
  178. option(CURL_DISABLE_GETOPTIONS "disables curl_easy_options API for existing options to curl_easy_setopt" OFF)
  179. mark_as_advanced(CURL_DISABLE_GETOPTIONS)
  180. option(CURL_DISABLE_GOPHER "disables Gopher" OFF)
  181. mark_as_advanced(CURL_DISABLE_GOPHER)
  182. option(CURL_DISABLE_HEADERS_API "disables headers-api support" OFF)
  183. mark_as_advanced(CURL_DISABLE_HEADERS_API)
  184. option(CURL_DISABLE_HSTS "disables HSTS support" OFF)
  185. mark_as_advanced(CURL_DISABLE_HSTS)
  186. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  187. mark_as_advanced(CURL_DISABLE_HTTP)
  188. option(CURL_DISABLE_HTTP_AUTH "disables all HTTP authentication methods" OFF)
  189. mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
  190. option(CURL_DISABLE_IMAP "disables IMAP" OFF)
  191. mark_as_advanced(CURL_DISABLE_IMAP)
  192. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  193. mark_as_advanced(CURL_DISABLE_LDAP)
  194. option(CURL_DISABLE_LDAPS "disables LDAPS" OFF)
  195. mark_as_advanced(CURL_DISABLE_LDAPS)
  196. option(CURL_DISABLE_LIBCURL_OPTION "disables --libcurl option from the curl tool" OFF)
  197. mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
  198. option(CURL_DISABLE_MIME "disables MIME support" OFF)
  199. mark_as_advanced(CURL_DISABLE_MIME)
  200. option(CURL_DISABLE_MQTT "disables MQTT" OFF)
  201. mark_as_advanced(CURL_DISABLE_BINDLOCAL)
  202. option(CURL_DISABLE_BINDLOCAL "disables local binding support" OFF)
  203. mark_as_advanced(CURL_DISABLE_MQTT)
  204. option(CURL_DISABLE_NETRC "disables netrc parser" OFF)
  205. mark_as_advanced(CURL_DISABLE_NETRC)
  206. option(CURL_DISABLE_NTLM "disables NTLM support" OFF)
  207. mark_as_advanced(CURL_DISABLE_NTLM)
  208. option(CURL_DISABLE_PARSEDATE "disables date parsing" OFF)
  209. mark_as_advanced(CURL_DISABLE_PARSEDATE)
  210. option(CURL_DISABLE_POP3 "disables POP3" OFF)
  211. mark_as_advanced(CURL_DISABLE_POP3)
  212. option(CURL_DISABLE_PROGRESS_METER "disables built-in progress meter" OFF)
  213. mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
  214. option(CURL_DISABLE_PROXY "disables proxy support" OFF)
  215. mark_as_advanced(CURL_DISABLE_PROXY)
  216. option(CURL_DISABLE_RTSP "disables RTSP" OFF)
  217. mark_as_advanced(CURL_DISABLE_RTSP)
  218. option(CURL_DISABLE_SHUFFLE_DNS "disables shuffle DNS feature" OFF)
  219. mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
  220. option(CURL_DISABLE_SMB "disables SMB" OFF)
  221. mark_as_advanced(CURL_DISABLE_SMB)
  222. option(CURL_DISABLE_SMTP "disables SMTP" OFF)
  223. mark_as_advanced(CURL_DISABLE_SMTP)
  224. option(CURL_DISABLE_SOCKETPAIR "disables use of socketpair for curl_multi_poll" OFF)
  225. mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
  226. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  227. mark_as_advanced(CURL_DISABLE_TELNET)
  228. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  229. mark_as_advanced(CURL_DISABLE_TFTP)
  230. option(CURL_DISABLE_VERBOSE_STRINGS "disables verbose strings" OFF)
  231. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  232. # Corresponds to HTTP_ONLY in lib/curl_setup.h
  233. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  234. mark_as_advanced(HTTP_ONLY)
  235. if(HTTP_ONLY)
  236. set(CURL_DISABLE_DICT ON)
  237. set(CURL_DISABLE_FILE ON)
  238. set(CURL_DISABLE_FTP ON)
  239. set(CURL_DISABLE_GOPHER ON)
  240. set(CURL_DISABLE_IMAP ON)
  241. set(CURL_DISABLE_LDAP ON)
  242. set(CURL_DISABLE_LDAPS ON)
  243. set(CURL_DISABLE_MQTT ON)
  244. set(CURL_DISABLE_POP3 ON)
  245. set(CURL_DISABLE_RTSP ON)
  246. set(CURL_DISABLE_SMB ON)
  247. set(CURL_DISABLE_SMTP ON)
  248. set(CURL_DISABLE_TELNET ON)
  249. set(CURL_DISABLE_TFTP ON)
  250. endif()
  251. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
  252. mark_as_advanced(ENABLE_IPV6)
  253. if(ENABLE_IPV6 AND NOT WIN32)
  254. include(CheckStructHasMember)
  255. check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
  256. HAVE_SOCKADDR_IN6_SIN6_ADDR)
  257. check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
  258. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
  259. if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
  260. message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
  261. # Force the feature off as this name is used as guard macro...
  262. set(ENABLE_IPV6 OFF
  263. CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
  264. endif()
  265. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_ARES)
  266. set(use_core_foundation_and_core_services ON)
  267. find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
  268. if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
  269. message(FATAL_ERROR "SystemConfiguration framework not found")
  270. endif()
  271. list(APPEND CURL_LIBS "-framework SystemConfiguration")
  272. endif()
  273. endif()
  274. if(USE_MANUAL)
  275. #nroff is currently only used when USE_MANUAL is set, so we can prevent the warning of no *NROFF if USE_MANUAL is OFF (or not defined), by not even looking for NROFF..
  276. curl_nroff_check()
  277. endif()
  278. find_package(Perl)
  279. cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
  280. ON "NROFF_USEFUL;PERL_FOUND"
  281. OFF)
  282. if(ENABLE_MANUAL)
  283. set(USE_MANUAL ON)
  284. endif()
  285. if(CURL_STATIC_CRT)
  286. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  287. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  288. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  289. endif()
  290. # Disable warnings on Borland to avoid changing 3rd party code.
  291. if(BORLAND)
  292. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  293. endif()
  294. # If we are on AIX, do the _ALL_SOURCE magic
  295. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  296. set(_ALL_SOURCE 1)
  297. endif()
  298. # If we are on Haiku, make sure that the network library is brought in.
  299. if(${CMAKE_SYSTEM_NAME} MATCHES Haiku)
  300. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnetwork")
  301. endif()
  302. # Include all the necessary files for macros
  303. include(CMakePushCheckState)
  304. include(CheckFunctionExists)
  305. include(CheckIncludeFile)
  306. include(CheckIncludeFiles)
  307. include(CheckLibraryExists)
  308. include(CheckSymbolExists)
  309. include(CheckTypeSize)
  310. include(CheckCSourceCompiles)
  311. # On windows preload settings
  312. if(WIN32)
  313. set(HAVE_WINDOWS_H 1)
  314. set(HAVE_WS2TCPIP_H 1)
  315. set(HAVE_WINSOCK2_H 1)
  316. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  317. endif()
  318. if(ENABLE_THREADED_RESOLVER)
  319. if(WIN32)
  320. set(USE_THREADS_WIN32 ON)
  321. else()
  322. find_package(Threads REQUIRED)
  323. set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
  324. set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
  325. set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
  326. endif()
  327. endif()
  328. # Check for all needed libraries
  329. check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
  330. if(HAVE_LIBSOCKET)
  331. set(CURL_LIBS "socket;${CURL_LIBS}")
  332. endif()
  333. check_function_exists(gethostname HAVE_GETHOSTNAME)
  334. if(WIN32)
  335. list(APPEND CURL_LIBS "ws2_32" "bcrypt")
  336. if(USE_LIBRTMP)
  337. list(APPEND CURL_LIBS "winmm")
  338. endif()
  339. endif()
  340. # check SSL libraries
  341. option(CURL_ENABLE_SSL "Enable SSL support" ON)
  342. if(CURL_DEFAULT_SSL_BACKEND)
  343. set(valid_default_ssl_backend FALSE)
  344. endif()
  345. if(APPLE)
  346. cmake_dependent_option(CURL_USE_SECTRANSP "Enable Apple OS native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  347. endif()
  348. if(WIN32)
  349. cmake_dependent_option(CURL_USE_SCHANNEL "Enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  350. cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without OpenSSL" ON
  351. CURL_USE_SCHANNEL OFF)
  352. endif()
  353. cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  354. cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  355. cmake_dependent_option(CURL_USE_WOLFSSL "Enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  356. cmake_dependent_option(CURL_USE_GNUTLS "Enable GnuTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
  357. set(openssl_default ON)
  358. if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_WOLFSSL)
  359. set(openssl_default OFF)
  360. endif()
  361. cmake_dependent_option(CURL_USE_OPENSSL "Enable OpenSSL for SSL/TLS" ${openssl_default} CURL_ENABLE_SSL OFF)
  362. option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF)
  363. count_true(enabled_ssl_options_count
  364. CURL_USE_SCHANNEL
  365. CURL_USE_SECTRANSP
  366. CURL_USE_OPENSSL
  367. CURL_USE_MBEDTLS
  368. CURL_USE_BEARSSL
  369. CURL_USE_WOLFSSL
  370. )
  371. if(enabled_ssl_options_count GREATER "1")
  372. set(CURL_WITH_MULTI_SSL ON)
  373. endif()
  374. if(CURL_USE_SCHANNEL)
  375. set(SSL_ENABLED ON)
  376. set(USE_SCHANNEL ON) # Windows native SSL/TLS support
  377. set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI
  378. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "schannel")
  379. set(valid_default_ssl_backend TRUE)
  380. endif()
  381. endif()
  382. if(CURL_WINDOWS_SSPI)
  383. set(USE_WINDOWS_SSPI ON)
  384. endif()
  385. if(CURL_USE_SECTRANSP)
  386. set(use_core_foundation_and_core_services ON)
  387. find_library(SECURITY_FRAMEWORK "Security")
  388. if(NOT SECURITY_FRAMEWORK)
  389. message(FATAL_ERROR "Security framework not found")
  390. endif()
  391. set(SSL_ENABLED ON)
  392. set(USE_SECTRANSP ON)
  393. list(APPEND CURL_LIBS "-framework Security")
  394. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport")
  395. set(valid_default_ssl_backend TRUE)
  396. endif()
  397. endif()
  398. if(use_core_foundation_and_core_services)
  399. find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
  400. find_library(CORESERVICES_FRAMEWORK "CoreServices")
  401. if(NOT COREFOUNDATION_FRAMEWORK)
  402. message(FATAL_ERROR "CoreFoundation framework not found")
  403. endif()
  404. if(NOT CORESERVICES_FRAMEWORK)
  405. message(FATAL_ERROR "CoreServices framework not found")
  406. endif()
  407. list(APPEND CURL_LIBS "-framework CoreFoundation -framework CoreServices")
  408. endif()
  409. if(CURL_USE_OPENSSL)
  410. find_package(OpenSSL REQUIRED)
  411. set(SSL_ENABLED ON)
  412. set(USE_OPENSSL ON)
  413. # Depend on OpenSSL via imported targets if supported by the running
  414. # version of CMake. This allows our dependents to get our dependencies
  415. # transitively.
  416. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  417. list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
  418. else()
  419. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  420. include_directories(${OPENSSL_INCLUDE_DIR})
  421. endif()
  422. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl")
  423. set(valid_default_ssl_backend TRUE)
  424. endif()
  425. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  426. if(NOT DEFINED HAVE_BORINGSSL)
  427. check_symbol_exists(OPENSSL_IS_BORINGSSL "openssl/base.h" HAVE_BORINGSSL)
  428. endif()
  429. if(NOT DEFINED HAVE_AWSLC)
  430. check_symbol_exists(OPENSSL_IS_AWSLC "openssl/base.h" HAVE_AWSLC)
  431. endif()
  432. endif()
  433. if(CURL_USE_MBEDTLS)
  434. find_package(MbedTLS REQUIRED)
  435. set(SSL_ENABLED ON)
  436. set(USE_MBEDTLS ON)
  437. list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
  438. include_directories(${MBEDTLS_INCLUDE_DIRS})
  439. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "mbedtls")
  440. set(valid_default_ssl_backend TRUE)
  441. endif()
  442. endif()
  443. if(CURL_USE_BEARSSL)
  444. find_package(BearSSL REQUIRED)
  445. set(SSL_ENABLED ON)
  446. set(USE_BEARSSL ON)
  447. list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
  448. include_directories(${BEARSSL_INCLUDE_DIRS})
  449. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "bearssl")
  450. set(valid_default_ssl_backend TRUE)
  451. endif()
  452. endif()
  453. if(CURL_USE_WOLFSSL)
  454. find_package(WolfSSL REQUIRED)
  455. set(SSL_ENABLED ON)
  456. set(USE_WOLFSSL ON)
  457. list(APPEND CURL_LIBS ${WolfSSL_LIBRARIES})
  458. include_directories(${WolfSSL_INCLUDE_DIRS})
  459. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "wolfssl")
  460. set(valid_default_ssl_backend TRUE)
  461. endif()
  462. endif()
  463. if(CURL_USE_GNUTLS)
  464. find_package(GnuTLS REQUIRED)
  465. set(SSL_ENABLED ON)
  466. set(USE_GNUTLS ON)
  467. list(APPEND CURL_LIBS ${GNUTLS_LIBRARIES} "nettle")
  468. include_directories(${GNUTLS_INCLUDE_DIRS})
  469. if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "gnutls")
  470. set(valid_default_ssl_backend TRUE)
  471. endif()
  472. if(NOT DEFINED HAVE_GNUTLS_SRP AND NOT CURL_DISABLE_SRP)
  473. cmake_push_check_state()
  474. set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
  475. set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
  476. check_symbol_exists(gnutls_srp_verifier "gnutls/gnutls.h" HAVE_GNUTLS_SRP)
  477. cmake_pop_check_state()
  478. endif()
  479. endif()
  480. if(CURL_DEFAULT_SSL_BACKEND AND NOT valid_default_ssl_backend)
  481. message(FATAL_ERROR "CURL_DEFAULT_SSL_BACKEND '${CURL_DEFAULT_SSL_BACKEND}' not enabled.")
  482. endif()
  483. # Keep ZLIB detection after TLS detection,
  484. # and before calling openssl_check_symbol_exists().
  485. set(HAVE_LIBZ OFF)
  486. set(USE_ZLIB OFF)
  487. optional_dependency(ZLIB)
  488. if(ZLIB_FOUND)
  489. set(HAVE_LIBZ ON)
  490. set(USE_ZLIB ON)
  491. # Depend on ZLIB via imported targets if supported by the running
  492. # version of CMake. This allows our dependents to get our dependencies
  493. # transitively.
  494. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  495. list(APPEND CURL_LIBS ZLIB::ZLIB)
  496. else()
  497. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  498. include_directories(${ZLIB_INCLUDE_DIRS})
  499. endif()
  500. list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
  501. endif()
  502. option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
  503. set(HAVE_BROTLI OFF)
  504. if(CURL_BROTLI)
  505. find_package(Brotli REQUIRED)
  506. if(BROTLI_FOUND)
  507. set(HAVE_BROTLI ON)
  508. set(CURL_LIBS "${BROTLI_LIBRARIES};${CURL_LIBS}") # For 'ld' linker. Emulate `list(PREPEND ...)` to stay compatible with <v3.15 CMake.
  509. list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
  510. include_directories(${BROTLI_INCLUDE_DIRS})
  511. list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
  512. endif()
  513. endif()
  514. option(CURL_ZSTD "Set to ON to enable building curl with zstd support." OFF)
  515. set(HAVE_ZSTD OFF)
  516. if(CURL_ZSTD)
  517. find_package(Zstd REQUIRED)
  518. if(Zstd_FOUND AND NOT Zstd_VERSION VERSION_LESS "1.0.0")
  519. set(HAVE_ZSTD ON)
  520. list(APPEND CURL_LIBS ${Zstd_LIBRARIES})
  521. include_directories(${Zstd_INCLUDE_DIRS})
  522. else()
  523. message(WARNING "zstd v1.0.0 or newer is required, disabling zstd support.")
  524. endif()
  525. endif()
  526. # Check symbol in OpenSSL-like TLS backends.
  527. macro(openssl_check_symbol_exists SYMBOL FILES VARIABLE)
  528. cmake_push_check_state()
  529. if(USE_OPENSSL)
  530. set(CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
  531. set(CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}")
  532. if(HAVE_LIBZ)
  533. list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
  534. endif()
  535. if(WIN32)
  536. list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
  537. list(APPEND CMAKE_REQUIRED_LIBRARIES "bcrypt") # for OpenSSL/LibreSSL
  538. endif()
  539. elseif(USE_WOLFSSL)
  540. set(CMAKE_REQUIRED_INCLUDES "${WolfSSL_INCLUDE_DIRS}")
  541. set(CMAKE_REQUIRED_LIBRARIES "${WolfSSL_LIBRARIES}")
  542. if(HAVE_LIBZ)
  543. list(APPEND CMAKE_REQUIRED_INCLUDES "${ZLIB_INCLUDE_DIRS}") # Public wolfSSL headers require zlib headers
  544. list(APPEND CMAKE_REQUIRED_LIBRARIES "${ZLIB_LIBRARIES}")
  545. endif()
  546. if(WIN32)
  547. list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32" "crypt32")
  548. endif()
  549. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_UINTPTR_T) # to pull in stdint.h (as of wolfSSL v5.5.4)
  550. endif()
  551. check_symbol_exists("${SYMBOL}" "${FILES}" "${VARIABLE}")
  552. cmake_pop_check_state()
  553. endmacro()
  554. # Ensure that the OpenSSL fork actually supports QUIC.
  555. macro(openssl_check_quic)
  556. if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD)
  557. if(USE_OPENSSL)
  558. openssl_check_symbol_exists(SSL_CTX_set_quic_method "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD)
  559. elseif(USE_WOLFSSL)
  560. openssl_check_symbol_exists(wolfSSL_set_quic_method "wolfssl/options.h;wolfssl/openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD)
  561. endif()
  562. endif()
  563. if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD)
  564. message(FATAL_ERROR "QUIC support is missing in OpenSSL fork. Try setting -DOPENSSL_ROOT_DIR")
  565. endif()
  566. endmacro()
  567. if(USE_OPENSSL OR USE_WOLFSSL)
  568. if(NOT DEFINED HAVE_SSL_SET0_WBIO)
  569. openssl_check_symbol_exists(SSL_set0_wbio "openssl/ssl.h" HAVE_SSL_SET0_WBIO)
  570. endif()
  571. if(NOT DEFINED HAVE_OPENSSL_SRP AND NOT CURL_DISABLE_SRP)
  572. openssl_check_symbol_exists(SSL_CTX_set_srp_username "openssl/ssl.h" HAVE_OPENSSL_SRP)
  573. endif()
  574. endif()
  575. option(USE_NGHTTP2 "Use nghttp2 library" OFF)
  576. if(USE_NGHTTP2)
  577. find_package(NGHTTP2 REQUIRED)
  578. include_directories(${NGHTTP2_INCLUDE_DIRS})
  579. list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
  580. endif()
  581. option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF)
  582. if(USE_NGTCP2)
  583. if(USE_OPENSSL OR USE_WOLFSSL)
  584. if(USE_WOLFSSL)
  585. find_package(NGTCP2 REQUIRED wolfSSL)
  586. elseif(HAVE_BORINGSSL OR HAVE_AWSLC)
  587. find_package(NGTCP2 REQUIRED BoringSSL)
  588. else()
  589. find_package(NGTCP2 REQUIRED quictls)
  590. endif()
  591. openssl_check_quic()
  592. elseif(USE_GNUTLS)
  593. find_package(NGTCP2 REQUIRED GnuTLS)
  594. else()
  595. message(FATAL_ERROR "ngtcp2 requires OpenSSL, wolfSSL or GnuTLS")
  596. endif()
  597. set(USE_NGTCP2 ON)
  598. include_directories(${NGTCP2_INCLUDE_DIRS})
  599. list(APPEND CURL_LIBS ${NGTCP2_LIBRARIES})
  600. find_package(NGHTTP3 REQUIRED)
  601. set(USE_NGHTTP3 ON)
  602. include_directories(${NGHTTP3_INCLUDE_DIRS})
  603. list(APPEND CURL_LIBS ${NGHTTP3_LIBRARIES})
  604. endif()
  605. option(USE_QUICHE "Use quiche library for HTTP/3 support" OFF)
  606. if(USE_QUICHE)
  607. if(USE_NGTCP2)
  608. message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
  609. endif()
  610. find_package(QUICHE REQUIRED)
  611. if(NOT HAVE_BORINGSSL)
  612. message(FATAL_ERROR "quiche requires BoringSSL")
  613. endif()
  614. openssl_check_quic()
  615. set(USE_QUICHE ON)
  616. include_directories(${QUICHE_INCLUDE_DIRS})
  617. list(APPEND CURL_LIBS ${QUICHE_LIBRARIES})
  618. if(NOT DEFINED HAVE_QUICHE_CONN_SET_QLOG_FD)
  619. cmake_push_check_state()
  620. set(CMAKE_REQUIRED_INCLUDES "${QUICHE_INCLUDE_DIRS}")
  621. set(CMAKE_REQUIRED_LIBRARIES "${QUICHE_LIBRARIES}")
  622. check_symbol_exists(quiche_conn_set_qlog_fd "quiche.h" HAVE_QUICHE_CONN_SET_QLOG_FD)
  623. cmake_pop_check_state()
  624. endif()
  625. endif()
  626. option(USE_MSH3 "Use msquic library for HTTP/3 support" OFF)
  627. if(USE_MSH3)
  628. if(USE_NGTCP2 OR USE_QUICHE)
  629. message(FATAL_ERROR "Only one HTTP/3 backend can be selected!")
  630. endif()
  631. set(USE_MSH3 ON)
  632. include_directories(${MSH3_INCLUDE_DIRS})
  633. list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
  634. endif()
  635. if(NOT CURL_DISABLE_SRP AND (HAVE_GNUTLS_SRP OR HAVE_OPENSSL_SRP))
  636. set(USE_TLS_SRP 1)
  637. endif()
  638. if(NOT CURL_DISABLE_LDAP)
  639. if(WIN32)
  640. option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
  641. if(USE_WIN32_LDAP)
  642. list(APPEND CURL_LIBS "wldap32")
  643. if(NOT CURL_DISABLE_LDAPS)
  644. set(HAVE_LDAP_SSL ON)
  645. endif()
  646. endif()
  647. endif()
  648. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  649. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  650. # Now that we know, we're not using windows LDAP...
  651. if(NOT USE_WIN32_LDAP)
  652. # Check for LDAP
  653. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  654. check_library_exists("${CMAKE_LDAP_LIB}" "ldap_init" "" HAVE_LIBLDAP)
  655. if(HAVE_LIBLDAP)
  656. check_library_exists("${CMAKE_LDAP_LIB};${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
  657. else()
  658. check_library_exists("${CMAKE_LBER_LIB}" "ber_init" "" HAVE_LIBLBER)
  659. endif()
  660. set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
  661. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  662. if(CMAKE_LDAP_INCLUDE_DIR)
  663. list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  664. endif()
  665. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  666. check_include_file_concat("lber.h" HAVE_LBER_H)
  667. if(NOT HAVE_LDAP_H)
  668. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  669. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  670. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  671. elseif(NOT HAVE_LIBLDAP)
  672. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  673. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  674. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  675. else()
  676. if(CMAKE_LDAP_INCLUDE_DIR)
  677. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  678. endif()
  679. set(NEED_LBER_H ON)
  680. set(_HEADER_LIST)
  681. if(HAVE_WINDOWS_H)
  682. list(APPEND _HEADER_LIST "windows.h")
  683. endif()
  684. if(HAVE_SYS_TYPES_H)
  685. list(APPEND _HEADER_LIST "sys/types.h")
  686. endif()
  687. list(APPEND _HEADER_LIST "ldap.h")
  688. set(_INCLUDE_STRING "")
  689. foreach(_HEADER ${_HEADER_LIST})
  690. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  691. endforeach()
  692. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DLDAP_DEPRECATED=1)
  693. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  694. set(CURL_LIBS "${CMAKE_LDAP_LIB};${CURL_LIBS}")
  695. if(HAVE_LIBLBER)
  696. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  697. set(CURL_LIBS "${CMAKE_LBER_LIB};${CURL_LIBS}")
  698. endif()
  699. check_c_source_compiles("
  700. ${_INCLUDE_STRING}
  701. int main(int argc, char ** argv)
  702. {
  703. BerValue *bvp = NULL;
  704. BerElement *bep = ber_init(bvp);
  705. ber_free(bep, 1);
  706. return 0;
  707. }" NOT_NEED_LBER_H)
  708. if(NOT_NEED_LBER_H)
  709. set(NEED_LBER_H OFF)
  710. else()
  711. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  712. endif()
  713. check_function_exists(ldap_url_parse HAVE_LDAP_URL_PARSE)
  714. check_function_exists(ldap_init_fd HAVE_LDAP_INIT_FD)
  715. unset(CMAKE_REQUIRED_LIBRARIES)
  716. check_include_file("ldap_ssl.h" HAVE_LDAP_SSL_H)
  717. if(HAVE_LDAP_INIT_FD)
  718. set(USE_OPENLDAP ON)
  719. add_definitions("-DLDAP_DEPRECATED=1")
  720. endif()
  721. if(NOT CURL_DISABLE_LDAPS)
  722. set(HAVE_LDAP_SSL ON)
  723. endif()
  724. endif()
  725. endif()
  726. endif()
  727. # No ldap, no ldaps.
  728. if(CURL_DISABLE_LDAP)
  729. if(NOT CURL_DISABLE_LDAPS)
  730. message(STATUS "LDAP needs to be enabled to support LDAPS")
  731. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  732. endif()
  733. endif()
  734. # Check for idn2
  735. option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
  736. if(USE_LIBIDN2)
  737. check_library_exists("idn2" "idn2_lookup_ul" "" HAVE_LIBIDN2)
  738. if(HAVE_LIBIDN2)
  739. set(CURL_LIBS "idn2;${CURL_LIBS}")
  740. check_include_file_concat("idn2.h" HAVE_IDN2_H)
  741. endif()
  742. else()
  743. set(HAVE_LIBIDN2 OFF)
  744. endif()
  745. if(WIN32)
  746. option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF)
  747. if(USE_WIN32_IDN)
  748. list(APPEND CURL_LIBS "normaliz")
  749. endif()
  750. endif()
  751. #libpsl
  752. option(CURL_USE_LIBPSL "Use libPSL" ON)
  753. mark_as_advanced(CURL_USE_LIBPSL)
  754. set(USE_LIBPSL OFF)
  755. if(CURL_USE_LIBPSL)
  756. find_package(LibPSL)
  757. if(LIBPSL_FOUND)
  758. list(APPEND CURL_LIBS ${LIBPSL_LIBRARY})
  759. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIR}")
  760. include_directories("${LIBPSL_INCLUDE_DIR}")
  761. set(USE_LIBPSL ON)
  762. endif()
  763. endif()
  764. #libSSH2
  765. option(CURL_USE_LIBSSH2 "Use libSSH2" ON)
  766. mark_as_advanced(CURL_USE_LIBSSH2)
  767. set(USE_LIBSSH2 OFF)
  768. if(CURL_USE_LIBSSH2)
  769. find_package(LibSSH2)
  770. if(LIBSSH2_FOUND)
  771. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  772. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  773. include_directories("${LIBSSH2_INCLUDE_DIR}")
  774. set(USE_LIBSSH2 ON)
  775. endif()
  776. endif()
  777. # libssh
  778. option(CURL_USE_LIBSSH "Use libSSH" OFF)
  779. mark_as_advanced(CURL_USE_LIBSSH)
  780. if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
  781. find_package(libssh CONFIG)
  782. if(libssh_FOUND)
  783. message(STATUS "Found libssh ${libssh_VERSION}")
  784. # Use imported target for include and library paths.
  785. list(APPEND CURL_LIBS ssh)
  786. set(USE_LIBSSH ON)
  787. endif()
  788. endif()
  789. option(CURL_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
  790. mark_as_advanced(CURL_USE_GSSAPI)
  791. if(CURL_USE_GSSAPI)
  792. find_package(GSS)
  793. set(HAVE_GSSAPI ${GSS_FOUND})
  794. if(GSS_FOUND)
  795. message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
  796. list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
  797. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  798. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  799. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  800. if(GSS_FLAVOUR STREQUAL "Heimdal")
  801. set(HAVE_GSSHEIMDAL ON)
  802. else() # MIT
  803. set(HAVE_GSSMIT ON)
  804. set(_INCLUDE_LIST "")
  805. if(HAVE_GSSAPI_GSSAPI_H)
  806. list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
  807. endif()
  808. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  809. list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
  810. endif()
  811. if(HAVE_GSSAPI_GSSAPI_KRB5_H)
  812. list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
  813. endif()
  814. string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
  815. string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
  816. foreach(_dir ${GSS_LINK_DIRECTORIES})
  817. set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
  818. endforeach()
  819. if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  820. set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
  821. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  822. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  823. unset(CMAKE_REQUIRED_LIBRARIES)
  824. endif()
  825. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  826. set(HAVE_OLD_GSSMIT ON)
  827. endif()
  828. endif()
  829. include_directories(${GSS_INCLUDE_DIR})
  830. link_directories(${GSS_LINK_DIRECTORIES})
  831. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
  832. string(REPLACE ";" " " GSS_LINKER_FLAGS "${GSS_LINKER_FLAGS}")
  833. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  834. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  835. set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  836. list(APPEND CURL_LIBS ${GSS_LIBRARIES})
  837. else()
  838. message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
  839. endif()
  840. endif()
  841. option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
  842. if(ENABLE_UNIX_SOCKETS)
  843. include(CheckStructHasMember)
  844. if(WIN32)
  845. set(USE_UNIX_SOCKETS ON)
  846. else()
  847. check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
  848. endif()
  849. else()
  850. unset(USE_UNIX_SOCKETS CACHE)
  851. endif()
  852. #
  853. # CA handling
  854. #
  855. set(CURL_CA_BUNDLE "auto" CACHE STRING
  856. "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  857. set(CURL_CA_FALLBACK OFF CACHE BOOL
  858. "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
  859. set(CURL_CA_PATH "auto" CACHE STRING
  860. "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  861. if("${CURL_CA_BUNDLE}" STREQUAL "")
  862. message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
  863. elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
  864. unset(CURL_CA_BUNDLE CACHE)
  865. elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
  866. unset(CURL_CA_BUNDLE CACHE)
  867. if(NOT CMAKE_CROSSCOMPILING)
  868. set(CURL_CA_BUNDLE_AUTODETECT TRUE)
  869. endif()
  870. else()
  871. set(CURL_CA_BUNDLE_SET TRUE)
  872. endif()
  873. if("${CURL_CA_PATH}" STREQUAL "")
  874. message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
  875. elseif("${CURL_CA_PATH}" STREQUAL "none")
  876. unset(CURL_CA_PATH CACHE)
  877. elseif("${CURL_CA_PATH}" STREQUAL "auto")
  878. unset(CURL_CA_PATH CACHE)
  879. if(NOT CMAKE_CROSSCOMPILING)
  880. set(CURL_CA_PATH_AUTODETECT TRUE)
  881. endif()
  882. else()
  883. set(CURL_CA_PATH_SET TRUE)
  884. endif()
  885. if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
  886. # Skip autodetection of unset CA path because CA bundle is set explicitly
  887. elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
  888. # Skip autodetection of unset CA bundle because CA path is set explicitly
  889. elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
  890. # first try autodetecting a CA bundle, then a CA path
  891. if(CURL_CA_BUNDLE_AUTODETECT)
  892. set(SEARCH_CA_BUNDLE_PATHS
  893. /etc/ssl/certs/ca-certificates.crt
  894. /etc/pki/tls/certs/ca-bundle.crt
  895. /usr/share/ssl/certs/ca-bundle.crt
  896. /usr/local/share/certs/ca-root-nss.crt
  897. /etc/ssl/cert.pem)
  898. foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
  899. if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
  900. message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
  901. set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}" CACHE STRING
  902. "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  903. set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  904. break()
  905. endif()
  906. endforeach()
  907. endif()
  908. if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
  909. if(EXISTS "/etc/ssl/certs")
  910. set(CURL_CA_PATH "/etc/ssl/certs" CACHE STRING
  911. "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  912. set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  913. endif()
  914. endif()
  915. endif()
  916. if(CURL_CA_PATH_SET AND
  917. NOT USE_OPENSSL AND
  918. NOT USE_WOLFSSL AND
  919. NOT USE_GNUTLS AND
  920. NOT USE_MBEDTLS)
  921. message(STATUS
  922. "CA path only supported by OpenSSL, wolfSSL, GnuTLS or mbedTLS. "
  923. "Set CURL_CA_PATH=none or enable one of those TLS backends.")
  924. endif()
  925. # Check for header files
  926. if(WIN32)
  927. check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
  928. check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
  929. check_include_file_concat("windows.h" HAVE_WINDOWS_H)
  930. endif()
  931. if(WIN32)
  932. # detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
  933. curl_internal_test(HAVE_WIN32_WINNT)
  934. if(HAVE_WIN32_WINNT)
  935. string(REGEX MATCH ".*_WIN32_WINNT=0x[0-9a-fA-F]+" OUTPUT "${OUTPUT}")
  936. string(REGEX REPLACE ".*_WIN32_WINNT=" "" OUTPUT "${OUTPUT}")
  937. string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" OUTPUT "${OUTPUT}") # pad to 4 digits
  938. string(TOLOWER "${OUTPUT}" HAVE_WIN32_WINNT)
  939. message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
  940. endif()
  941. # avoid storing HAVE_WIN32_WINNT in CMake cache
  942. unset(HAVE_WIN32_WINNT CACHE)
  943. if(HAVE_WIN32_WINNT)
  944. if(HAVE_WIN32_WINNT STRLESS "0x0501")
  945. # Windows XP is required for freeaddrinfo, getaddrinfo
  946. message(FATAL_ERROR "Building for Windows XP or newer is required.")
  947. endif()
  948. # pre-fill detection results based on target OS version
  949. if(MINGW OR MSVC)
  950. if(HAVE_WIN32_WINNT STRLESS "0x0600")
  951. set(HAVE_INET_NTOP 0)
  952. set(HAVE_INET_PTON 0)
  953. else() # Windows Vista or newer
  954. set(HAVE_INET_NTOP 1)
  955. set(HAVE_INET_PTON 1)
  956. endif()
  957. unset(HAVE_INET_NTOP CACHE)
  958. unset(HAVE_INET_PTON CACHE)
  959. endif()
  960. endif()
  961. endif()
  962. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  963. check_include_file_concat("sys/wait.h" HAVE_SYS_WAIT_H)
  964. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  965. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  966. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  967. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  968. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  969. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  970. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  971. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  972. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  973. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  974. check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
  975. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  976. check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
  977. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  978. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  979. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  980. check_include_file_concat("io.h" HAVE_IO_H)
  981. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  982. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  983. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  984. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  985. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  986. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
  987. check_include_file_concat("netinet/udp.h" HAVE_NETINET_UDP_H)
  988. check_include_file("linux/tcp.h" HAVE_LINUX_TCP_H)
  989. check_include_file_concat("poll.h" HAVE_POLL_H)
  990. check_include_file_concat("pwd.h" HAVE_PWD_H)
  991. check_include_file_concat("stdatomic.h" HAVE_STDATOMIC_H)
  992. check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
  993. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  994. check_include_file_concat("stropts.h" HAVE_STROPTS_H)
  995. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  996. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  997. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  998. check_include_file_concat("utime.h" HAVE_UTIME_H)
  999. check_type_size(size_t SIZEOF_SIZE_T)
  1000. check_type_size(ssize_t SIZEOF_SSIZE_T)
  1001. check_type_size("long long" SIZEOF_LONG_LONG)
  1002. check_type_size("long" SIZEOF_LONG)
  1003. check_type_size("int" SIZEOF_INT)
  1004. check_type_size("__int64" SIZEOF___INT64)
  1005. check_type_size("time_t" SIZEOF_TIME_T)
  1006. check_type_size("suseconds_t" SIZEOF_SUSECONDS_T)
  1007. if(NOT HAVE_SIZEOF_SSIZE_T)
  1008. if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  1009. set(ssize_t long)
  1010. endif()
  1011. if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  1012. set(ssize_t __int64)
  1013. endif()
  1014. endif()
  1015. # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
  1016. if(SIZEOF_LONG_LONG)
  1017. set(HAVE_LONGLONG 1)
  1018. endif()
  1019. if(SIZEOF_SUSECONDS_T)
  1020. set(HAVE_SUSECONDS_T 1)
  1021. endif()
  1022. if(NOT CMAKE_CROSSCOMPILING)
  1023. find_file(RANDOM_FILE urandom /dev)
  1024. mark_as_advanced(RANDOM_FILE)
  1025. endif()
  1026. # Check for some functions that are used
  1027. if(WIN32)
  1028. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  1029. elseif(HAVE_LIBSOCKET)
  1030. set(CMAKE_REQUIRED_LIBRARIES socket)
  1031. endif()
  1032. check_symbol_exists(fnmatch "${CURL_INCLUDES};fnmatch.h" HAVE_FNMATCH)
  1033. check_symbol_exists(basename "${CURL_INCLUDES};string.h" HAVE_BASENAME)
  1034. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  1035. check_symbol_exists(sched_yield "${CURL_INCLUDES};sched.h" HAVE_SCHED_YIELD)
  1036. check_symbol_exists(socketpair "${CURL_INCLUDES}" HAVE_SOCKETPAIR)
  1037. check_symbol_exists(recv "${CURL_INCLUDES}" HAVE_RECV)
  1038. check_symbol_exists(send "${CURL_INCLUDES}" HAVE_SEND)
  1039. check_symbol_exists(sendmsg "${CURL_INCLUDES}" HAVE_SENDMSG)
  1040. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  1041. check_symbol_exists(strdup "${CURL_INCLUDES};string.h" HAVE_STRDUP)
  1042. check_symbol_exists(strtok_r "${CURL_INCLUDES};string.h" HAVE_STRTOK_R)
  1043. check_symbol_exists(strcasecmp "${CURL_INCLUDES};string.h" HAVE_STRCASECMP)
  1044. check_symbol_exists(stricmp "${CURL_INCLUDES};string.h" HAVE_STRICMP)
  1045. check_symbol_exists(strcmpi "${CURL_INCLUDES};string.h" HAVE_STRCMPI)
  1046. check_symbol_exists(memrchr "${CURL_INCLUDES};string.h" HAVE_MEMRCHR)
  1047. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  1048. check_symbol_exists(arc4random "${CURL_INCLUDES};stdlib.h" HAVE_ARC4RANDOM)
  1049. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  1050. check_symbol_exists(getppid "${CURL_INCLUDES}" HAVE_GETPPID)
  1051. check_symbol_exists(utimes "${CURL_INCLUDES}" HAVE_UTIMES)
  1052. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  1053. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  1054. check_symbol_exists(sigsetjmp "${CURL_INCLUDES};setjmp.h" HAVE_SIGSETJMP)
  1055. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  1056. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  1057. check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
  1058. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  1059. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  1060. check_symbol_exists(gmtime_r "${CURL_INCLUDES};stdlib.h;time.h" HAVE_GMTIME_R)
  1061. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  1062. check_symbol_exists(signal "${CURL_INCLUDES};signal.h" HAVE_SIGNAL)
  1063. check_symbol_exists(strtoll "${CURL_INCLUDES};stdlib.h" HAVE_STRTOLL)
  1064. check_symbol_exists(strerror_r "${CURL_INCLUDES};stdlib.h;string.h" HAVE_STRERROR_R)
  1065. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  1066. check_symbol_exists(siginterrupt "${CURL_INCLUDES};signal.h" HAVE_SIGINTERRUPT)
  1067. check_symbol_exists(getaddrinfo "${CURL_INCLUDES};stdlib.h;string.h" HAVE_GETADDRINFO)
  1068. check_symbol_exists(getifaddrs "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS)
  1069. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  1070. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  1071. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  1072. check_symbol_exists(fseeko "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
  1073. check_symbol_exists(_fseeki64 "${CURL_INCLUDES};stdio.h" HAVE__FSEEKI64)
  1074. check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
  1075. check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
  1076. check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
  1077. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  1078. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  1079. check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
  1080. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  1081. if(HAVE_FSEEKO)
  1082. set(HAVE_DECL_FSEEKO 1)
  1083. endif()
  1084. if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900))
  1085. # earlier MSVC compilers had faulty snprintf implementations
  1086. check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
  1087. endif()
  1088. check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
  1089. check_symbol_exists(inet_ntop "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP)
  1090. if(MSVC AND (MSVC_VERSION LESS_EQUAL 1600))
  1091. set(HAVE_INET_NTOP OFF)
  1092. endif()
  1093. check_symbol_exists(inet_pton "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON)
  1094. check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
  1095. if(HAVE_FSETXATTR)
  1096. foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
  1097. curl_internal_test(${CURL_TEST})
  1098. endforeach()
  1099. endif()
  1100. set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
  1101. check_type_size("sa_family_t" SIZEOF_SA_FAMILY_T)
  1102. set(HAVE_SA_FAMILY_T ${HAVE_SIZEOF_SA_FAMILY_T})
  1103. set(CMAKE_EXTRA_INCLUDE_FILES "")
  1104. if(WIN32)
  1105. set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h")
  1106. check_type_size("ADDRESS_FAMILY" SIZEOF_ADDRESS_FAMILY)
  1107. set(HAVE_ADDRESS_FAMILY ${HAVE_SIZEOF_ADDRESS_FAMILY})
  1108. set(CMAKE_EXTRA_INCLUDE_FILES "")
  1109. endif()
  1110. # Do curl specific tests
  1111. foreach(CURL_TEST
  1112. HAVE_FCNTL_O_NONBLOCK
  1113. HAVE_IOCTLSOCKET
  1114. HAVE_IOCTLSOCKET_CAMEL
  1115. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  1116. HAVE_IOCTLSOCKET_FIONBIO
  1117. HAVE_IOCTL_FIONBIO
  1118. HAVE_IOCTL_SIOCGIFADDR
  1119. HAVE_SETSOCKOPT_SO_NONBLOCK
  1120. HAVE_O_NONBLOCK
  1121. HAVE_GETHOSTBYNAME_R_3
  1122. HAVE_GETHOSTBYNAME_R_5
  1123. HAVE_GETHOSTBYNAME_R_6
  1124. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  1125. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  1126. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  1127. HAVE_IN_ADDR_T
  1128. HAVE_BOOL_T
  1129. STDC_HEADERS
  1130. HAVE_FILE_OFFSET_BITS
  1131. HAVE_ATOMIC
  1132. )
  1133. curl_internal_test(${CURL_TEST})
  1134. endforeach()
  1135. if(HAVE_FILE_OFFSET_BITS)
  1136. set(_FILE_OFFSET_BITS 64)
  1137. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  1138. endif()
  1139. check_type_size("off_t" SIZEOF_OFF_T)
  1140. # include this header to get the type
  1141. set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
  1142. set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
  1143. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  1144. set(CMAKE_EXTRA_INCLUDE_FILES "curl/curl.h")
  1145. check_type_size("curl_socket_t" SIZEOF_CURL_SOCKET_T)
  1146. set(CMAKE_EXTRA_INCLUDE_FILES "")
  1147. if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
  1148. # on not-Windows and not-crosscompiling, check for writable argv[]
  1149. include(CheckCSourceRuns)
  1150. check_c_source_runs("
  1151. int main(int argc, char **argv)
  1152. {
  1153. (void)argc;
  1154. argv[0][0] = ' ';
  1155. return (argv[0][0] == ' ')?0:1;
  1156. }" HAVE_WRITABLE_ARGV)
  1157. endif()
  1158. set(CMAKE_REQUIRED_FLAGS)
  1159. option(ENABLE_WEBSOCKETS "Set to ON to enable EXPERIMENTAL websockets" OFF)
  1160. if(ENABLE_WEBSOCKETS)
  1161. if(${SIZEOF_CURL_OFF_T} GREATER "4")
  1162. set(USE_WEBSOCKETS ON)
  1163. else()
  1164. message(WARNING "curl_off_t is too small to enable WebSockets")
  1165. endif()
  1166. endif()
  1167. foreach(CURL_TEST
  1168. HAVE_GLIBC_STRERROR_R
  1169. HAVE_POSIX_STRERROR_R
  1170. )
  1171. curl_internal_test(${CURL_TEST})
  1172. endforeach()
  1173. # Check for reentrant
  1174. foreach(CURL_TEST
  1175. HAVE_GETHOSTBYNAME_R_3
  1176. HAVE_GETHOSTBYNAME_R_5
  1177. HAVE_GETHOSTBYNAME_R_6)
  1178. if(NOT ${CURL_TEST})
  1179. if(${CURL_TEST}_REENTRANT)
  1180. set(NEED_REENTRANT 1)
  1181. endif()
  1182. endif()
  1183. endforeach()
  1184. if(NEED_REENTRANT)
  1185. foreach(CURL_TEST
  1186. HAVE_GETHOSTBYNAME_R_3
  1187. HAVE_GETHOSTBYNAME_R_5
  1188. HAVE_GETHOSTBYNAME_R_6)
  1189. set(${CURL_TEST} 0)
  1190. if(${CURL_TEST}_REENTRANT)
  1191. set(${CURL_TEST} 1)
  1192. endif()
  1193. endforeach()
  1194. endif()
  1195. if(NOT WIN32)
  1196. # Check clock_gettime(CLOCK_MONOTONIC, x) support
  1197. curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
  1198. endif()
  1199. # Check compiler support of __builtin_available()
  1200. curl_internal_test(HAVE_BUILTIN_AVAILABLE)
  1201. # Some other minor tests
  1202. if(NOT HAVE_IN_ADDR_T)
  1203. set(in_addr_t "unsigned long")
  1204. endif()
  1205. # Check for nonblocking
  1206. set(HAVE_DISABLED_NONBLOCKING 1)
  1207. if(HAVE_FIONBIO OR
  1208. HAVE_IOCTLSOCKET OR
  1209. HAVE_IOCTLSOCKET_CASE OR
  1210. HAVE_O_NONBLOCK)
  1211. set(HAVE_DISABLED_NONBLOCKING)
  1212. endif()
  1213. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  1214. include(CheckCCompilerFlag)
  1215. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  1216. if(HAVE_C_FLAG_Wno_long_double)
  1217. # The Mac version of GCC warns about use of long double. Disable it.
  1218. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  1219. if(MPRINTF_COMPILE_FLAGS)
  1220. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  1221. else()
  1222. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  1223. endif()
  1224. set_source_files_properties(mprintf.c PROPERTIES
  1225. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  1226. endif()
  1227. endif()
  1228. # TODO test which of these headers are required
  1229. if(WIN32)
  1230. set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
  1231. else()
  1232. set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
  1233. set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
  1234. set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
  1235. endif()
  1236. include(CMake/OtherTests.cmake)
  1237. add_definitions(-DHAVE_CONFIG_H)
  1238. # For Windows, all compilers used by CMake should support large files
  1239. if(WIN32)
  1240. set(USE_WIN32_LARGE_FILES ON)
  1241. # Use the manifest embedded in the Windows Resource
  1242. set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
  1243. # We use crypto functions that are not available for UWP apps
  1244. if(NOT WINDOWS_STORE)
  1245. set(USE_WIN32_CRYPTO ON)
  1246. endif()
  1247. # Link required libraries for USE_WIN32_CRYPTO or USE_SCHANNEL
  1248. if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
  1249. list(APPEND CURL_LIBS "advapi32" "crypt32")
  1250. endif()
  1251. endif()
  1252. if(MSVC)
  1253. # Disable default manifest added by CMake
  1254. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
  1255. add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  1256. if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
  1257. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  1258. else()
  1259. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  1260. endif()
  1261. # Use multithreaded compilation on VS 2008+
  1262. if(MSVC_VERSION GREATER_EQUAL 1500)
  1263. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
  1264. endif()
  1265. endif()
  1266. if(CURL_WERROR)
  1267. if(MSVC_VERSION)
  1268. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
  1269. else()
  1270. # this assumes clang or gcc style options
  1271. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
  1272. endif()
  1273. endif()
  1274. if(CURL_LTO)
  1275. if(CMAKE_VERSION VERSION_LESS 3.9)
  1276. message(FATAL_ERROR "Requested LTO but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
  1277. endif()
  1278. cmake_policy(SET CMP0069 NEW)
  1279. include(CheckIPOSupported)
  1280. check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT CURL_LTO_ERROR LANGUAGES C)
  1281. if(CURL_HAS_LTO)
  1282. message(STATUS "LTO supported and enabled")
  1283. else()
  1284. message(FATAL_ERROR "LTO was requested - but compiler doesn't support it\n${CURL_LTO_ERROR}")
  1285. endif()
  1286. endif()
  1287. # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
  1288. function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
  1289. file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
  1290. string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1291. string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1292. string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1293. string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1294. string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1295. string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
  1296. string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace @@ with ${}, even if that may not be read by CMake scripts.
  1297. file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
  1298. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT_FILE}")
  1299. endfunction()
  1300. include(GNUInstallDirs)
  1301. set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  1302. set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
  1303. set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
  1304. set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
  1305. set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
  1306. if(USE_MANUAL)
  1307. add_subdirectory(docs)
  1308. endif()
  1309. add_subdirectory(lib)
  1310. if(BUILD_CURL_EXE)
  1311. add_subdirectory(src)
  1312. endif()
  1313. cmake_dependent_option(BUILD_TESTING "Build tests"
  1314. ON "PERL_FOUND;NOT CURL_DISABLE_TESTS"
  1315. OFF)
  1316. if(BUILD_TESTING)
  1317. add_subdirectory(tests)
  1318. endif()
  1319. if(NOT CURL_DISABLE_INSTALL)
  1320. # Helper to populate a list (_items) with a label when conditions (the remaining
  1321. # args) are satisfied
  1322. macro(_add_if label)
  1323. # needs to be a macro to allow this indirection
  1324. if(${ARGN})
  1325. set(_items ${_items} "${label}")
  1326. endif()
  1327. endmacro()
  1328. # NTLM support requires crypto function adaptions from various SSL libs
  1329. if(NOT (CURL_DISABLE_NTLM) AND
  1330. (USE_OPENSSL OR USE_MBEDTLS OR USE_DARWINSSL OR USE_WIN32_CRYPTO OR USE_GNUTLS))
  1331. set(use_curl_ntlm_core ON)
  1332. endif()
  1333. # Clear list and try to detect available features
  1334. set(_items)
  1335. _add_if("SSL" SSL_ENABLED)
  1336. _add_if("IPv6" ENABLE_IPV6)
  1337. _add_if("UnixSockets" USE_UNIX_SOCKETS)
  1338. _add_if("libz" HAVE_LIBZ)
  1339. _add_if("brotli" HAVE_BROTLI)
  1340. _add_if("zstd" HAVE_ZSTD)
  1341. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
  1342. _add_if("IDN" HAVE_LIBIDN2 OR USE_WIN32_IDN)
  1343. _add_if("Largefile" (SIZEOF_CURL_OFF_T GREATER 4) AND
  1344. ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
  1345. _add_if("SSPI" USE_WINDOWS_SSPI)
  1346. _add_if("GSS-API" HAVE_GSSAPI)
  1347. _add_if("alt-svc" NOT CURL_DISABLE_ALTSVC)
  1348. _add_if("HSTS" NOT CURL_DISABLE_HSTS)
  1349. _add_if("SPNEGO" NOT CURL_DISABLE_NEGOTIATE_AUTH AND
  1350. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1351. _add_if("Kerberos" NOT CURL_DISABLE_KERBEROS_AUTH AND
  1352. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1353. _add_if("NTLM" NOT (CURL_DISABLE_NTLM) AND
  1354. (use_curl_ntlm_core OR USE_WINDOWS_SSPI))
  1355. _add_if("NTLM_WB" NOT (CURL_DISABLE_NTLM) AND
  1356. (use_curl_ntlm_core OR USE_WINDOWS_SSPI) AND
  1357. NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
  1358. _add_if("TLS-SRP" USE_TLS_SRP)
  1359. _add_if("HTTP2" USE_NGHTTP2)
  1360. _add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE)
  1361. _add_if("MultiSSL" CURL_WITH_MULTI_SSL)
  1362. # TODO wolfSSL only support this from v5.0.0 onwards
  1363. _add_if("HTTPS-proxy" SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS
  1364. OR USE_SCHANNEL OR USE_RUSTLS OR USE_BEARSSL OR
  1365. USE_MBEDTLS OR USE_SECTRANSP))
  1366. _add_if("unicode" ENABLE_UNICODE)
  1367. _add_if("threadsafe" HAVE_ATOMIC OR
  1368. (USE_THREADS_POSIX AND HAVE_PTHREAD_H) OR
  1369. (WIN32 AND HAVE_WIN32_WINNT GREATER_EQUAL 0x600))
  1370. _add_if("PSL" USE_LIBPSL)
  1371. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1372. message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
  1373. # Clear list and try to detect available protocols
  1374. set(_items)
  1375. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1376. _add_if("IPFS" NOT CURL_DISABLE_HTTP)
  1377. _add_if("IPNS" NOT CURL_DISABLE_HTTP)
  1378. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
  1379. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1380. _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
  1381. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1382. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1383. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1384. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1385. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1386. ((USE_OPENLDAP AND SSL_ENABLED) OR
  1387. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1388. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1389. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1390. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1391. _add_if("GOPHERS" NOT CURL_DISABLE_GOPHER AND SSL_ENABLED)
  1392. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1393. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
  1394. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1395. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
  1396. _add_if("SMB" NOT CURL_DISABLE_SMB AND
  1397. use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
  1398. _add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND
  1399. use_curl_ntlm_core AND (SIZEOF_CURL_OFF_T GREATER 4))
  1400. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1401. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
  1402. _add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH)
  1403. _add_if("SFTP" USE_LIBSSH2 OR USE_LIBSSH)
  1404. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1405. _add_if("RTMP" USE_LIBRTMP)
  1406. _add_if("MQTT" NOT CURL_DISABLE_MQTT)
  1407. _add_if("WS" USE_WEBSOCKETS)
  1408. _add_if("WSS" USE_WEBSOCKETS)
  1409. if(_items)
  1410. list(SORT _items)
  1411. endif()
  1412. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1413. message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
  1414. # Clear list and collect SSL backends
  1415. set(_items)
  1416. _add_if("Schannel" SSL_ENABLED AND USE_SCHANNEL)
  1417. _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
  1418. _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
  1419. _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
  1420. _add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL)
  1421. _add_if("wolfSSL" SSL_ENABLED AND USE_WOLFSSL)
  1422. _add_if("GnuTLS" SSL_ENABLED AND USE_GNUTLS)
  1423. if(_items)
  1424. list(SORT _items)
  1425. endif()
  1426. string(REPLACE ";" " " SSL_BACKENDS "${_items}")
  1427. message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
  1428. if(CURL_DEFAULT_SSL_BACKEND)
  1429. message(STATUS "Default SSL backend: ${CURL_DEFAULT_SSL_BACKEND}")
  1430. endif()
  1431. # curl-config needs the following options to be set.
  1432. set(CC "${CMAKE_C_COMPILER}")
  1433. # TODO probably put a -D... options here?
  1434. set(CONFIGURE_OPTIONS "")
  1435. set(CURLVERSION "${CURL_VERSION}")
  1436. set(exec_prefix "\${prefix}")
  1437. set(includedir "\${prefix}/include")
  1438. set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  1439. set(LIBCURL_LIBS "")
  1440. set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
  1441. foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
  1442. if(TARGET "${_lib}")
  1443. set(_libname "${_lib}")
  1444. get_target_property(_imported "${_libname}" IMPORTED)
  1445. if(NOT _imported)
  1446. # Reading the LOCATION property on non-imported target will error out.
  1447. # Assume the user won't need this information in the .pc file.
  1448. continue()
  1449. endif()
  1450. get_target_property(_lib "${_libname}" LOCATION)
  1451. if(NOT _lib)
  1452. message(WARNING "Bad lib in library list: ${_libname}")
  1453. continue()
  1454. endif()
  1455. endif()
  1456. if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
  1457. set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
  1458. else()
  1459. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
  1460. endif()
  1461. endforeach()
  1462. if(BUILD_SHARED_LIBS)
  1463. set(ENABLE_SHARED "yes")
  1464. set(LIBCURL_NO_SHARED "")
  1465. set(CPPFLAG_CURL_STATICLIB "")
  1466. else()
  1467. set(ENABLE_SHARED "no")
  1468. set(LIBCURL_NO_SHARED "${LIBCURL_LIBS}")
  1469. set(CPPFLAG_CURL_STATICLIB "-DCURL_STATICLIB")
  1470. endif()
  1471. if(BUILD_STATIC_LIBS)
  1472. set(ENABLE_STATIC "yes")
  1473. else()
  1474. set(ENABLE_STATIC "no")
  1475. endif()
  1476. # "a" (Linux) or "lib" (Windows)
  1477. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1478. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1479. # Set this to "yes" to append all libraries on which -lcurl is dependent
  1480. set(REQUIRE_LIB_DEPS "no")
  1481. # SUPPORT_FEATURES
  1482. # SUPPORT_PROTOCOLS
  1483. set(VERSIONNUM "${CURL_VERSION_NUM}")
  1484. # Finally generate a "curl-config" matching this config
  1485. # Use:
  1486. # * ENABLE_SHARED
  1487. # * ENABLE_STATIC
  1488. configure_file("${CURL_SOURCE_DIR}/curl-config.in"
  1489. "${CURL_BINARY_DIR}/curl-config" @ONLY)
  1490. install(FILES "${CURL_BINARY_DIR}/curl-config"
  1491. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1492. PERMISSIONS
  1493. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1494. GROUP_READ GROUP_EXECUTE
  1495. WORLD_READ WORLD_EXECUTE)
  1496. # Finally generate a pkg-config file matching this config
  1497. configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
  1498. "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
  1499. install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
  1500. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1501. # install headers
  1502. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  1503. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  1504. FILES_MATCHING PATTERN "*.h")
  1505. include(CMakePackageConfigHelpers)
  1506. write_basic_package_version_file(
  1507. "${version_config}"
  1508. VERSION ${CURL_VERSION}
  1509. COMPATIBILITY SameMajorVersion
  1510. )
  1511. file(READ "${version_config}" generated_version_config)
  1512. file(WRITE "${version_config}"
  1513. "if(NOT PACKAGE_FIND_VERSION_RANGE AND PACKAGE_FIND_VERSION_MAJOR STREQUAL \"7\")
  1514. # Version 8 satisfies version 7... requirements
  1515. set(PACKAGE_FIND_VERSION_MAJOR 8)
  1516. set(PACKAGE_FIND_VERSION_COUNT 1)
  1517. endif()
  1518. ${generated_version_config}"
  1519. )
  1520. # Use:
  1521. # * TARGETS_EXPORT_NAME
  1522. # * PROJECT_NAME
  1523. configure_package_config_file(CMake/curl-config.cmake.in
  1524. "${project_config}"
  1525. INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1526. )
  1527. if(CURL_ENABLE_EXPORT_TARGET)
  1528. install(
  1529. EXPORT "${TARGETS_EXPORT_NAME}"
  1530. NAMESPACE "${PROJECT_NAME}::"
  1531. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1532. )
  1533. endif()
  1534. install(
  1535. FILES ${version_config} ${project_config}
  1536. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1537. )
  1538. # Workaround for MSVS10 to avoid the Dialog Hell
  1539. # FIXME: This could be removed with future version of CMake.
  1540. if(MSVC_VERSION EQUAL 1600)
  1541. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  1542. if(EXISTS "${CURL_SLN_FILENAME}")
  1543. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  1544. endif()
  1545. endif()
  1546. if(NOT TARGET curl_uninstall)
  1547. configure_file(
  1548. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
  1549. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
  1550. IMMEDIATE @ONLY)
  1551. add_custom_target(curl_uninstall
  1552. COMMAND ${CMAKE_COMMAND} -P
  1553. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
  1554. endif()
  1555. endif()