CMakeLists.txt 57 KB

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