CMakeLists.txt 56 KB

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