CMakeLists.txt 49 KB

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