CMakeLists.txt 57 KB

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