CMakeLists.txt 64 KB

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