CMakeLists.txt 49 KB

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