CMakeLists.txt 78 KB

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