CMakeLists.txt 63 KB

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