You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 50KB

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