CMakeLists.txt 55 KB

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