CMakeLists.txt 54 KB

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