CMakeLists.txt 70 KB

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