CMakeLists.txt 49 KB

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