CMakeLists.txt 62 KB

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