CMakeLists.txt 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. include_regular_expression("^.*$") # Sukender: Is it necessary?
  56. # Setup package meta-data
  57. # SET(PACKAGE "curl")
  58. message(STATUS "curl version=[${CURL_VERSION}]")
  59. # SET(PACKAGE_TARNAME "curl")
  60. # SET(PACKAGE_NAME "curl")
  61. # SET(PACKAGE_VERSION "-")
  62. # SET(PACKAGE_STRING "curl-")
  63. # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/")
  64. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  65. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  66. include_directories(${CURL_SOURCE_DIR}/include)
  67. option(CURL_WERROR "Turn compiler warnings into errors" OFF)
  68. option(PICKY_COMPILER "Enable picky compiler options" ON)
  69. option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
  70. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  71. option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
  72. if(WIN32)
  73. option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
  74. 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)
  75. endif()
  76. cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
  77. ON "NOT ENABLE_ARES"
  78. OFF)
  79. option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
  80. option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
  81. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
  82. if(PICKY_COMPILER)
  83. 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)
  84. # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
  85. # test result in.
  86. check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
  87. if(OPT${_CCOPT})
  88. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
  89. endif()
  90. endforeach()
  91. endif()
  92. endif()
  93. if(ENABLE_DEBUG)
  94. # DEBUGBUILD will be defined only for Debug builds
  95. if(NOT CMAKE_VERSION VERSION_LESS 3.0)
  96. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
  97. else()
  98. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUGBUILD)
  99. endif()
  100. set(ENABLE_CURLDEBUG ON)
  101. endif()
  102. if(ENABLE_CURLDEBUG)
  103. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
  104. endif()
  105. # For debug libs and exes, add "-d" postfix
  106. if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
  107. set(CMAKE_DEBUG_POSTFIX "-d")
  108. endif()
  109. # initialize CURL_LIBS
  110. set(CURL_LIBS "")
  111. if(ENABLE_ARES)
  112. set(USE_ARES 1)
  113. find_package(CARES REQUIRED)
  114. list(APPEND CURL_LIBS ${CARES_LIBRARY})
  115. set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
  116. endif()
  117. include(CurlSymbolHiding)
  118. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  119. mark_as_advanced(HTTP_ONLY)
  120. option(CURL_DISABLE_FTP "disables FTP" OFF)
  121. mark_as_advanced(CURL_DISABLE_FTP)
  122. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  123. mark_as_advanced(CURL_DISABLE_LDAP)
  124. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  125. mark_as_advanced(CURL_DISABLE_TELNET)
  126. option(CURL_DISABLE_DICT "disables DICT" OFF)
  127. mark_as_advanced(CURL_DISABLE_DICT)
  128. option(CURL_DISABLE_FILE "disables FILE" OFF)
  129. mark_as_advanced(CURL_DISABLE_FILE)
  130. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  131. mark_as_advanced(CURL_DISABLE_TFTP)
  132. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  133. mark_as_advanced(CURL_DISABLE_HTTP)
  134. option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
  135. mark_as_advanced(CURL_DISABLE_LDAPS)
  136. option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
  137. mark_as_advanced(CURL_DISABLE_RTSP)
  138. option(CURL_DISABLE_PROXY "to disable proxy" OFF)
  139. mark_as_advanced(CURL_DISABLE_PROXY)
  140. option(CURL_DISABLE_POP3 "to disable POP3" OFF)
  141. mark_as_advanced(CURL_DISABLE_POP3)
  142. option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
  143. mark_as_advanced(CURL_DISABLE_IMAP)
  144. option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
  145. mark_as_advanced(CURL_DISABLE_SMTP)
  146. option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
  147. mark_as_advanced(CURL_DISABLE_GOPHER)
  148. if(HTTP_ONLY)
  149. set(CURL_DISABLE_FTP ON)
  150. set(CURL_DISABLE_LDAP ON)
  151. set(CURL_DISABLE_LDAPS ON)
  152. set(CURL_DISABLE_TELNET ON)
  153. set(CURL_DISABLE_DICT ON)
  154. set(CURL_DISABLE_FILE ON)
  155. set(CURL_DISABLE_TFTP ON)
  156. set(CURL_DISABLE_RTSP ON)
  157. set(CURL_DISABLE_POP3 ON)
  158. set(CURL_DISABLE_IMAP ON)
  159. set(CURL_DISABLE_SMTP ON)
  160. set(CURL_DISABLE_GOPHER ON)
  161. endif()
  162. option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
  163. mark_as_advanced(CURL_DISABLE_COOKIES)
  164. option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
  165. mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
  166. option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
  167. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  168. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
  169. mark_as_advanced(ENABLE_IPV6)
  170. if(ENABLE_IPV6 AND NOT WIN32)
  171. include(CheckStructHasMember)
  172. check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
  173. HAVE_SOCKADDR_IN6_SIN6_ADDR)
  174. check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
  175. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
  176. if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
  177. message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
  178. # Force the feature off as this name is used as guard macro...
  179. set(ENABLE_IPV6 OFF
  180. CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
  181. endif()
  182. endif()
  183. curl_nroff_check()
  184. find_package(Perl)
  185. cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
  186. ON "NROFF_USEFUL;PERL_FOUND"
  187. OFF)
  188. if(NOT PERL_FOUND)
  189. message(STATUS "Perl not found, testing disabled.")
  190. set(BUILD_TESTING OFF)
  191. endif()
  192. if(ENABLE_MANUAL)
  193. set(USE_MANUAL ON)
  194. endif()
  195. # We need ansi c-flags, especially on HP
  196. set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  197. set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
  198. if(CURL_STATIC_CRT)
  199. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  200. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  201. endif()
  202. # Disable warnings on Borland to avoid changing 3rd party code.
  203. if(BORLAND)
  204. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  205. endif()
  206. # If we are on AIX, do the _ALL_SOURCE magic
  207. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  208. set(_ALL_SOURCE 1)
  209. endif()
  210. # Include all the necessary files for macros
  211. include(CheckFunctionExists)
  212. include(CheckIncludeFile)
  213. include(CheckIncludeFiles)
  214. include(CheckLibraryExists)
  215. include(CheckSymbolExists)
  216. include(CheckTypeSize)
  217. include(CheckCSourceCompiles)
  218. include(CMakeDependentOption)
  219. # On windows preload settings
  220. if(WIN32)
  221. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
  222. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  223. endif()
  224. if(ENABLE_THREADED_RESOLVER)
  225. find_package(Threads REQUIRED)
  226. if(WIN32)
  227. set(USE_THREADS_WIN32 ON)
  228. else()
  229. set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
  230. set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
  231. endif()
  232. set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
  233. endif()
  234. # Check for all needed libraries
  235. check_library_exists_concat("dl" dlopen HAVE_LIBDL)
  236. check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
  237. check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
  238. # Yellowtab Zeta needs different libraries than BeOS 5.
  239. if(BEOS)
  240. set(NOT_NEED_LIBNSL 1)
  241. check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
  242. check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
  243. endif()
  244. if(NOT NOT_NEED_LIBNSL)
  245. check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
  246. endif()
  247. check_function_exists(gethostname HAVE_GETHOSTNAME)
  248. if(WIN32)
  249. check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
  250. check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
  251. list(APPEND CURL_LIBS "advapi32")
  252. endif()
  253. # check SSL libraries
  254. # TODO support GNUTLS, NSS, POLARSSL, CYASSL
  255. if(APPLE)
  256. option(CMAKE_USE_DARWINSSL "enable Apple OS native SSL/TLS" OFF)
  257. endif()
  258. if(WIN32)
  259. option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
  260. cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
  261. CMAKE_USE_WINSSL OFF)
  262. endif()
  263. option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
  264. set(openssl_default ON)
  265. if(WIN32 OR CMAKE_USE_DARWINSSL OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
  266. set(openssl_default OFF)
  267. endif()
  268. option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default})
  269. count_true(enabled_ssl_options_count
  270. CMAKE_USE_WINSSL
  271. CMAKE_USE_DARWINSSL
  272. CMAKE_USE_OPENSSL
  273. CMAKE_USE_MBEDTLS
  274. )
  275. if(enabled_ssl_options_count GREATER "1")
  276. set(CURL_WITH_MULTI_SSL ON)
  277. endif()
  278. if(CMAKE_USE_WINSSL)
  279. set(SSL_ENABLED ON)
  280. set(USE_SCHANNEL ON) # Windows native SSL/TLS support
  281. set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
  282. list(APPEND CURL_LIBS "crypt32")
  283. endif()
  284. if(CURL_WINDOWS_SSPI)
  285. set(USE_WINDOWS_SSPI ON)
  286. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
  287. endif()
  288. if(CMAKE_USE_DARWINSSL)
  289. find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
  290. if(NOT COREFOUNDATION_FRAMEWORK)
  291. message(FATAL_ERROR "CoreFoundation framework not found")
  292. endif()
  293. find_library(SECURITY_FRAMEWORK "Security")
  294. if(NOT SECURITY_FRAMEWORK)
  295. message(FATAL_ERROR "Security framework not found")
  296. endif()
  297. set(SSL_ENABLED ON)
  298. set(USE_DARWINSSL ON)
  299. list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
  300. endif()
  301. if(CMAKE_USE_OPENSSL)
  302. find_package(OpenSSL REQUIRED)
  303. set(SSL_ENABLED ON)
  304. set(USE_OPENSSL ON)
  305. set(HAVE_LIBCRYPTO ON)
  306. set(HAVE_LIBSSL ON)
  307. # Depend on OpenSSL via imported targets if supported by the running
  308. # version of CMake. This allows our dependents to get our dependencies
  309. # transitively.
  310. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  311. list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
  312. else()
  313. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  314. include_directories(${OPENSSL_INCLUDE_DIR})
  315. endif()
  316. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  317. check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  318. check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
  319. check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  320. check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  321. check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  322. check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
  323. check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  324. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  325. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  326. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  327. endif()
  328. if(CMAKE_USE_MBEDTLS)
  329. find_package(MbedTLS REQUIRED)
  330. set(SSL_ENABLED ON)
  331. set(USE_MBEDTLS ON)
  332. list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
  333. include_directories(${MBEDTLS_INCLUDE_DIRS})
  334. endif()
  335. option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
  336. if(USE_NGHTTP2)
  337. find_package(NGHTTP2 REQUIRED)
  338. include_directories(${NGHTTP2_INCLUDE_DIRS})
  339. list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
  340. endif()
  341. if(NOT CURL_DISABLE_LDAP)
  342. if(WIN32)
  343. option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
  344. if(USE_WIN32_LDAP)
  345. check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
  346. if(NOT HAVE_WLDAP32)
  347. set(USE_WIN32_LDAP OFF)
  348. endif()
  349. endif()
  350. endif()
  351. option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
  352. mark_as_advanced(CMAKE_USE_OPENLDAP)
  353. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  354. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  355. if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
  356. message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
  357. endif()
  358. # Now that we know, we're not using windows LDAP...
  359. if(USE_WIN32_LDAP)
  360. check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
  361. check_include_file_concat("winber.h" HAVE_WINBER_H)
  362. else()
  363. # Check for LDAP
  364. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  365. check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
  366. check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
  367. set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
  368. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  369. if(CMAKE_LDAP_INCLUDE_DIR)
  370. list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  371. endif()
  372. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  373. check_include_file_concat("lber.h" HAVE_LBER_H)
  374. if(NOT HAVE_LDAP_H)
  375. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  376. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  377. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  378. elseif(NOT HAVE_LIBLDAP)
  379. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  380. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  381. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  382. else()
  383. if(CMAKE_USE_OPENLDAP)
  384. set(USE_OPENLDAP ON)
  385. endif()
  386. if(CMAKE_LDAP_INCLUDE_DIR)
  387. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  388. endif()
  389. set(NEED_LBER_H ON)
  390. set(_HEADER_LIST)
  391. if(HAVE_WINDOWS_H)
  392. list(APPEND _HEADER_LIST "windows.h")
  393. endif()
  394. if(HAVE_SYS_TYPES_H)
  395. list(APPEND _HEADER_LIST "sys/types.h")
  396. endif()
  397. list(APPEND _HEADER_LIST "ldap.h")
  398. set(_SRC_STRING "")
  399. foreach(_HEADER ${_HEADER_LIST})
  400. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  401. endforeach()
  402. set(_SRC_STRING
  403. "
  404. ${_INCLUDE_STRING}
  405. int main(int argc, char ** argv)
  406. {
  407. BerValue *bvp = NULL;
  408. BerElement *bep = ber_init(bvp);
  409. ber_free(bep, 1);
  410. return 0;
  411. }"
  412. )
  413. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
  414. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  415. if(HAVE_LIBLBER)
  416. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  417. endif()
  418. check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
  419. if(NOT_NEED_LBER_H)
  420. set(NEED_LBER_H OFF)
  421. else()
  422. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  423. endif()
  424. endif()
  425. endif()
  426. endif()
  427. # No ldap, no ldaps.
  428. if(CURL_DISABLE_LDAP)
  429. if(NOT CURL_DISABLE_LDAPS)
  430. message(STATUS "LDAP needs to be enabled to support LDAPS")
  431. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  432. endif()
  433. endif()
  434. if(NOT CURL_DISABLE_LDAPS)
  435. check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
  436. check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
  437. endif()
  438. # Check for idn
  439. check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
  440. # Check for symbol dlopen (same as HAVE_LIBDL)
  441. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  442. option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
  443. set(HAVE_LIBZ OFF)
  444. set(HAVE_ZLIB_H OFF)
  445. set(USE_ZLIB OFF)
  446. if(CURL_ZLIB)
  447. find_package(ZLIB QUIET)
  448. if(ZLIB_FOUND)
  449. set(HAVE_ZLIB_H ON)
  450. set(HAVE_LIBZ ON)
  451. set(USE_ZLIB ON)
  452. # Depend on ZLIB via imported targets if supported by the running
  453. # version of CMake. This allows our dependents to get our dependencies
  454. # transitively.
  455. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  456. list(APPEND CURL_LIBS ZLIB::ZLIB)
  457. else()
  458. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  459. include_directories(${ZLIB_INCLUDE_DIRS})
  460. endif()
  461. list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
  462. endif()
  463. endif()
  464. option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
  465. set(HAVE_BROTLI OFF)
  466. if(CURL_BROTLI)
  467. find_package(BROTLI QUIET)
  468. if(BROTLI_FOUND)
  469. set(HAVE_BROTLI ON)
  470. list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
  471. include_directories(${BROTLI_INCLUDE_DIRS})
  472. list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
  473. endif()
  474. endif()
  475. #libSSH2
  476. option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
  477. mark_as_advanced(CMAKE_USE_LIBSSH2)
  478. set(USE_LIBSSH2 OFF)
  479. set(HAVE_LIBSSH2 OFF)
  480. set(HAVE_LIBSSH2_H OFF)
  481. if(CMAKE_USE_LIBSSH2)
  482. find_package(LibSSH2)
  483. if(LIBSSH2_FOUND)
  484. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  485. set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
  486. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  487. include_directories("${LIBSSH2_INCLUDE_DIR}")
  488. set(HAVE_LIBSSH2 ON)
  489. set(USE_LIBSSH2 ON)
  490. # find_package has already found the headers
  491. set(HAVE_LIBSSH2_H ON)
  492. set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
  493. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
  494. # now check for specific libssh2 symbols as they were added in different versions
  495. set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
  496. check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
  497. check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
  498. check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
  499. check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
  500. check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
  501. set(CMAKE_EXTRA_INCLUDE_FILES "")
  502. endif()
  503. endif()
  504. option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
  505. mark_as_advanced(CMAKE_USE_GSSAPI)
  506. if(CMAKE_USE_GSSAPI)
  507. find_package(GSS)
  508. set(HAVE_GSSAPI ${GSS_FOUND})
  509. if(GSS_FOUND)
  510. message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
  511. list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
  512. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  513. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  514. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  515. if(GSS_FLAVOUR STREQUAL "Heimdal")
  516. set(HAVE_GSSHEIMDAL ON)
  517. else() # MIT
  518. set(HAVE_GSSMIT ON)
  519. set(_INCLUDE_LIST "")
  520. if(HAVE_GSSAPI_GSSAPI_H)
  521. list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
  522. endif()
  523. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  524. list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
  525. endif()
  526. if(HAVE_GSSAPI_GSSAPI_KRB5_H)
  527. list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
  528. endif()
  529. string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
  530. string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
  531. foreach(_dir ${GSS_LINK_DIRECTORIES})
  532. set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
  533. endforeach()
  534. set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
  535. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  536. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  537. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  538. set(HAVE_OLD_GSSMIT ON)
  539. endif()
  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("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
  1037. _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
  1038. _add_if("DarwinSSL" SSL_ENABLED AND USE_DARWINSSL)
  1039. _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
  1040. _add_if("IPv6" ENABLE_IPV6)
  1041. _add_if("unix-sockets" USE_UNIX_SOCKETS)
  1042. _add_if("libz" HAVE_LIBZ)
  1043. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
  1044. _add_if("IDN" HAVE_LIBIDN2)
  1045. _add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
  1046. ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
  1047. # TODO SSP1 (WinSSL) check is missing
  1048. _add_if("SSPI" USE_WINDOWS_SSPI)
  1049. _add_if("GSS-API" HAVE_GSSAPI)
  1050. # TODO SSP1 missing for SPNEGO
  1051. _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1052. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1053. _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1054. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1055. # NTLM support requires crypto function adaptions from various SSL libs
  1056. # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
  1057. if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_DARWINSSL OR USE_MBEDTLS))
  1058. _add_if("NTLM" 1)
  1059. # TODO missing option (autoconf: --enable-ntlm-wb)
  1060. _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
  1061. endif()
  1062. # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
  1063. _add_if("TLS-SRP" USE_TLS_SRP)
  1064. # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
  1065. _add_if("HTTP2" USE_NGHTTP2)
  1066. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1067. message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
  1068. # Clear list and try to detect available protocols
  1069. set(_items)
  1070. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1071. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
  1072. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1073. _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
  1074. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1075. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1076. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1077. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1078. # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
  1079. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1080. ((USE_OPENLDAP AND SSL_ENABLED) OR
  1081. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1082. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1083. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1084. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1085. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1086. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
  1087. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1088. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
  1089. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1090. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
  1091. _add_if("SCP" USE_LIBSSH2)
  1092. _add_if("SFTP" USE_LIBSSH2)
  1093. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1094. _add_if("RTMP" USE_LIBRTMP)
  1095. list(SORT _items)
  1096. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1097. message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
  1098. # curl-config needs the following options to be set.
  1099. set(CC "${CMAKE_C_COMPILER}")
  1100. # TODO probably put a -D... options here?
  1101. set(CONFIGURE_OPTIONS "")
  1102. # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
  1103. set(CPPFLAG_CURL_STATICLIB "")
  1104. set(CURLVERSION "${CURL_VERSION}")
  1105. if(BUILD_SHARED_LIBS)
  1106. set(ENABLE_SHARED "yes")
  1107. set(ENABLE_STATIC "no")
  1108. else()
  1109. set(ENABLE_SHARED "no")
  1110. set(ENABLE_STATIC "yes")
  1111. endif()
  1112. set(exec_prefix "\${prefix}")
  1113. set(includedir "\${prefix}/include")
  1114. set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  1115. set(LIBCURL_LIBS "")
  1116. set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
  1117. foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
  1118. if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
  1119. set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
  1120. else()
  1121. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
  1122. endif()
  1123. endforeach()
  1124. # "a" (Linux) or "lib" (Windows)
  1125. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1126. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1127. # Set this to "yes" to append all libraries on which -lcurl is dependent
  1128. set(REQUIRE_LIB_DEPS "no")
  1129. # SUPPORT_FEATURES
  1130. # SUPPORT_PROTOCOLS
  1131. set(VERSIONNUM "${CURL_VERSION_NUM}")
  1132. # Finally generate a "curl-config" matching this config
  1133. # Use:
  1134. # * ENABLE_SHARED
  1135. # * ENABLE_STATIC
  1136. configure_file("${CURL_SOURCE_DIR}/curl-config.in"
  1137. "${CURL_BINARY_DIR}/curl-config" @ONLY)
  1138. install(FILES "${CURL_BINARY_DIR}/curl-config"
  1139. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1140. PERMISSIONS
  1141. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1142. GROUP_READ GROUP_EXECUTE
  1143. WORLD_READ WORLD_EXECUTE)
  1144. # Finally generate a pkg-config file matching this config
  1145. configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
  1146. "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
  1147. install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
  1148. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1149. # install headers
  1150. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  1151. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  1152. FILES_MATCHING PATTERN "*.h")
  1153. include(CMakePackageConfigHelpers)
  1154. write_basic_package_version_file(
  1155. "${version_config}"
  1156. VERSION ${CURL_VERSION}
  1157. COMPATIBILITY SameMajorVersion
  1158. )
  1159. # Use:
  1160. # * TARGETS_EXPORT_NAME
  1161. # * PROJECT_NAME
  1162. configure_package_config_file(CMake/curl-config.cmake.in
  1163. "${project_config}"
  1164. INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1165. )
  1166. install(
  1167. EXPORT "${TARGETS_EXPORT_NAME}"
  1168. NAMESPACE "${PROJECT_NAME}::"
  1169. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1170. )
  1171. install(
  1172. FILES ${version_config} ${project_config}
  1173. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1174. )
  1175. # Workaround for MSVS10 to avoid the Dialog Hell
  1176. # FIXME: This could be removed with future version of CMake.
  1177. if(MSVC_VERSION EQUAL 1600)
  1178. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  1179. if(EXISTS "${CURL_SLN_FILENAME}")
  1180. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  1181. endif()
  1182. endif()
  1183. if(NOT TARGET uninstall)
  1184. configure_file(
  1185. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
  1186. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
  1187. IMMEDIATE @ONLY)
  1188. add_custom_target(uninstall
  1189. COMMAND ${CMAKE_COMMAND} -P
  1190. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
  1191. endif()