2
0

CMakeLists.txt 59 KB

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