CMakeLists.txt 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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. # Depend on OpenSSL via imported targets if supported by the running
  303. # version of CMake. This allows our dependents to get our dependencies
  304. # transitively.
  305. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  306. list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
  307. else()
  308. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  309. include_directories(${OPENSSL_INCLUDE_DIR})
  310. endif()
  311. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  312. check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  313. check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
  314. check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  315. check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  316. check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  317. check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
  318. check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  319. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  320. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  321. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  322. endif()
  323. if(CMAKE_USE_MBEDTLS)
  324. find_package(MbedTLS REQUIRED)
  325. set(SSL_ENABLED ON)
  326. set(USE_MBEDTLS ON)
  327. list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
  328. include_directories(${MBEDTLS_INCLUDE_DIRS})
  329. endif()
  330. option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
  331. if(USE_NGHTTP2)
  332. find_package(NGHTTP2 REQUIRED)
  333. include_directories(${NGHTTP2_INCLUDE_DIRS})
  334. list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
  335. endif()
  336. if(NOT CURL_DISABLE_LDAP)
  337. if(WIN32)
  338. option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
  339. if(USE_WIN32_LDAP)
  340. check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
  341. if(NOT HAVE_WLDAP32)
  342. set(USE_WIN32_LDAP OFF)
  343. endif()
  344. endif()
  345. endif()
  346. option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
  347. mark_as_advanced(CMAKE_USE_OPENLDAP)
  348. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  349. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  350. if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
  351. message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
  352. endif()
  353. # Now that we know, we're not using windows LDAP...
  354. if(USE_WIN32_LDAP)
  355. check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
  356. check_include_file_concat("winber.h" HAVE_WINBER_H)
  357. else()
  358. # Check for LDAP
  359. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  360. check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
  361. check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
  362. set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
  363. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  364. if(CMAKE_LDAP_INCLUDE_DIR)
  365. list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  366. endif()
  367. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  368. check_include_file_concat("lber.h" HAVE_LBER_H)
  369. if(NOT HAVE_LDAP_H)
  370. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  371. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  372. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  373. elseif(NOT HAVE_LIBLDAP)
  374. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  375. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  376. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  377. else()
  378. if(CMAKE_USE_OPENLDAP)
  379. set(USE_OPENLDAP ON)
  380. endif()
  381. if(CMAKE_LDAP_INCLUDE_DIR)
  382. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  383. endif()
  384. set(NEED_LBER_H ON)
  385. set(_HEADER_LIST)
  386. if(HAVE_WINDOWS_H)
  387. list(APPEND _HEADER_LIST "windows.h")
  388. endif()
  389. if(HAVE_SYS_TYPES_H)
  390. list(APPEND _HEADER_LIST "sys/types.h")
  391. endif()
  392. list(APPEND _HEADER_LIST "ldap.h")
  393. set(_SRC_STRING "")
  394. foreach(_HEADER ${_HEADER_LIST})
  395. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  396. endforeach()
  397. set(_SRC_STRING
  398. "
  399. ${_INCLUDE_STRING}
  400. int main(int argc, char ** argv)
  401. {
  402. BerValue *bvp = NULL;
  403. BerElement *bep = ber_init(bvp);
  404. ber_free(bep, 1);
  405. return 0;
  406. }"
  407. )
  408. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
  409. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  410. if(HAVE_LIBLBER)
  411. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  412. endif()
  413. check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
  414. unset(CMAKE_REQUIRED_LIBRARIES)
  415. if(NOT_NEED_LBER_H)
  416. set(NEED_LBER_H OFF)
  417. else()
  418. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  419. endif()
  420. endif()
  421. endif()
  422. endif()
  423. # No ldap, no ldaps.
  424. if(CURL_DISABLE_LDAP)
  425. if(NOT CURL_DISABLE_LDAPS)
  426. message(STATUS "LDAP needs to be enabled to support LDAPS")
  427. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  428. endif()
  429. endif()
  430. if(NOT CURL_DISABLE_LDAPS)
  431. check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
  432. check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
  433. endif()
  434. # Check for idn
  435. check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
  436. # Check for symbol dlopen (same as HAVE_LIBDL)
  437. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  438. option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
  439. set(HAVE_LIBZ OFF)
  440. set(HAVE_ZLIB_H OFF)
  441. set(USE_ZLIB OFF)
  442. if(CURL_ZLIB)
  443. find_package(ZLIB QUIET)
  444. if(ZLIB_FOUND)
  445. set(HAVE_ZLIB_H ON)
  446. set(HAVE_LIBZ ON)
  447. set(USE_ZLIB ON)
  448. # Depend on ZLIB via imported targets if supported by the running
  449. # version of CMake. This allows our dependents to get our dependencies
  450. # transitively.
  451. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  452. list(APPEND CURL_LIBS ZLIB::ZLIB)
  453. else()
  454. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  455. include_directories(${ZLIB_INCLUDE_DIRS})
  456. endif()
  457. list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
  458. endif()
  459. endif()
  460. option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
  461. set(HAVE_BROTLI OFF)
  462. if(CURL_BROTLI)
  463. find_package(Brotli QUIET)
  464. if(BROTLI_FOUND)
  465. set(HAVE_BROTLI ON)
  466. list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
  467. include_directories(${BROTLI_INCLUDE_DIRS})
  468. list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
  469. endif()
  470. endif()
  471. #libSSH2
  472. option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
  473. mark_as_advanced(CMAKE_USE_LIBSSH2)
  474. set(USE_LIBSSH2 OFF)
  475. set(HAVE_LIBSSH2 OFF)
  476. set(HAVE_LIBSSH2_H OFF)
  477. if(CMAKE_USE_LIBSSH2)
  478. find_package(LibSSH2)
  479. if(LIBSSH2_FOUND)
  480. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  481. set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
  482. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  483. include_directories("${LIBSSH2_INCLUDE_DIR}")
  484. set(HAVE_LIBSSH2 ON)
  485. set(USE_LIBSSH2 ON)
  486. # find_package has already found the headers
  487. set(HAVE_LIBSSH2_H ON)
  488. set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
  489. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
  490. # now check for specific libssh2 symbols as they were added in different versions
  491. set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
  492. check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
  493. check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
  494. check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
  495. check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
  496. check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
  497. set(CMAKE_EXTRA_INCLUDE_FILES "")
  498. unset(CMAKE_REQUIRED_LIBRARIES)
  499. endif()
  500. endif()
  501. option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
  502. mark_as_advanced(CMAKE_USE_GSSAPI)
  503. if(CMAKE_USE_GSSAPI)
  504. find_package(GSS)
  505. set(HAVE_GSSAPI ${GSS_FOUND})
  506. if(GSS_FOUND)
  507. message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
  508. list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
  509. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  510. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  511. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  512. if(GSS_FLAVOUR STREQUAL "Heimdal")
  513. set(HAVE_GSSHEIMDAL ON)
  514. else() # MIT
  515. set(HAVE_GSSMIT ON)
  516. set(_INCLUDE_LIST "")
  517. if(HAVE_GSSAPI_GSSAPI_H)
  518. list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
  519. endif()
  520. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  521. list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
  522. endif()
  523. if(HAVE_GSSAPI_GSSAPI_KRB5_H)
  524. list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
  525. endif()
  526. string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
  527. string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
  528. foreach(_dir ${GSS_LINK_DIRECTORIES})
  529. set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
  530. endforeach()
  531. set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
  532. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  533. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  534. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  535. set(HAVE_OLD_GSSMIT ON)
  536. endif()
  537. unset(CMAKE_REQUIRED_LIBRARIES)
  538. endif()
  539. include_directories(${GSS_INCLUDE_DIR})
  540. link_directories(${GSS_LINK_DIRECTORIES})
  541. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
  542. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  543. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  544. list(APPEND CURL_LIBS ${GSS_LIBRARIES})
  545. else()
  546. message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
  547. endif()
  548. endif()
  549. option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
  550. if(ENABLE_UNIX_SOCKETS)
  551. include(CheckStructHasMember)
  552. check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
  553. else()
  554. unset(USE_UNIX_SOCKETS CACHE)
  555. endif()
  556. #
  557. # CA handling
  558. #
  559. set(CURL_CA_BUNDLE "auto" CACHE STRING
  560. "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  561. set(CURL_CA_FALLBACK OFF CACHE BOOL
  562. "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
  563. set(CURL_CA_PATH "auto" CACHE STRING
  564. "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  565. if("${CURL_CA_BUNDLE}" STREQUAL "")
  566. message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
  567. elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
  568. unset(CURL_CA_BUNDLE CACHE)
  569. elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
  570. unset(CURL_CA_BUNDLE CACHE)
  571. set(CURL_CA_BUNDLE_AUTODETECT TRUE)
  572. else()
  573. set(CURL_CA_BUNDLE_SET TRUE)
  574. endif()
  575. if("${CURL_CA_PATH}" STREQUAL "")
  576. message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
  577. elseif("${CURL_CA_PATH}" STREQUAL "none")
  578. unset(CURL_CA_PATH CACHE)
  579. elseif("${CURL_CA_PATH}" STREQUAL "auto")
  580. unset(CURL_CA_PATH CACHE)
  581. set(CURL_CA_PATH_AUTODETECT TRUE)
  582. else()
  583. set(CURL_CA_PATH_SET TRUE)
  584. endif()
  585. if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
  586. # Skip autodetection of unset CA path because CA bundle is set explicitly
  587. elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
  588. # Skip autodetection of unset CA bundle because CA path is set explicitly
  589. elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
  590. # first try autodetecting a CA bundle, then a CA path
  591. if(CURL_CA_BUNDLE_AUTODETECT)
  592. set(SEARCH_CA_BUNDLE_PATHS
  593. /etc/ssl/certs/ca-certificates.crt
  594. /etc/pki/tls/certs/ca-bundle.crt
  595. /usr/share/ssl/certs/ca-bundle.crt
  596. /usr/local/share/certs/ca-root-nss.crt
  597. /etc/ssl/cert.pem)
  598. foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
  599. if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
  600. message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
  601. set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
  602. set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  603. break()
  604. endif()
  605. endforeach()
  606. endif()
  607. if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
  608. if(EXISTS "/etc/ssl/certs")
  609. set(CURL_CA_PATH "/etc/ssl/certs")
  610. set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  611. endif()
  612. endif()
  613. endif()
  614. if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
  615. message(FATAL_ERROR
  616. "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
  617. "Set CURL_CA_PATH=none or enable one of those TLS backends.")
  618. endif()
  619. # Check for header files
  620. if(NOT UNIX)
  621. check_include_file_concat("windows.h" HAVE_WINDOWS_H)
  622. check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
  623. check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
  624. check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
  625. if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL)
  626. set(CURL_LIBS ${CURL_LIBS} "crypt32")
  627. endif()
  628. endif()
  629. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  630. check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
  631. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  632. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  633. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  634. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  635. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  636. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  637. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  638. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  639. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  640. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  641. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  642. check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
  643. check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
  644. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  645. check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
  646. check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
  647. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  648. check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
  649. check_include_file_concat("assert.h" HAVE_ASSERT_H)
  650. check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
  651. check_include_file_concat("des.h" HAVE_DES_H)
  652. check_include_file_concat("err.h" HAVE_ERR_H)
  653. check_include_file_concat("errno.h" HAVE_ERRNO_H)
  654. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  655. check_include_file_concat("idn2.h" HAVE_IDN2_H)
  656. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  657. check_include_file_concat("io.h" HAVE_IO_H)
  658. check_include_file_concat("krb.h" HAVE_KRB_H)
  659. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  660. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  661. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  662. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  663. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  664. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
  665. check_include_file_concat("pem.h" HAVE_PEM_H)
  666. check_include_file_concat("poll.h" HAVE_POLL_H)
  667. check_include_file_concat("pwd.h" HAVE_PWD_H)
  668. check_include_file_concat("rsa.h" HAVE_RSA_H)
  669. check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
  670. check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
  671. check_include_file_concat("signal.h" HAVE_SIGNAL_H)
  672. check_include_file_concat("ssl.h" HAVE_SSL_H)
  673. check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
  674. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  675. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  676. check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
  677. check_include_file_concat("string.h" HAVE_STRING_H)
  678. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  679. check_include_file_concat("stropts.h" HAVE_STROPTS_H)
  680. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  681. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  682. check_include_file_concat("time.h" HAVE_TIME_H)
  683. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  684. check_include_file_concat("utime.h" HAVE_UTIME_H)
  685. check_include_file_concat("x509.h" HAVE_X509_H)
  686. check_include_file_concat("process.h" HAVE_PROCESS_H)
  687. check_include_file_concat("stddef.h" HAVE_STDDEF_H)
  688. check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
  689. check_include_file_concat("malloc.h" HAVE_MALLOC_H)
  690. check_include_file_concat("memory.h" HAVE_MEMORY_H)
  691. check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
  692. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  693. check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
  694. check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
  695. check_type_size(size_t SIZEOF_SIZE_T)
  696. check_type_size(ssize_t SIZEOF_SSIZE_T)
  697. check_type_size("long long" SIZEOF_LONG_LONG)
  698. check_type_size("long" SIZEOF_LONG)
  699. check_type_size("short" SIZEOF_SHORT)
  700. check_type_size("int" SIZEOF_INT)
  701. check_type_size("__int64" SIZEOF___INT64)
  702. check_type_size("long double" SIZEOF_LONG_DOUBLE)
  703. check_type_size("time_t" SIZEOF_TIME_T)
  704. if(NOT HAVE_SIZEOF_SSIZE_T)
  705. if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  706. set(ssize_t long)
  707. endif()
  708. if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  709. set(ssize_t __int64)
  710. endif()
  711. endif()
  712. # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
  713. if(HAVE_SIZEOF_LONG_LONG)
  714. set(HAVE_LONGLONG 1)
  715. set(HAVE_LL 1)
  716. endif()
  717. find_file(RANDOM_FILE urandom /dev)
  718. mark_as_advanced(RANDOM_FILE)
  719. # Check for some functions that are used
  720. if(HAVE_LIBWS2_32)
  721. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  722. elseif(HAVE_LIBSOCKET)
  723. set(CMAKE_REQUIRED_LIBRARIES socket)
  724. endif()
  725. check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
  726. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  727. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  728. check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
  729. check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
  730. check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
  731. check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
  732. check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
  733. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  734. check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
  735. check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
  736. check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
  737. check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
  738. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  739. if(NOT HAVE_STRNCMPI)
  740. set(HAVE_STRCMPI)
  741. endif()
  742. check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
  743. check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
  744. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  745. check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
  746. check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
  747. check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
  748. check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
  749. check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
  750. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  751. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  752. check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
  753. check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
  754. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  755. check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
  756. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  757. check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
  758. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  759. check_symbol_exists(usleep "${CURL_INCLUDES}" HAVE_USLEEP)
  760. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  761. check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
  762. check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
  763. check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
  764. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  765. check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
  766. check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
  767. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  768. set(HAVE_SIGNAL 1)
  769. endif()
  770. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  771. check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
  772. check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
  773. check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
  774. check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
  775. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  776. check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
  777. check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
  778. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  779. check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
  780. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  781. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  782. check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
  783. check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
  784. check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
  785. check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
  786. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  787. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  788. check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
  789. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  790. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  791. check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
  792. check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
  793. check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
  794. # symbol exists in win32, but function does not.
  795. if(WIN32)
  796. if(ENABLE_INET_PTON)
  797. check_function_exists(inet_pton HAVE_INET_PTON)
  798. # _WIN32_WINNT_VISTA (0x0600)
  799. add_definitions(-D_WIN32_WINNT=0x0600)
  800. else()
  801. # _WIN32_WINNT_WINXP (0x0501)
  802. add_definitions(-D_WIN32_WINNT=0x0501)
  803. endif()
  804. else()
  805. check_function_exists(inet_pton HAVE_INET_PTON)
  806. endif()
  807. check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
  808. if(HAVE_FSETXATTR)
  809. foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
  810. curl_internal_test(${CURL_TEST})
  811. endforeach()
  812. endif()
  813. # sigaction and sigsetjmp are special. Use special mechanism for
  814. # detecting those, but only if previous attempt failed.
  815. if(HAVE_SIGNAL_H)
  816. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  817. endif()
  818. if(NOT HAVE_SIGSETJMP)
  819. if(HAVE_SETJMP_H)
  820. check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
  821. if(HAVE_MACRO_SIGSETJMP)
  822. set(HAVE_SIGSETJMP 1)
  823. endif()
  824. endif()
  825. endif()
  826. # If there is no stricmp(), do not allow LDAP to parse URLs
  827. if(NOT HAVE_STRICMP)
  828. set(HAVE_LDAP_URL_PARSE 1)
  829. endif()
  830. # Do curl specific tests
  831. foreach(CURL_TEST
  832. HAVE_FCNTL_O_NONBLOCK
  833. HAVE_IOCTLSOCKET
  834. HAVE_IOCTLSOCKET_CAMEL
  835. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  836. HAVE_IOCTLSOCKET_FIONBIO
  837. HAVE_IOCTL_FIONBIO
  838. HAVE_IOCTL_SIOCGIFADDR
  839. HAVE_SETSOCKOPT_SO_NONBLOCK
  840. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
  841. TIME_WITH_SYS_TIME
  842. HAVE_O_NONBLOCK
  843. HAVE_GETHOSTBYADDR_R_5
  844. HAVE_GETHOSTBYADDR_R_7
  845. HAVE_GETHOSTBYADDR_R_8
  846. HAVE_GETHOSTBYADDR_R_5_REENTRANT
  847. HAVE_GETHOSTBYADDR_R_7_REENTRANT
  848. HAVE_GETHOSTBYADDR_R_8_REENTRANT
  849. HAVE_GETHOSTBYNAME_R_3
  850. HAVE_GETHOSTBYNAME_R_5
  851. HAVE_GETHOSTBYNAME_R_6
  852. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  853. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  854. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  855. HAVE_IN_ADDR_T
  856. HAVE_BOOL_T
  857. STDC_HEADERS
  858. RETSIGTYPE_TEST
  859. HAVE_INET_NTOA_R_DECL
  860. HAVE_INET_NTOA_R_DECL_REENTRANT
  861. HAVE_GETADDRINFO
  862. HAVE_FILE_OFFSET_BITS
  863. HAVE_VARIADIC_MACROS_C99
  864. HAVE_VARIADIC_MACROS_GCC
  865. )
  866. curl_internal_test(${CURL_TEST})
  867. endforeach()
  868. if(HAVE_FILE_OFFSET_BITS)
  869. set(_FILE_OFFSET_BITS 64)
  870. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  871. endif()
  872. check_type_size("off_t" SIZEOF_OFF_T)
  873. # include this header to get the type
  874. set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
  875. set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
  876. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  877. set(CMAKE_EXTRA_INCLUDE_FILES "")
  878. set(CMAKE_REQUIRED_FLAGS)
  879. foreach(CURL_TEST
  880. HAVE_GLIBC_STRERROR_R
  881. HAVE_POSIX_STRERROR_R
  882. )
  883. curl_internal_test(${CURL_TEST})
  884. endforeach()
  885. # Check for reentrant
  886. foreach(CURL_TEST
  887. HAVE_GETHOSTBYADDR_R_5
  888. HAVE_GETHOSTBYADDR_R_7
  889. HAVE_GETHOSTBYADDR_R_8
  890. HAVE_GETHOSTBYNAME_R_3
  891. HAVE_GETHOSTBYNAME_R_5
  892. HAVE_GETHOSTBYNAME_R_6
  893. HAVE_INET_NTOA_R_DECL_REENTRANT)
  894. if(NOT ${CURL_TEST})
  895. if(${CURL_TEST}_REENTRANT)
  896. set(NEED_REENTRANT 1)
  897. endif()
  898. endif()
  899. endforeach()
  900. if(NEED_REENTRANT)
  901. foreach(CURL_TEST
  902. HAVE_GETHOSTBYADDR_R_5
  903. HAVE_GETHOSTBYADDR_R_7
  904. HAVE_GETHOSTBYADDR_R_8
  905. HAVE_GETHOSTBYNAME_R_3
  906. HAVE_GETHOSTBYNAME_R_5
  907. HAVE_GETHOSTBYNAME_R_6)
  908. set(${CURL_TEST} 0)
  909. if(${CURL_TEST}_REENTRANT)
  910. set(${CURL_TEST} 1)
  911. endif()
  912. endforeach()
  913. endif()
  914. if(HAVE_INET_NTOA_R_DECL_REENTRANT)
  915. set(HAVE_INET_NTOA_R_DECL 1)
  916. set(NEED_REENTRANT 1)
  917. endif()
  918. # Check clock_gettime(CLOCK_MONOTONIC, x) support
  919. curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
  920. # Check compiler support of __builtin_available()
  921. curl_internal_test(HAVE_BUILTIN_AVAILABLE)
  922. # Some other minor tests
  923. if(NOT HAVE_IN_ADDR_T)
  924. set(in_addr_t "unsigned long")
  925. endif()
  926. # Fix libz / zlib.h
  927. if(NOT CURL_SPECIAL_LIBZ)
  928. if(NOT HAVE_LIBZ)
  929. set(HAVE_ZLIB_H 0)
  930. endif()
  931. if(NOT HAVE_ZLIB_H)
  932. set(HAVE_LIBZ 0)
  933. endif()
  934. endif()
  935. # Check for nonblocking
  936. set(HAVE_DISABLED_NONBLOCKING 1)
  937. if(HAVE_FIONBIO OR
  938. HAVE_IOCTLSOCKET OR
  939. HAVE_IOCTLSOCKET_CASE OR
  940. HAVE_O_NONBLOCK)
  941. set(HAVE_DISABLED_NONBLOCKING)
  942. endif()
  943. if(RETSIGTYPE_TEST)
  944. set(RETSIGTYPE void)
  945. else()
  946. set(RETSIGTYPE int)
  947. endif()
  948. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  949. include(CheckCCompilerFlag)
  950. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  951. if(HAVE_C_FLAG_Wno_long_double)
  952. # The Mac version of GCC warns about use of long double. Disable it.
  953. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  954. if(MPRINTF_COMPILE_FLAGS)
  955. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  956. else()
  957. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  958. endif()
  959. set_source_files_properties(mprintf.c PROPERTIES
  960. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  961. endif()
  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. include(GNUInstallDirs)
  1012. set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  1013. set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
  1014. set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
  1015. set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
  1016. set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
  1017. if(USE_MANUAL)
  1018. add_subdirectory(docs)
  1019. endif()
  1020. add_subdirectory(lib)
  1021. if(BUILD_CURL_EXE)
  1022. add_subdirectory(src)
  1023. endif()
  1024. include(CTest)
  1025. if(BUILD_TESTING)
  1026. add_subdirectory(tests)
  1027. endif()
  1028. # Helper to populate a list (_items) with a label when conditions (the remaining
  1029. # args) are satisfied
  1030. function(_add_if label)
  1031. # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
  1032. if(${ARGN})
  1033. set(_items ${_items} "${label}" PARENT_SCOPE)
  1034. endif()
  1035. endfunction()
  1036. # Clear list and try to detect available features
  1037. set(_items)
  1038. _add_if("SSL" SSL_ENABLED)
  1039. _add_if("IPv6" ENABLE_IPV6)
  1040. _add_if("unix-sockets" USE_UNIX_SOCKETS)
  1041. _add_if("libz" HAVE_LIBZ)
  1042. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
  1043. _add_if("IDN" HAVE_LIBIDN2)
  1044. _add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
  1045. ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
  1046. # TODO SSP1 (WinSSL) check is missing
  1047. _add_if("SSPI" USE_WINDOWS_SSPI)
  1048. _add_if("GSS-API" HAVE_GSSAPI)
  1049. # TODO SSP1 missing for SPNEGO
  1050. _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1051. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1052. _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1053. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1054. # NTLM support requires crypto function adaptions from various SSL libs
  1055. # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
  1056. if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_SECTRANSP OR USE_MBEDTLS))
  1057. _add_if("NTLM" 1)
  1058. # TODO missing option (autoconf: --enable-ntlm-wb)
  1059. _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
  1060. endif()
  1061. # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
  1062. _add_if("TLS-SRP" USE_TLS_SRP)
  1063. # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
  1064. _add_if("HTTP2" USE_NGHTTP2)
  1065. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1066. message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
  1067. # Clear list and try to detect available protocols
  1068. set(_items)
  1069. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1070. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
  1071. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1072. _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
  1073. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1074. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1075. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1076. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1077. # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
  1078. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1079. ((USE_OPENLDAP AND SSL_ENABLED) OR
  1080. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1081. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1082. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1083. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1084. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1085. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
  1086. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1087. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
  1088. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1089. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
  1090. _add_if("SCP" USE_LIBSSH2)
  1091. _add_if("SFTP" USE_LIBSSH2)
  1092. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1093. _add_if("RTMP" USE_LIBRTMP)
  1094. if(_items)
  1095. list(SORT _items)
  1096. endif()
  1097. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1098. message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
  1099. # Clear list and collect SSL backends
  1100. set(_items)
  1101. _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
  1102. _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
  1103. _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
  1104. _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
  1105. if(_items)
  1106. list(SORT _items)
  1107. endif()
  1108. string(REPLACE ";" " " SSL_BACKENDS "${_items}")
  1109. message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
  1110. # curl-config needs the following options to be set.
  1111. set(CC "${CMAKE_C_COMPILER}")
  1112. # TODO probably put a -D... options here?
  1113. set(CONFIGURE_OPTIONS "")
  1114. # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
  1115. set(CPPFLAG_CURL_STATICLIB "")
  1116. set(CURLVERSION "${CURL_VERSION}")
  1117. if(BUILD_SHARED_LIBS)
  1118. set(ENABLE_SHARED "yes")
  1119. set(ENABLE_STATIC "no")
  1120. else()
  1121. set(ENABLE_SHARED "no")
  1122. set(ENABLE_STATIC "yes")
  1123. endif()
  1124. set(exec_prefix "\${prefix}")
  1125. set(includedir "\${prefix}/include")
  1126. set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  1127. set(LIBCURL_LIBS "")
  1128. set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
  1129. foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
  1130. if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
  1131. set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
  1132. else()
  1133. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
  1134. endif()
  1135. endforeach()
  1136. # "a" (Linux) or "lib" (Windows)
  1137. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1138. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1139. # Set this to "yes" to append all libraries on which -lcurl is dependent
  1140. set(REQUIRE_LIB_DEPS "no")
  1141. # SUPPORT_FEATURES
  1142. # SUPPORT_PROTOCOLS
  1143. set(VERSIONNUM "${CURL_VERSION_NUM}")
  1144. # Finally generate a "curl-config" matching this config
  1145. # Use:
  1146. # * ENABLE_SHARED
  1147. # * ENABLE_STATIC
  1148. configure_file("${CURL_SOURCE_DIR}/curl-config.in"
  1149. "${CURL_BINARY_DIR}/curl-config" @ONLY)
  1150. install(FILES "${CURL_BINARY_DIR}/curl-config"
  1151. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1152. PERMISSIONS
  1153. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1154. GROUP_READ GROUP_EXECUTE
  1155. WORLD_READ WORLD_EXECUTE)
  1156. # Finally generate a pkg-config file matching this config
  1157. configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
  1158. "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
  1159. install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
  1160. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1161. # install headers
  1162. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  1163. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  1164. FILES_MATCHING PATTERN "*.h")
  1165. include(CMakePackageConfigHelpers)
  1166. write_basic_package_version_file(
  1167. "${version_config}"
  1168. VERSION ${CURL_VERSION}
  1169. COMPATIBILITY SameMajorVersion
  1170. )
  1171. # Use:
  1172. # * TARGETS_EXPORT_NAME
  1173. # * PROJECT_NAME
  1174. configure_package_config_file(CMake/curl-config.cmake.in
  1175. "${project_config}"
  1176. INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1177. )
  1178. install(
  1179. EXPORT "${TARGETS_EXPORT_NAME}"
  1180. NAMESPACE "${PROJECT_NAME}::"
  1181. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1182. )
  1183. install(
  1184. FILES ${version_config} ${project_config}
  1185. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1186. )
  1187. # Workaround for MSVS10 to avoid the Dialog Hell
  1188. # FIXME: This could be removed with future version of CMake.
  1189. if(MSVC_VERSION EQUAL 1600)
  1190. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  1191. if(EXISTS "${CURL_SLN_FILENAME}")
  1192. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  1193. endif()
  1194. endif()
  1195. if(NOT TARGET uninstall)
  1196. configure_file(
  1197. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
  1198. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
  1199. IMMEDIATE @ONLY)
  1200. add_custom_target(uninstall
  1201. COMMAND ${CMAKE_COMMAND} -P
  1202. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
  1203. endif()