CMakeLists.txt 63 KB

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