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