CMakeLists.txt 66 KB

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