CMakeLists.txt 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  1. # Set curl options as needed for CMake build
  2. set(BUILD_CURL_EXE OFF CACHE INTERNAL "No curl exe")
  3. set(BUILD_DASHBOARD_REPORTS OFF CACHE INTERNAL "No curl dashboard reports")
  4. set(BUILD_RELEASE_DEBUG_DIRS OFF CACHE INTERNAL "No curl release/debug dirs")
  5. set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Build shared libraries")
  6. set(CMAKE_USE_GSSAPI OFF CACHE INTERNAL "Disable curl gssapi")
  7. set(CMAKE_USE_LIBSSH2 OFF CACHE INTERNAL "Disable curl libssh2")
  8. set(CMAKE_USE_OPENLDAP OFF CACHE INTERNAL "No curl OpenLDAP")
  9. set(CURL_DISABLE_COOKIES OFF CACHE INTERNAL "Do not disable curl cookie support")
  10. set(CURL_DISABLE_CRYPTO_AUTH OFF CACHE INTERNAL "Do not disable curl crypto auth")
  11. set(CURL_DISABLE_DICT ON CACHE INTERNAL "Disable curl dict protocol?")
  12. set(CURL_DISABLE_FILE OFF CACHE INTERNAL "Disable curl file protocol?")
  13. set(CURL_DISABLE_FTP OFF CACHE INTERNAL "Disable curl ftp protocol?")
  14. set(CURL_DISABLE_GOPHER ON CACHE INTERNAL "Disable curl gopher protocol?")
  15. set(CURL_DISABLE_HTTP OFF CACHE INTERNAL "Disable curl http protocol?")
  16. set(CURL_DISABLE_IMAP ON CACHE INTERNAL "Disable curl imap protocol?")
  17. set(CURL_DISABLE_LDAP ON CACHE INTERNAL "Disable curl ldap protocol?")
  18. set(CURL_DISABLE_LDAPS ON CACHE INTERNAL "Disable curl ldaps protocol?")
  19. set(CURL_DISABLE_POP3 ON CACHE INTERNAL "Disable curl pop3 protocol?")
  20. set(CURL_DISABLE_PROXY OFF CACHE INTERNAL "Do not disable curl proxy")
  21. set(CURL_DISABLE_RTSP ON CACHE INTERNAL "Disable curl rtsp protocol?")
  22. set(CURL_DISABLE_SMTP ON CACHE INTERNAL "Disable curl smtp protocol?")
  23. set(CURL_DISABLE_TELNET ON CACHE INTERNAL "Disable curl telnet protocol?")
  24. set(CURL_DISABLE_TFTP ON CACHE INTERNAL "Disable curl tftp protocol?")
  25. set(CURL_DISABLE_VERBOSE_STRINGS OFF CACHE INTERNAL "Do not disable curl verbosity")
  26. set(CURL_HIDDEN_SYMBOLS OFF CACHE INTERNAL "No curl hidden symbols")
  27. set(CURL_LTO OFF CACHE INTERNAL "Turn on compiler Link Time Optimizations")
  28. set(CURL_STATIC_CRT OFF CACHE INTERNAL "Set to ON to build libcurl with static CRT on Windows (/MT).")
  29. set(CURL_WERROR OFF CACHE INTERNAL "Turn compiler warnings into errors")
  30. set(DISABLED_THREADSAFE OFF CACHE INTERNAL "Curl can use thread-safe functions")
  31. set(ENABLE_ARES OFF CACHE INTERNAL "No curl c-ares support")
  32. set(ENABLE_CURLDEBUG OFF CACHE INTERNAL "No curl TrackMemory features")
  33. set(ENABLE_DEBUG OFF CACHE INTERNAL "No curl debug features")
  34. set(ENABLE_INET_PTON OFF CACHE INTERNAL "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.")
  35. set(ENABLE_IPV6 ON CACHE INTERNAL "Enable curl IPv6 support detection")
  36. set(ENABLE_MANUAL OFF CACHE INTERNAL "No curl built-in manual")
  37. set(ENABLE_THREADED_RESOLVER OFF CACHE INTERNAL "No curl POSIX threaded DNS lookup")
  38. set(ENABLE_UNIX_SOCKETS OFF CACHE INTERNAL "No curl Unix domain sockets support")
  39. set(HTTP_ONLY OFF CACHE INTERNAL "Curl is not http-only")
  40. set(PICKY_COMPILER OFF CACHE INTERNAL "Enable picky compiler options")
  41. set(USE_WIN32_LDAP OFF CACHE INTERNAL "No curl Windows LDAP")
  42. if(CMAKE_USE_OPENSSL)
  43. elseif(WIN32)
  44. set(CMAKE_USE_WINSSL ON CACHE INTERNAL "enable Windows native SSL/TLS")
  45. set(CURL_WINDOWS_SSPI ON CACHE INTERNAL "Use windows libraries to allow NTLM authentication without openssl")
  46. elseif(APPLE)
  47. # Use OS X SSL/TLS native implementation if available on target version.
  48. if(CMAKE_OSX_DEPLOYMENT_TARGET)
  49. set(OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
  50. else()
  51. execute_process(
  52. COMMAND sw_vers -productVersion
  53. OUTPUT_VARIABLE OSX_VERSION
  54. OUTPUT_STRIP_TRAILING_WHITESPACE
  55. )
  56. endif()
  57. if(NOT OSX_VERSION VERSION_LESS 10.6 AND
  58. CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
  59. set(CMAKE_USE_SECTRANSP ON CACHE INTERNAL "enable Apple OS native SSL/TLS")
  60. else()
  61. set(CMAKE_USE_SECTRANSP OFF CACHE INTERNAL "enable Apple OS native SSL/TLS")
  62. endif()
  63. unset(CMAKE_USE_DARWINSSL CACHE)
  64. endif()
  65. set(CMAKE_USE_MBEDTLS OFF CACHE INTERNAL "Enable mbedTLS for SSL/TLS")
  66. set(CMAKE_USE_BEARSSL OFF CACHE INTERNAL "Enable BearSSL for SSL/TLS")
  67. set(CMAKE_USE_NSS OFF CACHE INTERNAL "Enable NSS for SSL/TLS")
  68. # Windows Vista and above have inet_pton, but this will link on
  69. # older versions and then the executable will fail to launch at
  70. # runtime on older versions because no DLL provides the symbol.
  71. if(WIN32)
  72. set(HAVE_INET_PTON 0 CACHE INTERNAL "Do not use inet_pton")
  73. endif()
  74. # Starting with OSX 10.11 there is an unrelated libnetwork library which will
  75. # be picked up during curl configuration. Linking against this library is
  76. # unnecessary and breaks backward compatibility of the resulting binaries
  77. # because libnetwork is unavailable on older OSX versions.
  78. if(APPLE)
  79. set(HAVE_LIBNETWORK 0 CACHE INTERNAL "Do not use libnetwork")
  80. endif(APPLE)
  81. # Disable warnings to avoid changing 3rd party code.
  82. if(CMAKE_C_COMPILER_ID MATCHES
  83. "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
  84. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
  85. elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
  86. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
  87. endif()
  88. #***************************************************************************
  89. # _ _ ____ _
  90. # Project ___| | | | _ \| |
  91. # / __| | | | |_) | |
  92. # | (__| |_| | _ <| |___
  93. # \___|\___/|_| \_\_____|
  94. #
  95. # Copyright (C) 1998 - 2020, Daniel Stenberg, <[email protected]>, et al.
  96. #
  97. # This software is licensed as described in the file COPYING, which
  98. # you should have received as part of this distribution. The terms
  99. # are also available at https://curl.haxx.se/docs/copyright.html.
  100. #
  101. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  102. # copies of the Software, and permit persons to whom the Software is
  103. # furnished to do so, under the terms of the COPYING file.
  104. #
  105. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  106. # KIND, either express or implied.
  107. #
  108. ###########################################################################
  109. # curl/libcurl CMake script
  110. # by Tetetest and Sukender (Benoit Neil)
  111. # TODO:
  112. # The output .so file lacks the soname number which we currently have within the lib/Makefile.am file
  113. # Add full (4 or 5 libs) SSL support
  114. # 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).
  115. # Add CTests(?)
  116. # Check on all possible platforms
  117. # Test with as many configurations possible (With or without any option)
  118. # Create scripts that help keeping the CMake build system up to date (to reduce maintenance). According to Tetetest:
  119. # - lists of headers that 'configure' checks for;
  120. # - curl-specific tests (the ones that are in m4/curl-*.m4 files);
  121. # - (most obvious thing:) curl version numbers.
  122. # Add documentation subproject
  123. #
  124. # To check:
  125. # (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
  126. # (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.
  127. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
  128. include(Utilities)
  129. include(Macros)
  130. include(CMakeDependentOption)
  131. include(CheckCCompilerFlag)
  132. project(CURL C)
  133. if(0) # This code not needed for building within CMake.
  134. message(WARNING "the curl cmake build system is poorly maintained. Be aware")
  135. endif()
  136. file(STRINGS ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS REGEX "#define LIBCURL_VERSION( |_NUM )")
  137. string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
  138. CURL_VERSION ${CURL_VERSION_H_CONTENTS})
  139. string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
  140. string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
  141. CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
  142. string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
  143. # Setup package meta-data
  144. # SET(PACKAGE "curl")
  145. if(0) # This code not needed for building within CMake.
  146. message(STATUS "curl version=[${CURL_VERSION}]")
  147. endif()
  148. # SET(PACKAGE_TARNAME "curl")
  149. # SET(PACKAGE_NAME "curl")
  150. # SET(PACKAGE_VERSION "-")
  151. # SET(PACKAGE_STRING "curl-")
  152. # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/")
  153. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  154. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  155. include_directories(${CURL_SOURCE_DIR}/include)
  156. option(CURL_WERROR "Turn compiler warnings into errors" OFF)
  157. option(PICKY_COMPILER "Enable picky compiler options" ON)
  158. option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
  159. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  160. option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
  161. if(WIN32)
  162. option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
  163. 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)
  164. if(0) # This code not needed for building within CMake.
  165. set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
  166. if(CURL_TARGET_WINDOWS_VERSION)
  167. add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
  168. elseif(ENABLE_INET_PTON)
  169. # _WIN32_WINNT_VISTA (0x0600)
  170. add_definitions(-D_WIN32_WINNT=0x0600)
  171. else()
  172. # _WIN32_WINNT_WINXP (0x0501)
  173. add_definitions(-D_WIN32_WINNT=0x0501)
  174. endif()
  175. endif()
  176. endif()
  177. option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)
  178. if(0) # This code not needed for building within CMake.
  179. cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
  180. ON "NOT ENABLE_ARES"
  181. OFF)
  182. endif()
  183. option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
  184. option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
  185. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
  186. if(PICKY_COMPILER)
  187. 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)
  188. # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
  189. # test result in.
  190. string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
  191. check_c_compiler_flag(${_CCOPT} ${_optvarname})
  192. if(${_optvarname})
  193. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
  194. endif()
  195. endforeach()
  196. endif()
  197. endif()
  198. if(ENABLE_DEBUG)
  199. # DEBUGBUILD will be defined only for Debug builds
  200. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
  201. set(ENABLE_CURLDEBUG ON)
  202. endif()
  203. if(ENABLE_CURLDEBUG)
  204. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
  205. endif()
  206. if(0) # This code not needed for building within CMake.
  207. # For debug libs and exes, add "-d" postfix
  208. if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
  209. set(CMAKE_DEBUG_POSTFIX "-d")
  210. endif()
  211. endif()
  212. # initialize CURL_LIBS
  213. set(CURL_LIBS "")
  214. if(ENABLE_ARES)
  215. set(USE_ARES 1)
  216. find_package(CARES REQUIRED)
  217. list(APPEND CURL_LIBS ${CARES_LIBRARY})
  218. endif()
  219. if(0) # This code not needed for building within CMake.
  220. include(CurlSymbolHiding)
  221. endif()
  222. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  223. mark_as_advanced(HTTP_ONLY)
  224. option(CURL_DISABLE_FTP "disables FTP" OFF)
  225. mark_as_advanced(CURL_DISABLE_FTP)
  226. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  227. mark_as_advanced(CURL_DISABLE_LDAP)
  228. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  229. mark_as_advanced(CURL_DISABLE_TELNET)
  230. option(CURL_DISABLE_DICT "disables DICT" OFF)
  231. mark_as_advanced(CURL_DISABLE_DICT)
  232. option(CURL_DISABLE_FILE "disables FILE" OFF)
  233. mark_as_advanced(CURL_DISABLE_FILE)
  234. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  235. mark_as_advanced(CURL_DISABLE_TFTP)
  236. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  237. mark_as_advanced(CURL_DISABLE_HTTP)
  238. option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
  239. mark_as_advanced(CURL_DISABLE_LDAPS)
  240. option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
  241. mark_as_advanced(CURL_DISABLE_RTSP)
  242. option(CURL_DISABLE_PROXY "to disable proxy" OFF)
  243. mark_as_advanced(CURL_DISABLE_PROXY)
  244. option(CURL_DISABLE_POP3 "to disable POP3" OFF)
  245. mark_as_advanced(CURL_DISABLE_POP3)
  246. option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
  247. mark_as_advanced(CURL_DISABLE_IMAP)
  248. option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
  249. mark_as_advanced(CURL_DISABLE_SMTP)
  250. option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
  251. mark_as_advanced(CURL_DISABLE_GOPHER)
  252. if(HTTP_ONLY)
  253. set(CURL_DISABLE_FTP ON)
  254. set(CURL_DISABLE_LDAP ON)
  255. set(CURL_DISABLE_LDAPS ON)
  256. set(CURL_DISABLE_TELNET ON)
  257. set(CURL_DISABLE_DICT ON)
  258. set(CURL_DISABLE_FILE ON)
  259. set(CURL_DISABLE_TFTP ON)
  260. set(CURL_DISABLE_RTSP ON)
  261. set(CURL_DISABLE_POP3 ON)
  262. set(CURL_DISABLE_IMAP ON)
  263. set(CURL_DISABLE_SMB ON)
  264. set(CURL_DISABLE_SMTP ON)
  265. set(CURL_DISABLE_GOPHER ON)
  266. endif()
  267. option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
  268. mark_as_advanced(CURL_DISABLE_COOKIES)
  269. option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
  270. mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
  271. option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
  272. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  273. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
  274. mark_as_advanced(ENABLE_IPV6)
  275. if(ENABLE_IPV6 AND NOT WIN32)
  276. include(CheckStructHasMember)
  277. check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
  278. HAVE_SOCKADDR_IN6_SIN6_ADDR)
  279. check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
  280. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
  281. if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
  282. message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
  283. # Force the feature off as this name is used as guard macro...
  284. set(ENABLE_IPV6 OFF
  285. CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
  286. endif()
  287. endif()
  288. if(0) # This code not needed for building within CMake.
  289. # Required for building manual, docs, tests
  290. curl_nroff_check()
  291. find_package(Perl)
  292. cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
  293. ON "NROFF_USEFUL;PERL_FOUND"
  294. OFF)
  295. if(NOT PERL_FOUND)
  296. message(STATUS "Perl not found, testing disabled.")
  297. set(BUILD_TESTING OFF)
  298. endif()
  299. if(ENABLE_MANUAL)
  300. set(USE_MANUAL ON)
  301. endif()
  302. endif()
  303. # We need ansi c-flags, especially on HP
  304. set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  305. set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
  306. if(CURL_STATIC_CRT)
  307. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  308. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  309. endif()
  310. # Disable warnings on Borland to avoid changing 3rd party code.
  311. if(BORLAND)
  312. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  313. endif()
  314. # If we are on AIX, do the _ALL_SOURCE magic
  315. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  316. set(_ALL_SOURCE 1)
  317. endif()
  318. # Include all the necessary files for macros
  319. include(CMakePushCheckState)
  320. include(CheckFunctionExists)
  321. include(CheckIncludeFile)
  322. include(CheckIncludeFiles)
  323. include(CheckLibraryExists)
  324. include(CheckSymbolExists)
  325. include(CheckTypeSize)
  326. include(CheckCSourceCompiles)
  327. # On windows preload settings
  328. if(WIN32)
  329. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
  330. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  331. endif()
  332. if(ENABLE_THREADED_RESOLVER)
  333. find_package(Threads REQUIRED)
  334. if(WIN32)
  335. set(USE_THREADS_WIN32 ON)
  336. else()
  337. set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
  338. set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
  339. endif()
  340. set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
  341. endif()
  342. # Check for all needed libraries
  343. if(0) # This code not needed for building within CMake.
  344. check_library_exists_concat("${CMAKE_DL_LIBS}" dlopen HAVE_LIBDL)
  345. else()
  346. # Use the cmake-defined dl libs as dl is should not be used
  347. # on HPUX, but rather dld this avoids a warning
  348. list(APPEND CURL_LIBS ${CMAKE_DL_LIBS})
  349. endif()
  350. check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
  351. check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
  352. # Yellowtab Zeta needs different libraries than BeOS 5.
  353. if(BEOS)
  354. set(NOT_NEED_LIBNSL 1)
  355. check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
  356. check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
  357. endif()
  358. check_library_exists_concat("network" recv HAVE_LIBNETWORK)
  359. if(NOT NOT_NEED_LIBNSL)
  360. check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
  361. endif()
  362. check_function_exists(gethostname HAVE_GETHOSTNAME)
  363. if(WIN32)
  364. check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
  365. check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
  366. list(APPEND CURL_LIBS "advapi32")
  367. endif()
  368. # check SSL libraries
  369. # TODO support GnuTLS and WolfSSL
  370. if(APPLE)
  371. option(CMAKE_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF)
  372. endif()
  373. if(WIN32)
  374. option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
  375. cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
  376. CMAKE_USE_WINSSL OFF)
  377. endif()
  378. option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
  379. option(CMAKE_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF)
  380. option(CMAKE_USE_NSS "Enable NSS for SSL/TLS" OFF)
  381. set(openssl_default ON)
  382. if(WIN32 OR CMAKE_USE_SECTRANSP OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS OR CMAKE_USE_NSS)
  383. set(openssl_default OFF)
  384. endif()
  385. count_true(enabled_ssl_options_count
  386. CMAKE_USE_WINSSL
  387. CMAKE_USE_SECTRANSP
  388. CMAKE_USE_OPENSSL
  389. CMAKE_USE_MBEDTLS
  390. CMAKE_USE_BEARSSL
  391. CMAKE_USE_NSS
  392. )
  393. if(enabled_ssl_options_count GREATER "1")
  394. set(CURL_WITH_MULTI_SSL ON)
  395. endif()
  396. if(CMAKE_USE_WINSSL)
  397. set(SSL_ENABLED ON)
  398. set(USE_SCHANNEL ON) # Windows native SSL/TLS support
  399. set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
  400. list(APPEND CURL_LIBS "crypt32")
  401. endif()
  402. if(CURL_WINDOWS_SSPI)
  403. set(USE_WINDOWS_SSPI ON)
  404. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
  405. endif()
  406. if(CMAKE_USE_DARWINSSL)
  407. message(FATAL_ERROR "The cmake option CMAKE_USE_DARWINSSL was renamed to CMAKE_USE_SECTRANSP.")
  408. endif()
  409. if(CMAKE_USE_SECTRANSP)
  410. find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
  411. if(NOT COREFOUNDATION_FRAMEWORK)
  412. message(FATAL_ERROR "CoreFoundation framework not found")
  413. endif()
  414. find_library(SECURITY_FRAMEWORK "Security")
  415. if(NOT SECURITY_FRAMEWORK)
  416. message(FATAL_ERROR "Security framework not found")
  417. endif()
  418. set(SSL_ENABLED ON)
  419. set(USE_SECTRANSP ON)
  420. list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
  421. endif()
  422. if(CMAKE_USE_OPENSSL)
  423. find_package(OpenSSL)
  424. if(NOT OpenSSL_FOUND)
  425. message(FATAL_ERROR
  426. "Could not find OpenSSL. Install an OpenSSL development package or "
  427. "configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.")
  428. endif()
  429. set(SSL_ENABLED ON)
  430. set(USE_OPENSSL ON)
  431. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  432. include_directories(${OPENSSL_INCLUDE_DIR})
  433. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  434. check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  435. check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
  436. check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  437. check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  438. check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  439. check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
  440. check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  441. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  442. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  443. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  444. # Optionally build with a specific CA cert bundle.
  445. if(CURL_CA_BUNDLE)
  446. add_definitions(-DCURL_CA_BUNDLE="${CURL_CA_BUNDLE}")
  447. endif()
  448. # Optionally build with a specific CA cert dir.
  449. if(CURL_CA_PATH)
  450. add_definitions(-DCURL_CA_PATH="${CURL_CA_PATH}")
  451. endif()
  452. endif()
  453. if(CMAKE_USE_MBEDTLS)
  454. find_package(MbedTLS REQUIRED)
  455. set(SSL_ENABLED ON)
  456. set(USE_MBEDTLS ON)
  457. list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
  458. include_directories(${MBEDTLS_INCLUDE_DIRS})
  459. endif()
  460. if(CMAKE_USE_BEARSSL)
  461. find_package(BearSSL REQUIRED)
  462. set(SSL_ENABLED ON)
  463. set(USE_BEARSSL ON)
  464. list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
  465. include_directories(${BEARSSL_INCLUDE_DIRS})
  466. endif()
  467. if(CMAKE_USE_NSS)
  468. find_package(NSS REQUIRED)
  469. include_directories(${NSS_INCLUDE_DIRS})
  470. list(APPEND CURL_LIBS ${NSS_LIBRARIES})
  471. set(SSL_ENABLED ON)
  472. set(USE_NSS ON)
  473. cmake_push_check_state()
  474. set(CMAKE_REQUIRED_INCLUDES ${NSS_INCLUDE_DIRS})
  475. set(CMAKE_REQUIRED_LIBRARIES ${NSS_LIBRARIES})
  476. check_symbol_exists(PK11_CreateManagedGenericObject "pk11pub.h" HAVE_PK11_CREATEMANAGEDGENERICOBJECT)
  477. cmake_pop_check_state()
  478. endif()
  479. option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
  480. if(USE_NGHTTP2)
  481. find_package(NGHTTP2 REQUIRED)
  482. include_directories(${NGHTTP2_INCLUDE_DIRS})
  483. list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
  484. endif()
  485. if(WIN32)
  486. set(USE_WIN32_CRYPTO ON)
  487. endif()
  488. if(NOT CURL_DISABLE_LDAP)
  489. if(WIN32)
  490. option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
  491. if(USE_WIN32_LDAP)
  492. check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
  493. if(NOT HAVE_WLDAP32)
  494. set(USE_WIN32_LDAP OFF)
  495. endif()
  496. endif()
  497. endif()
  498. option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
  499. mark_as_advanced(CMAKE_USE_OPENLDAP)
  500. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  501. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  502. if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
  503. message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
  504. endif()
  505. # Now that we know, we're not using windows LDAP...
  506. if(USE_WIN32_LDAP)
  507. check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
  508. check_include_file_concat("winber.h" HAVE_WINBER_H)
  509. else()
  510. # Check for LDAP
  511. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  512. check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
  513. check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
  514. set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
  515. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  516. if(CMAKE_LDAP_INCLUDE_DIR)
  517. list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  518. endif()
  519. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  520. check_include_file_concat("lber.h" HAVE_LBER_H)
  521. if(NOT HAVE_LDAP_H)
  522. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  523. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  524. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  525. elseif(NOT HAVE_LIBLDAP)
  526. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  527. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  528. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  529. else()
  530. if(CMAKE_USE_OPENLDAP)
  531. set(USE_OPENLDAP ON)
  532. endif()
  533. if(CMAKE_LDAP_INCLUDE_DIR)
  534. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  535. endif()
  536. set(NEED_LBER_H ON)
  537. set(_HEADER_LIST)
  538. if(HAVE_WINDOWS_H)
  539. list(APPEND _HEADER_LIST "windows.h")
  540. endif()
  541. if(HAVE_SYS_TYPES_H)
  542. list(APPEND _HEADER_LIST "sys/types.h")
  543. endif()
  544. list(APPEND _HEADER_LIST "ldap.h")
  545. set(_SRC_STRING "")
  546. foreach(_HEADER ${_HEADER_LIST})
  547. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  548. endforeach()
  549. set(_SRC_STRING
  550. "
  551. ${_INCLUDE_STRING}
  552. int main(int argc, char ** argv)
  553. {
  554. BerValue *bvp = NULL;
  555. BerElement *bep = ber_init(bvp);
  556. ber_free(bep, 1);
  557. return 0;
  558. }"
  559. )
  560. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
  561. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  562. if(HAVE_LIBLBER)
  563. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  564. endif()
  565. check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
  566. unset(CMAKE_REQUIRED_LIBRARIES)
  567. if(NOT_NEED_LBER_H)
  568. set(NEED_LBER_H OFF)
  569. else()
  570. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  571. endif()
  572. endif()
  573. endif()
  574. endif()
  575. # No ldap, no ldaps.
  576. if(CURL_DISABLE_LDAP)
  577. if(NOT CURL_DISABLE_LDAPS)
  578. message(STATUS "LDAP needs to be enabled to support LDAPS")
  579. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  580. endif()
  581. endif()
  582. if(NOT CURL_DISABLE_LDAPS)
  583. check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
  584. check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
  585. endif()
  586. # Check for idn
  587. check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
  588. # Check for symbol dlopen (same as HAVE_LIBDL)
  589. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  590. if(0) # This code not needed for building within CMake.
  591. option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
  592. set(HAVE_LIBZ OFF)
  593. set(HAVE_ZLIB_H OFF)
  594. set(USE_ZLIB OFF)
  595. if(CURL_ZLIB)
  596. find_package(ZLIB QUIET)
  597. if(ZLIB_FOUND)
  598. set(HAVE_ZLIB_H ON)
  599. set(HAVE_LIBZ ON)
  600. set(USE_ZLIB ON)
  601. # Depend on ZLIB via imported targets if supported by the running
  602. # version of CMake. This allows our dependents to get our dependencies
  603. # transitively.
  604. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  605. list(APPEND CURL_LIBS ZLIB::ZLIB)
  606. else()
  607. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  608. include_directories(${ZLIB_INCLUDE_DIRS})
  609. endif()
  610. list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
  611. endif()
  612. endif()
  613. endif()
  614. #-----------------------------------------------------------------------------
  615. # CMake-specific curl code.
  616. if(CURL_SPECIAL_LIBZ)
  617. set(CURL_LIBS ${CURL_LIBS} "${CURL_SPECIAL_LIBZ}")
  618. include_directories(${CURL_SPECIAL_LIBZ_INCLUDES})
  619. set(HAVE_LIBZ 0)
  620. set(HAVE_ZLIB_H 0)
  621. endif()
  622. option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
  623. set(HAVE_BROTLI OFF)
  624. if(CURL_BROTLI)
  625. find_package(Brotli QUIET)
  626. if(BROTLI_FOUND)
  627. set(HAVE_BROTLI ON)
  628. list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
  629. include_directories(${BROTLI_INCLUDE_DIRS})
  630. list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
  631. endif()
  632. endif()
  633. #libSSH2
  634. option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
  635. mark_as_advanced(CMAKE_USE_LIBSSH2)
  636. set(USE_LIBSSH2 OFF)
  637. set(HAVE_LIBSSH2 OFF)
  638. set(HAVE_LIBSSH2_H OFF)
  639. if(CMAKE_USE_LIBSSH2)
  640. find_package(LibSSH2)
  641. if(LIBSSH2_FOUND)
  642. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  643. set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
  644. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  645. include_directories("${LIBSSH2_INCLUDE_DIR}")
  646. set(HAVE_LIBSSH2 ON)
  647. set(USE_LIBSSH2 ON)
  648. # find_package has already found the headers
  649. set(HAVE_LIBSSH2_H ON)
  650. set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
  651. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
  652. # now check for specific libssh2 symbols as they were added in different versions
  653. set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
  654. check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
  655. check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
  656. check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
  657. check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
  658. check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
  659. set(CMAKE_EXTRA_INCLUDE_FILES "")
  660. unset(CMAKE_REQUIRED_LIBRARIES)
  661. endif()
  662. endif()
  663. option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
  664. mark_as_advanced(CMAKE_USE_GSSAPI)
  665. if(CMAKE_USE_GSSAPI)
  666. find_package(GSS)
  667. set(HAVE_GSSAPI ${GSS_FOUND})
  668. if(GSS_FOUND)
  669. message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
  670. list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
  671. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  672. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  673. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  674. if(GSS_FLAVOUR STREQUAL "Heimdal")
  675. set(HAVE_GSSHEIMDAL ON)
  676. else() # MIT
  677. set(HAVE_GSSMIT ON)
  678. set(_INCLUDE_LIST "")
  679. if(HAVE_GSSAPI_GSSAPI_H)
  680. list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
  681. endif()
  682. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  683. list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
  684. endif()
  685. if(HAVE_GSSAPI_GSSAPI_KRB5_H)
  686. list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
  687. endif()
  688. string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
  689. string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
  690. foreach(_dir ${GSS_LINK_DIRECTORIES})
  691. set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
  692. endforeach()
  693. set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
  694. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  695. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  696. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  697. set(HAVE_OLD_GSSMIT ON)
  698. endif()
  699. unset(CMAKE_REQUIRED_LIBRARIES)
  700. endif()
  701. include_directories(${GSS_INCLUDE_DIR})
  702. link_directories(${GSS_LINK_DIRECTORIES})
  703. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
  704. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  705. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
  706. list(APPEND CURL_LIBS ${GSS_LIBRARIES})
  707. else()
  708. message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
  709. endif()
  710. endif()
  711. option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
  712. if(ENABLE_UNIX_SOCKETS)
  713. include(CheckStructHasMember)
  714. check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
  715. else()
  716. unset(USE_UNIX_SOCKETS CACHE)
  717. endif()
  718. if(0) # This code not needed for building within CMake.
  719. #
  720. # CA handling
  721. #
  722. set(CURL_CA_BUNDLE "auto" CACHE STRING
  723. "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  724. set(CURL_CA_FALLBACK OFF CACHE BOOL
  725. "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
  726. set(CURL_CA_PATH "auto" CACHE STRING
  727. "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
  728. if("${CURL_CA_BUNDLE}" STREQUAL "")
  729. message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
  730. elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
  731. unset(CURL_CA_BUNDLE CACHE)
  732. elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
  733. unset(CURL_CA_BUNDLE CACHE)
  734. set(CURL_CA_BUNDLE_AUTODETECT TRUE)
  735. else()
  736. set(CURL_CA_BUNDLE_SET TRUE)
  737. endif()
  738. if("${CURL_CA_PATH}" STREQUAL "")
  739. message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
  740. elseif("${CURL_CA_PATH}" STREQUAL "none")
  741. unset(CURL_CA_PATH CACHE)
  742. elseif("${CURL_CA_PATH}" STREQUAL "auto")
  743. unset(CURL_CA_PATH CACHE)
  744. if(NOT USE_NSS)
  745. set(CURL_CA_PATH_AUTODETECT TRUE)
  746. endif()
  747. else()
  748. set(CURL_CA_PATH_SET TRUE)
  749. endif()
  750. if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
  751. # Skip autodetection of unset CA path because CA bundle is set explicitly
  752. elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
  753. # Skip autodetection of unset CA bundle because CA path is set explicitly
  754. elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
  755. # first try autodetecting a CA bundle, then a CA path
  756. if(CURL_CA_BUNDLE_AUTODETECT)
  757. set(SEARCH_CA_BUNDLE_PATHS
  758. /etc/ssl/certs/ca-certificates.crt
  759. /etc/pki/tls/certs/ca-bundle.crt
  760. /usr/share/ssl/certs/ca-bundle.crt
  761. /usr/local/share/certs/ca-root-nss.crt
  762. /etc/ssl/cert.pem)
  763. foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
  764. if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
  765. message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
  766. set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
  767. set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  768. break()
  769. endif()
  770. endforeach()
  771. endif()
  772. if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
  773. if(EXISTS "/etc/ssl/certs")
  774. set(CURL_CA_PATH "/etc/ssl/certs")
  775. set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
  776. endif()
  777. endif()
  778. endif()
  779. if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
  780. message(FATAL_ERROR
  781. "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
  782. "Set CURL_CA_PATH=none or enable one of those TLS backends.")
  783. endif()
  784. endif()
  785. # Check for header files
  786. if(NOT UNIX)
  787. check_include_file_concat("windows.h" HAVE_WINDOWS_H)
  788. check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
  789. check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
  790. check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
  791. if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL)
  792. set(CURL_LIBS ${CURL_LIBS} "crypt32")
  793. endif()
  794. else()
  795. set(HAVE_WINDOWS_H 0)
  796. set(HAVE_WINSOCK_H 0)
  797. set(HAVE_WS2TCPIP_H 0)
  798. set(HAVE_WINSOCK2_H 0)
  799. endif()
  800. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  801. check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
  802. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  803. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  804. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  805. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  806. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  807. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  808. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  809. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  810. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  811. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  812. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  813. check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
  814. check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
  815. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  816. check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
  817. check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
  818. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  819. check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
  820. check_include_file_concat("assert.h" HAVE_ASSERT_H)
  821. check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
  822. check_include_file_concat("des.h" HAVE_DES_H)
  823. check_include_file_concat("err.h" HAVE_ERR_H)
  824. check_include_file_concat("errno.h" HAVE_ERRNO_H)
  825. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  826. check_include_file_concat("idn2.h" HAVE_IDN2_H)
  827. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  828. check_include_file_concat("io.h" HAVE_IO_H)
  829. check_include_file_concat("krb.h" HAVE_KRB_H)
  830. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  831. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  832. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  833. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  834. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  835. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
  836. check_include_file_concat("pem.h" HAVE_PEM_H)
  837. check_include_file_concat("poll.h" HAVE_POLL_H)
  838. check_include_file_concat("pwd.h" HAVE_PWD_H)
  839. check_include_file_concat("rsa.h" HAVE_RSA_H)
  840. check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
  841. check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
  842. check_include_file_concat("signal.h" HAVE_SIGNAL_H)
  843. check_include_file_concat("ssl.h" HAVE_SSL_H)
  844. check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
  845. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  846. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  847. check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
  848. check_include_file_concat("string.h" HAVE_STRING_H)
  849. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  850. check_include_file_concat("stropts.h" HAVE_STROPTS_H)
  851. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  852. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  853. check_include_file_concat("time.h" HAVE_TIME_H)
  854. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  855. check_include_file_concat("utime.h" HAVE_UTIME_H)
  856. check_include_file_concat("x509.h" HAVE_X509_H)
  857. check_include_file_concat("process.h" HAVE_PROCESS_H)
  858. check_include_file_concat("stddef.h" HAVE_STDDEF_H)
  859. check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
  860. check_include_file_concat("malloc.h" HAVE_MALLOC_H)
  861. check_include_file_concat("memory.h" HAVE_MEMORY_H)
  862. check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
  863. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  864. check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
  865. check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
  866. check_type_size(size_t SIZEOF_SIZE_T)
  867. check_type_size(ssize_t SIZEOF_SSIZE_T)
  868. check_type_size("long long" SIZEOF_LONG_LONG)
  869. check_type_size("long" SIZEOF_LONG)
  870. check_type_size("short" SIZEOF_SHORT)
  871. check_type_size("int" SIZEOF_INT)
  872. check_type_size("__int64" SIZEOF___INT64)
  873. check_type_size("time_t" SIZEOF_TIME_T)
  874. if(HAVE_SIZEOF_LONG_LONG)
  875. set(HAVE_LONGLONG 1)
  876. set(HAVE_LL 1)
  877. endif()
  878. find_file(RANDOM_FILE urandom /dev)
  879. mark_as_advanced(RANDOM_FILE)
  880. # Check for some functions that are used
  881. if(HAVE_LIBWS2_32)
  882. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  883. elseif(HAVE_LIBSOCKET)
  884. set(CMAKE_REQUIRED_LIBRARIES socket)
  885. elseif(HAVE_LIBNETWORK)
  886. set(CMAKE_REQUIRED_LIBRARIES network)
  887. endif()
  888. check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
  889. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  890. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  891. check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
  892. check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
  893. check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
  894. check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
  895. check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
  896. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  897. check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
  898. check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
  899. check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
  900. check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
  901. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  902. if(NOT HAVE_STRNCMPI)
  903. set(HAVE_STRCMPI)
  904. endif()
  905. check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
  906. check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
  907. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  908. check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
  909. check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
  910. check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
  911. check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
  912. check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
  913. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  914. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  915. check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
  916. check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
  917. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  918. check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
  919. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  920. check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
  921. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  922. check_symbol_exists(usleep "${CURL_INCLUDES}" HAVE_USLEEP)
  923. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  924. check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
  925. check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
  926. check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
  927. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  928. check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
  929. check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
  930. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  931. set(HAVE_SIGNAL 1)
  932. endif()
  933. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  934. check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
  935. check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
  936. check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
  937. check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
  938. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  939. check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
  940. check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
  941. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  942. check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
  943. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  944. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  945. check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
  946. check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
  947. check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
  948. check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
  949. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  950. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  951. check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
  952. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  953. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  954. check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
  955. check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
  956. check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
  957. check_symbol_exists(inet_pton "${CURL_INCLUDES}" HAVE_INET_PTON)
  958. check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
  959. if(HAVE_FSETXATTR)
  960. foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
  961. curl_internal_test(${CURL_TEST})
  962. endforeach()
  963. endif()
  964. # sigaction and sigsetjmp are special. Use special mechanism for
  965. # detecting those, but only if previous attempt failed.
  966. if(HAVE_SIGNAL_H)
  967. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  968. endif()
  969. if(NOT HAVE_SIGSETJMP)
  970. if(HAVE_SETJMP_H)
  971. check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
  972. if(HAVE_MACRO_SIGSETJMP)
  973. set(HAVE_SIGSETJMP 1)
  974. endif()
  975. endif()
  976. endif()
  977. # If there is no stricmp(), do not allow LDAP to parse URLs
  978. if(NOT HAVE_STRICMP)
  979. set(HAVE_LDAP_URL_PARSE 1)
  980. endif()
  981. # Do curl specific tests
  982. foreach(CURL_TEST
  983. HAVE_FCNTL_O_NONBLOCK
  984. HAVE_IOCTLSOCKET
  985. HAVE_IOCTLSOCKET_CAMEL
  986. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  987. HAVE_IOCTLSOCKET_FIONBIO
  988. HAVE_IOCTL_FIONBIO
  989. HAVE_IOCTL_SIOCGIFADDR
  990. HAVE_SETSOCKOPT_SO_NONBLOCK
  991. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
  992. TIME_WITH_SYS_TIME
  993. HAVE_O_NONBLOCK
  994. HAVE_GETHOSTBYADDR_R_5
  995. HAVE_GETHOSTBYADDR_R_7
  996. HAVE_GETHOSTBYADDR_R_8
  997. HAVE_GETHOSTBYADDR_R_5_REENTRANT
  998. HAVE_GETHOSTBYADDR_R_7_REENTRANT
  999. HAVE_GETHOSTBYADDR_R_8_REENTRANT
  1000. HAVE_GETHOSTBYNAME_R_3
  1001. HAVE_GETHOSTBYNAME_R_5
  1002. HAVE_GETHOSTBYNAME_R_6
  1003. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  1004. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  1005. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  1006. HAVE_IN_ADDR_T
  1007. HAVE_BOOL_T
  1008. STDC_HEADERS
  1009. RETSIGTYPE_TEST
  1010. HAVE_INET_NTOA_R_DECL
  1011. HAVE_INET_NTOA_R_DECL_REENTRANT
  1012. HAVE_GETADDRINFO
  1013. HAVE_FILE_OFFSET_BITS
  1014. HAVE_VARIADIC_MACROS_C99
  1015. HAVE_VARIADIC_MACROS_GCC
  1016. )
  1017. curl_internal_test(${CURL_TEST})
  1018. endforeach()
  1019. if(HAVE_FILE_OFFSET_BITS)
  1020. set(_FILE_OFFSET_BITS 64)
  1021. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  1022. endif()
  1023. check_type_size("off_t" SIZEOF_OFF_T)
  1024. # include this header to get the type
  1025. set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
  1026. set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
  1027. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  1028. set(CMAKE_EXTRA_INCLUDE_FILES "")
  1029. set(CMAKE_REQUIRED_FLAGS)
  1030. foreach(CURL_TEST
  1031. HAVE_GLIBC_STRERROR_R
  1032. HAVE_POSIX_STRERROR_R
  1033. )
  1034. curl_internal_test(${CURL_TEST})
  1035. endforeach()
  1036. # Check for reentrant
  1037. foreach(CURL_TEST
  1038. HAVE_GETHOSTBYADDR_R_5
  1039. HAVE_GETHOSTBYADDR_R_7
  1040. HAVE_GETHOSTBYADDR_R_8
  1041. HAVE_GETHOSTBYNAME_R_3
  1042. HAVE_GETHOSTBYNAME_R_5
  1043. HAVE_GETHOSTBYNAME_R_6
  1044. HAVE_INET_NTOA_R_DECL_REENTRANT)
  1045. if(NOT ${CURL_TEST})
  1046. if(${CURL_TEST}_REENTRANT)
  1047. set(NEED_REENTRANT 1)
  1048. endif()
  1049. endif()
  1050. endforeach()
  1051. if(NEED_REENTRANT)
  1052. foreach(CURL_TEST
  1053. HAVE_GETHOSTBYADDR_R_5
  1054. HAVE_GETHOSTBYADDR_R_7
  1055. HAVE_GETHOSTBYADDR_R_8
  1056. HAVE_GETHOSTBYNAME_R_3
  1057. HAVE_GETHOSTBYNAME_R_5
  1058. HAVE_GETHOSTBYNAME_R_6)
  1059. set(${CURL_TEST} 0)
  1060. if(${CURL_TEST}_REENTRANT)
  1061. set(${CURL_TEST} 1)
  1062. endif()
  1063. endforeach()
  1064. endif()
  1065. if(HAVE_INET_NTOA_R_DECL_REENTRANT)
  1066. set(HAVE_INET_NTOA_R_DECL 1)
  1067. set(NEED_REENTRANT 1)
  1068. endif()
  1069. # Check clock_gettime(CLOCK_MONOTONIC, x) support
  1070. curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
  1071. # Check compiler support of __builtin_available()
  1072. curl_internal_test(HAVE_BUILTIN_AVAILABLE)
  1073. # Some other minor tests
  1074. if(NOT HAVE_IN_ADDR_T)
  1075. set(in_addr_t "unsigned long")
  1076. endif()
  1077. # Fix libz / zlib.h
  1078. if(NOT CURL_SPECIAL_LIBZ)
  1079. if(NOT HAVE_LIBZ)
  1080. set(HAVE_ZLIB_H 0)
  1081. endif()
  1082. if(NOT HAVE_ZLIB_H)
  1083. set(HAVE_LIBZ 0)
  1084. endif()
  1085. endif()
  1086. # Check for nonblocking
  1087. set(HAVE_DISABLED_NONBLOCKING 1)
  1088. if(HAVE_FIONBIO OR
  1089. HAVE_IOCTLSOCKET OR
  1090. HAVE_IOCTLSOCKET_CASE OR
  1091. HAVE_O_NONBLOCK)
  1092. set(HAVE_DISABLED_NONBLOCKING)
  1093. endif()
  1094. if(RETSIGTYPE_TEST)
  1095. set(RETSIGTYPE void)
  1096. else()
  1097. set(RETSIGTYPE int)
  1098. endif()
  1099. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  1100. include(CheckCCompilerFlag)
  1101. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  1102. if(HAVE_C_FLAG_Wno_long_double)
  1103. # The Mac version of GCC warns about use of long double. Disable it.
  1104. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  1105. if(MPRINTF_COMPILE_FLAGS)
  1106. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  1107. else()
  1108. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  1109. endif()
  1110. set_source_files_properties(mprintf.c PROPERTIES
  1111. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  1112. endif()
  1113. endif()
  1114. # TODO test which of these headers are required
  1115. if(WIN32)
  1116. set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
  1117. else()
  1118. set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
  1119. set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
  1120. set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
  1121. endif()
  1122. set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
  1123. set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
  1124. include(CMake/OtherTests.cmake)
  1125. add_definitions(-DHAVE_CONFIG_H)
  1126. # For Windows, all compilers used by CMake should support large files
  1127. if(WIN32)
  1128. set(USE_WIN32_LARGE_FILES ON)
  1129. # Use the manifest embedded in the Windows Resource
  1130. set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
  1131. endif()
  1132. if(MSVC)
  1133. # Disable default manifest added by CMake
  1134. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
  1135. add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  1136. if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
  1137. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  1138. else()
  1139. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  1140. endif()
  1141. endif()
  1142. if(CURL_WERROR)
  1143. if(MSVC_VERSION)
  1144. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
  1145. else()
  1146. # this assumes clang or gcc style options
  1147. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
  1148. endif()
  1149. endif()
  1150. if(CURL_LTO)
  1151. if(CMAKE_VERSION VERSION_LESS 3.9)
  1152. message(FATAL_ERROR "Requested LTO but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
  1153. endif()
  1154. cmake_policy(SET CMP0069 NEW)
  1155. include(CheckIPOSupported)
  1156. check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT CURL_LTO_ERROR LANGUAGES C)
  1157. if(CURL_HAS_LTO)
  1158. message(STATUS "LTO supported and enabled")
  1159. else()
  1160. message(FATAL_ERROR "LTO was requested - but compiler doesn't support it\n${CURL_LTO_ERROR}")
  1161. endif()
  1162. endif()
  1163. # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
  1164. function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
  1165. file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
  1166. string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1167. string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1168. string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1169. string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1170. string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  1171. string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
  1172. 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.
  1173. file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
  1174. endfunction()
  1175. if(0) # This code not needed for building within CMake.
  1176. include(GNUInstallDirs)
  1177. set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  1178. set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
  1179. set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
  1180. set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
  1181. set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
  1182. endif()
  1183. if(USE_MANUAL)
  1184. add_subdirectory(docs)
  1185. endif()
  1186. add_subdirectory(lib)
  1187. if(BUILD_CURL_EXE)
  1188. add_subdirectory(src)
  1189. endif()
  1190. #-----------------------------------------------------------------------------
  1191. # CMake-specific curl code.
  1192. add_executable(curltest curltest.c)
  1193. target_link_libraries(curltest cmcurl)
  1194. if(BUILD_TESTING AND CMAKE_CURL_TEST_URL)
  1195. add_test(curl curltest ${CMAKE_CURL_TEST_URL})
  1196. endif()
  1197. install(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmcurl)
  1198. #-----------------------------------------------------------------------------
  1199. if(0) # This code not needed for building within CMake.
  1200. include(CTest)
  1201. if(BUILD_TESTING)
  1202. add_subdirectory(tests)
  1203. endif()
  1204. # NTLM support requires crypto function adaptions from various SSL libs
  1205. # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
  1206. if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_DARWINSSL OR USE_MBEDTLS OR USE_WIN32_CRYPTO))
  1207. set(use_ntlm ON)
  1208. else()
  1209. set(use_ntlm OFF)
  1210. endif()
  1211. # Helper to populate a list (_items) with a label when conditions (the remaining
  1212. # args) are satisfied
  1213. macro(_add_if label)
  1214. # needs to be a macro to allow this indirection
  1215. if(${ARGN})
  1216. set(_items ${_items} "${label}")
  1217. endif()
  1218. endmacro()
  1219. # Clear list and try to detect available features
  1220. set(_items)
  1221. _add_if("SSL" SSL_ENABLED)
  1222. _add_if("IPv6" ENABLE_IPV6)
  1223. _add_if("unix-sockets" USE_UNIX_SOCKETS)
  1224. _add_if("libz" HAVE_LIBZ)
  1225. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
  1226. _add_if("IDN" HAVE_LIBIDN2)
  1227. _add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
  1228. ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
  1229. # TODO SSP1 (WinSSL) check is missing
  1230. _add_if("SSPI" USE_WINDOWS_SSPI)
  1231. _add_if("GSS-API" HAVE_GSSAPI)
  1232. # TODO SSP1 missing for SPNEGO
  1233. _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1234. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1235. _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1236. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1237. # NTLM support requires crypto function adaptions from various SSL libs
  1238. # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
  1239. _add_if("NTLM" use_ntlm)
  1240. # TODO missing option (autoconf: --enable-ntlm-wb)
  1241. _add_if("NTLM_WB" use_ntlm AND NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
  1242. # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
  1243. _add_if("TLS-SRP" USE_TLS_SRP)
  1244. # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
  1245. _add_if("HTTP2" USE_NGHTTP2)
  1246. _add_if("HTTPS-proxy" SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS OR USE_NSS))
  1247. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1248. message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
  1249. # Clear list and try to detect available protocols
  1250. set(_items)
  1251. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1252. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
  1253. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1254. _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
  1255. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1256. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1257. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1258. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1259. # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
  1260. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1261. ((USE_OPENLDAP AND SSL_ENABLED) OR
  1262. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1263. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1264. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1265. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1266. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1267. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
  1268. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1269. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
  1270. _add_if("SMB" NOT CURL_DISABLE_SMB AND use_ntlm)
  1271. _add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND use_ntlm)
  1272. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1273. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
  1274. _add_if("SCP" USE_LIBSSH2)
  1275. _add_if("SFTP" USE_LIBSSH2)
  1276. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1277. _add_if("RTMP" USE_LIBRTMP)
  1278. if(_items)
  1279. list(SORT _items)
  1280. endif()
  1281. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1282. message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
  1283. # Clear list and collect SSL backends
  1284. set(_items)
  1285. _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
  1286. _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
  1287. _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
  1288. _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
  1289. _add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL)
  1290. _add_if("NSS" SSL_ENABLED AND USE_NSS)
  1291. if(_items)
  1292. list(SORT _items)
  1293. endif()
  1294. string(REPLACE ";" " " SSL_BACKENDS "${_items}")
  1295. message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
  1296. # curl-config needs the following options to be set.
  1297. set(CC "${CMAKE_C_COMPILER}")
  1298. # TODO probably put a -D... options here?
  1299. set(CONFIGURE_OPTIONS "")
  1300. # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
  1301. set(CPPFLAG_CURL_STATICLIB "")
  1302. set(CURLVERSION "${CURL_VERSION}")
  1303. if(BUILD_SHARED_LIBS)
  1304. set(ENABLE_SHARED "yes")
  1305. set(ENABLE_STATIC "no")
  1306. else()
  1307. set(ENABLE_SHARED "no")
  1308. set(ENABLE_STATIC "yes")
  1309. endif()
  1310. set(exec_prefix "\${prefix}")
  1311. set(includedir "\${prefix}/include")
  1312. set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  1313. set(LIBCURL_LIBS "")
  1314. set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
  1315. foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
  1316. if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
  1317. set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
  1318. else()
  1319. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
  1320. endif()
  1321. endforeach()
  1322. # "a" (Linux) or "lib" (Windows)
  1323. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1324. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1325. # Set this to "yes" to append all libraries on which -lcurl is dependent
  1326. set(REQUIRE_LIB_DEPS "no")
  1327. # SUPPORT_FEATURES
  1328. # SUPPORT_PROTOCOLS
  1329. set(VERSIONNUM "${CURL_VERSION_NUM}")
  1330. # Finally generate a "curl-config" matching this config
  1331. # Use:
  1332. # * ENABLE_SHARED
  1333. # * ENABLE_STATIC
  1334. configure_file("${CURL_SOURCE_DIR}/curl-config.in"
  1335. "${CURL_BINARY_DIR}/curl-config" @ONLY)
  1336. install(FILES "${CURL_BINARY_DIR}/curl-config"
  1337. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1338. PERMISSIONS
  1339. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1340. GROUP_READ GROUP_EXECUTE
  1341. WORLD_READ WORLD_EXECUTE)
  1342. # Finally generate a pkg-config file matching this config
  1343. configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
  1344. "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
  1345. install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
  1346. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1347. # install headers
  1348. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  1349. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  1350. FILES_MATCHING PATTERN "*.h")
  1351. include(CMakePackageConfigHelpers)
  1352. write_basic_package_version_file(
  1353. "${version_config}"
  1354. VERSION ${CURL_VERSION}
  1355. COMPATIBILITY SameMajorVersion
  1356. )
  1357. # Use:
  1358. # * TARGETS_EXPORT_NAME
  1359. # * PROJECT_NAME
  1360. configure_package_config_file(CMake/curl-config.cmake.in
  1361. "${project_config}"
  1362. INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1363. )
  1364. install(
  1365. EXPORT "${TARGETS_EXPORT_NAME}"
  1366. NAMESPACE "${PROJECT_NAME}::"
  1367. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1368. )
  1369. install(
  1370. FILES ${version_config} ${project_config}
  1371. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1372. )
  1373. # Workaround for MSVS10 to avoid the Dialog Hell
  1374. # FIXME: This could be removed with future version of CMake.
  1375. if(MSVC_VERSION EQUAL 1600)
  1376. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  1377. if(EXISTS "${CURL_SLN_FILENAME}")
  1378. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  1379. endif()
  1380. endif()
  1381. if(NOT TARGET uninstall)
  1382. configure_file(
  1383. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
  1384. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
  1385. IMMEDIATE @ONLY)
  1386. add_custom_target(uninstall
  1387. COMMAND ${CMAKE_COMMAND} -P
  1388. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
  1389. endif()
  1390. endif()