2
0

CMakeLists.txt 58 KB

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