CMakeLists.txt 55 KB

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