CMakeLists.txt 65 KB

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