CMakeLists.txt 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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 - 2019, 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. # Setup package meta-data
  138. # SET(PACKAGE "curl")
  139. if(0) # This code not needed for building within CMake.
  140. message(STATUS "curl version=[${CURL_VERSION}]")
  141. endif()
  142. # SET(PACKAGE_TARNAME "curl")
  143. # SET(PACKAGE_NAME "curl")
  144. # SET(PACKAGE_VERSION "-")
  145. # SET(PACKAGE_STRING "curl-")
  146. # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/")
  147. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  148. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  149. include_directories(${CURL_SOURCE_DIR}/include)
  150. option(CURL_WERROR "Turn compiler warnings into errors" OFF)
  151. option(PICKY_COMPILER "Enable picky compiler options" ON)
  152. option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
  153. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  154. option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
  155. if(WIN32)
  156. option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
  157. 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)
  158. endif()
  159. cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
  160. ON "NOT ENABLE_ARES"
  161. OFF)
  162. option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
  163. option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
  164. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
  165. if(PICKY_COMPILER)
  166. 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)
  167. # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
  168. # test result in.
  169. check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
  170. if(OPT${_CCOPT})
  171. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
  172. endif()
  173. endforeach()
  174. endif()
  175. endif()
  176. if(ENABLE_DEBUG)
  177. # DEBUGBUILD will be defined only for Debug builds
  178. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
  179. set(ENABLE_CURLDEBUG ON)
  180. endif()
  181. if(ENABLE_CURLDEBUG)
  182. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
  183. endif()
  184. if(0) # This code not needed for building within CMake.
  185. # For debug libs and exes, add "-d" postfix
  186. if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
  187. set(CMAKE_DEBUG_POSTFIX "-d")
  188. endif()
  189. endif()
  190. # initialize CURL_LIBS
  191. set(CURL_LIBS "")
  192. if(ENABLE_ARES)
  193. set(USE_ARES 1)
  194. find_package(CARES REQUIRED)
  195. list(APPEND CURL_LIBS ${CARES_LIBRARY})
  196. set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
  197. endif()
  198. if(0) # This code not needed for building within CMake.
  199. include(CurlSymbolHiding)
  200. endif()
  201. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  202. mark_as_advanced(HTTP_ONLY)
  203. option(CURL_DISABLE_FTP "disables FTP" OFF)
  204. mark_as_advanced(CURL_DISABLE_FTP)
  205. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  206. mark_as_advanced(CURL_DISABLE_LDAP)
  207. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  208. mark_as_advanced(CURL_DISABLE_TELNET)
  209. option(CURL_DISABLE_DICT "disables DICT" OFF)
  210. mark_as_advanced(CURL_DISABLE_DICT)
  211. option(CURL_DISABLE_FILE "disables FILE" OFF)
  212. mark_as_advanced(CURL_DISABLE_FILE)
  213. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  214. mark_as_advanced(CURL_DISABLE_TFTP)
  215. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  216. mark_as_advanced(CURL_DISABLE_HTTP)
  217. option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
  218. mark_as_advanced(CURL_DISABLE_LDAPS)
  219. option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
  220. mark_as_advanced(CURL_DISABLE_RTSP)
  221. option(CURL_DISABLE_PROXY "to disable proxy" OFF)
  222. mark_as_advanced(CURL_DISABLE_PROXY)
  223. option(CURL_DISABLE_POP3 "to disable POP3" OFF)
  224. mark_as_advanced(CURL_DISABLE_POP3)
  225. option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
  226. mark_as_advanced(CURL_DISABLE_IMAP)
  227. option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
  228. mark_as_advanced(CURL_DISABLE_SMTP)
  229. option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
  230. mark_as_advanced(CURL_DISABLE_GOPHER)
  231. if(HTTP_ONLY)
  232. set(CURL_DISABLE_FTP ON)
  233. set(CURL_DISABLE_LDAP ON)
  234. set(CURL_DISABLE_LDAPS ON)
  235. set(CURL_DISABLE_TELNET ON)
  236. set(CURL_DISABLE_DICT ON)
  237. set(CURL_DISABLE_FILE ON)
  238. set(CURL_DISABLE_TFTP ON)
  239. set(CURL_DISABLE_RTSP ON)
  240. set(CURL_DISABLE_POP3 ON)
  241. set(CURL_DISABLE_IMAP ON)
  242. set(CURL_DISABLE_SMTP ON)
  243. set(CURL_DISABLE_GOPHER ON)
  244. endif()
  245. option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
  246. mark_as_advanced(CURL_DISABLE_COOKIES)
  247. option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
  248. mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
  249. option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
  250. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  251. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
  252. mark_as_advanced(ENABLE_IPV6)
  253. if(ENABLE_IPV6 AND NOT WIN32)
  254. include(CheckStructHasMember)
  255. check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
  256. HAVE_SOCKADDR_IN6_SIN6_ADDR)
  257. check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
  258. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
  259. if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
  260. message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
  261. # Force the feature off as this name is used as guard macro...
  262. set(ENABLE_IPV6 OFF
  263. CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
  264. endif()
  265. endif()
  266. if(0) # This code not needed for building within CMake.
  267. # Required for building manual, docs, tests
  268. curl_nroff_check()
  269. find_package(Perl)
  270. cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
  271. ON "NROFF_USEFUL;PERL_FOUND"
  272. OFF)
  273. if(NOT PERL_FOUND)
  274. message(STATUS "Perl not found, testing disabled.")
  275. set(BUILD_TESTING OFF)
  276. endif()
  277. if(ENABLE_MANUAL)
  278. set(USE_MANUAL ON)
  279. endif()
  280. endif()
  281. # We need ansi c-flags, especially on HP
  282. set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  283. set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
  284. if(CURL_STATIC_CRT)
  285. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  286. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  287. endif()
  288. # Disable warnings on Borland to avoid changing 3rd party code.
  289. if(BORLAND)
  290. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  291. endif()
  292. # If we are on AIX, do the _ALL_SOURCE magic
  293. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  294. set(_ALL_SOURCE 1)
  295. endif()
  296. # Include all the necessary files for macros
  297. include(CheckFunctionExists)
  298. include(CheckIncludeFile)
  299. include(CheckIncludeFiles)
  300. include(CheckLibraryExists)
  301. include(CheckSymbolExists)
  302. include(CheckTypeSize)
  303. include(CheckCSourceCompiles)
  304. # On windows preload settings
  305. if(WIN32)
  306. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
  307. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  308. endif()
  309. if(ENABLE_THREADED_RESOLVER)
  310. find_package(Threads REQUIRED)
  311. if(WIN32)
  312. set(USE_THREADS_WIN32 ON)
  313. else()
  314. set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
  315. set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
  316. endif()
  317. set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
  318. endif()
  319. # Check for all needed libraries
  320. if(0) # This code not needed for building within CMake.
  321. check_library_exists_concat("dl" dlopen HAVE_LIBDL)
  322. else()
  323. # Use the cmake-defined dl libs as dl is should not be used
  324. # on HPUX, but rather dld this avoids a warning
  325. list(APPEND CURL_LIBS ${CMAKE_DL_LIBS})
  326. endif()
  327. check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
  328. check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
  329. # Yellowtab Zeta needs different libraries than BeOS 5.
  330. if(BEOS)
  331. set(NOT_NEED_LIBNSL 1)
  332. check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
  333. check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
  334. endif()
  335. check_library_exists_concat("network" recv HAVE_LIBNETWORK)
  336. if(NOT NOT_NEED_LIBNSL)
  337. check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
  338. endif()
  339. check_function_exists(gethostname HAVE_GETHOSTNAME)
  340. if(WIN32)
  341. check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
  342. check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
  343. list(APPEND CURL_LIBS "advapi32")
  344. endif()
  345. # check SSL libraries
  346. # TODO support GNUTLS, NSS, POLARSSL, CYASSL
  347. if(APPLE)
  348. option(CMAKE_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF)
  349. endif()
  350. if(WIN32)
  351. option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
  352. cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
  353. CMAKE_USE_WINSSL OFF)
  354. endif()
  355. option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
  356. set(openssl_default ON)
  357. if(WIN32 OR CMAKE_USE_SECTRANSP OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
  358. set(openssl_default OFF)
  359. endif()
  360. count_true(enabled_ssl_options_count
  361. CMAKE_USE_WINSSL
  362. CMAKE_USE_SECTRANSP
  363. CMAKE_USE_OPENSSL
  364. CMAKE_USE_MBEDTLS
  365. )
  366. if(enabled_ssl_options_count GREATER "1")
  367. set(CURL_WITH_MULTI_SSL ON)
  368. endif()
  369. if(CMAKE_USE_WINSSL)
  370. set(SSL_ENABLED ON)
  371. set(USE_SCHANNEL ON) # Windows native SSL/TLS support
  372. set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
  373. list(APPEND CURL_LIBS "crypt32")
  374. endif()
  375. if(CURL_WINDOWS_SSPI)
  376. set(USE_WINDOWS_SSPI ON)
  377. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
  378. endif()
  379. if(CMAKE_USE_DARWINSSL)
  380. message(FATAL_ERROR "The cmake option CMAKE_USE_DARWINSSL was renamed to CMAKE_USE_SECTRANSP.")
  381. endif()
  382. if(CMAKE_USE_SECTRANSP)
  383. find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
  384. if(NOT COREFOUNDATION_FRAMEWORK)
  385. message(FATAL_ERROR "CoreFoundation framework not found")
  386. endif()
  387. find_library(SECURITY_FRAMEWORK "Security")
  388. if(NOT SECURITY_FRAMEWORK)
  389. message(FATAL_ERROR "Security framework not found")
  390. endif()
  391. set(SSL_ENABLED ON)
  392. set(USE_SECTRANSP ON)
  393. list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
  394. endif()
  395. if(CMAKE_USE_OPENSSL)
  396. find_package(OpenSSL REQUIRED)
  397. set(SSL_ENABLED ON)
  398. set(USE_OPENSSL ON)
  399. set(HAVE_LIBCRYPTO ON)
  400. set(HAVE_LIBSSL ON)
  401. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  402. include_directories(${OPENSSL_INCLUDE_DIR})
  403. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  404. check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  405. check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
  406. check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  407. check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  408. check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  409. check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
  410. check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  411. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  412. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  413. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  414. # Optionally build with a specific CA cert bundle.
  415. if(CURL_CA_BUNDLE)
  416. add_definitions(-DCURL_CA_BUNDLE="${CURL_CA_BUNDLE}")
  417. endif()
  418. # Optionally build with a specific CA cert dir.
  419. if(CURL_CA_PATH)
  420. add_definitions(-DCURL_CA_PATH="${CURL_CA_PATH}")
  421. endif()
  422. endif()
  423. if(CMAKE_USE_MBEDTLS)
  424. find_package(MbedTLS REQUIRED)
  425. set(SSL_ENABLED ON)
  426. set(USE_MBEDTLS ON)
  427. list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
  428. include_directories(${MBEDTLS_INCLUDE_DIRS})
  429. endif()
  430. option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
  431. if(USE_NGHTTP2)
  432. find_package(NGHTTP2 REQUIRED)
  433. include_directories(${NGHTTP2_INCLUDE_DIRS})
  434. list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
  435. endif()
  436. if(NOT CURL_DISABLE_LDAP)
  437. if(WIN32)
  438. option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
  439. if(USE_WIN32_LDAP)
  440. check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
  441. if(NOT HAVE_WLDAP32)
  442. set(USE_WIN32_LDAP OFF)
  443. endif()
  444. endif()
  445. endif()
  446. option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
  447. mark_as_advanced(CMAKE_USE_OPENLDAP)
  448. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  449. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  450. if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
  451. message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
  452. endif()
  453. # Now that we know, we're not using windows LDAP...
  454. if(USE_WIN32_LDAP)
  455. check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
  456. check_include_file_concat("winber.h" HAVE_WINBER_H)
  457. else()
  458. # Check for LDAP
  459. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  460. check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
  461. check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
  462. set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
  463. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  464. if(CMAKE_LDAP_INCLUDE_DIR)
  465. list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  466. endif()
  467. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  468. check_include_file_concat("lber.h" HAVE_LBER_H)
  469. if(NOT HAVE_LDAP_H)
  470. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  471. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  472. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  473. elseif(NOT HAVE_LIBLDAP)
  474. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  475. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  476. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
  477. else()
  478. if(CMAKE_USE_OPENLDAP)
  479. set(USE_OPENLDAP ON)
  480. endif()
  481. if(CMAKE_LDAP_INCLUDE_DIR)
  482. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  483. endif()
  484. set(NEED_LBER_H ON)
  485. set(_HEADER_LIST)
  486. if(HAVE_WINDOWS_H)
  487. list(APPEND _HEADER_LIST "windows.h")
  488. endif()
  489. if(HAVE_SYS_TYPES_H)
  490. list(APPEND _HEADER_LIST "sys/types.h")
  491. endif()
  492. list(APPEND _HEADER_LIST "ldap.h")
  493. set(_SRC_STRING "")
  494. foreach(_HEADER ${_HEADER_LIST})
  495. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  496. endforeach()
  497. set(_SRC_STRING
  498. "
  499. ${_INCLUDE_STRING}
  500. int main(int argc, char ** argv)
  501. {
  502. BerValue *bvp = NULL;
  503. BerElement *bep = ber_init(bvp);
  504. ber_free(bep, 1);
  505. return 0;
  506. }"
  507. )
  508. set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
  509. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  510. if(HAVE_LIBLBER)
  511. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  512. endif()
  513. check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
  514. unset(CMAKE_REQUIRED_LIBRARIES)
  515. if(NOT_NEED_LBER_H)
  516. set(NEED_LBER_H OFF)
  517. else()
  518. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  519. endif()
  520. endif()
  521. endif()
  522. endif()
  523. # No ldap, no ldaps.
  524. if(CURL_DISABLE_LDAP)
  525. if(NOT CURL_DISABLE_LDAPS)
  526. message(STATUS "LDAP needs to be enabled to support LDAPS")
  527. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  528. endif()
  529. endif()
  530. if(NOT CURL_DISABLE_LDAPS)
  531. check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
  532. check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
  533. endif()
  534. # Check for idn
  535. check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
  536. # Check for symbol dlopen (same as HAVE_LIBDL)
  537. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  538. if(0) # This code not needed for building within CMake.
  539. option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
  540. set(HAVE_LIBZ OFF)
  541. set(HAVE_ZLIB_H OFF)
  542. set(USE_ZLIB OFF)
  543. if(CURL_ZLIB)
  544. find_package(ZLIB QUIET)
  545. if(ZLIB_FOUND)
  546. set(HAVE_ZLIB_H ON)
  547. set(HAVE_LIBZ ON)
  548. set(USE_ZLIB ON)
  549. # Depend on ZLIB via imported targets if supported by the running
  550. # version of CMake. This allows our dependents to get our dependencies
  551. # transitively.
  552. if(NOT CMAKE_VERSION VERSION_LESS 3.4)
  553. list(APPEND CURL_LIBS ZLIB::ZLIB)
  554. else()
  555. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  556. include_directories(${ZLIB_INCLUDE_DIRS})
  557. endif()
  558. list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
  559. endif()
  560. endif()
  561. endif()
  562. #-----------------------------------------------------------------------------
  563. # CMake-specific curl code.
  564. if(CURL_SPECIAL_LIBZ)
  565. set(CURL_LIBS ${CURL_LIBS} "${CURL_SPECIAL_LIBZ}")
  566. include_directories(${CURL_SPECIAL_LIBZ_INCLUDES})
  567. set(HAVE_LIBZ 0)
  568. set(HAVE_ZLIB_H 0)
  569. endif()
  570. option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
  571. set(HAVE_BROTLI OFF)
  572. if(CURL_BROTLI)
  573. find_package(BROTLI QUIET)
  574. if(BROTLI_FOUND)
  575. set(HAVE_BROTLI ON)
  576. list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
  577. include_directories(${BROTLI_INCLUDE_DIRS})
  578. list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
  579. endif()
  580. endif()
  581. #libSSH2
  582. option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
  583. mark_as_advanced(CMAKE_USE_LIBSSH2)
  584. set(USE_LIBSSH2 OFF)
  585. set(HAVE_LIBSSH2 OFF)
  586. set(HAVE_LIBSSH2_H OFF)
  587. if(CMAKE_USE_LIBSSH2)
  588. find_package(LibSSH2)
  589. if(LIBSSH2_FOUND)
  590. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  591. set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
  592. list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  593. include_directories("${LIBSSH2_INCLUDE_DIR}")
  594. set(HAVE_LIBSSH2 ON)
  595. set(USE_LIBSSH2 ON)
  596. # find_package has already found the headers
  597. set(HAVE_LIBSSH2_H ON)
  598. set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
  599. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
  600. # now check for specific libssh2 symbols as they were added in different versions
  601. set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
  602. check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
  603. check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
  604. check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
  605. check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
  606. check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
  607. set(CMAKE_EXTRA_INCLUDE_FILES "")
  608. unset(CMAKE_REQUIRED_LIBRARIES)
  609. endif()
  610. endif()
  611. option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
  612. mark_as_advanced(CMAKE_USE_GSSAPI)
  613. if(CMAKE_USE_GSSAPI)
  614. find_package(GSS)
  615. set(HAVE_GSSAPI ${GSS_FOUND})
  616. if(GSS_FOUND)
  617. message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
  618. list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
  619. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  620. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  621. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  622. if(GSS_FLAVOUR STREQUAL "Heimdal")
  623. set(HAVE_GSSHEIMDAL ON)
  624. else() # MIT
  625. set(HAVE_GSSMIT ON)
  626. set(_INCLUDE_LIST "")
  627. if(HAVE_GSSAPI_GSSAPI_H)
  628. list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
  629. endif()
  630. if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
  631. list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
  632. endif()
  633. if(HAVE_GSSAPI_GSSAPI_KRB5_H)
  634. list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
  635. endif()
  636. string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
  637. string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
  638. foreach(_dir ${GSS_LINK_DIRECTORIES})
  639. set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
  640. endforeach()
  641. set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
  642. set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
  643. check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  644. if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
  645. set(HAVE_OLD_GSSMIT ON)
  646. endif()
  647. unset(CMAKE_REQUIRED_LIBRARIES)
  648. endif()
  649. include_directories(${GSS_INCLUDE_DIR})
  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. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  837. check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
  838. check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
  839. check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
  840. check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
  841. check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
  842. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  843. check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
  844. check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
  845. check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
  846. check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
  847. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  848. if(NOT HAVE_STRNCMPI)
  849. set(HAVE_STRCMPI)
  850. endif()
  851. check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
  852. check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
  853. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  854. check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
  855. check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
  856. check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
  857. check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
  858. check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
  859. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  860. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  861. check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
  862. check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
  863. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  864. check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
  865. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  866. check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
  867. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  868. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  869. check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
  870. check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
  871. check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
  872. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  873. check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
  874. check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
  875. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  876. set(HAVE_SIGNAL 1)
  877. endif()
  878. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  879. check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
  880. check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
  881. check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
  882. check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
  883. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  884. check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
  885. check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
  886. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  887. check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
  888. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  889. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  890. check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
  891. check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
  892. check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
  893. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  894. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  895. check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
  896. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  897. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  898. check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
  899. check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
  900. check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
  901. # symbol exists in win32, but function does not.
  902. if(WIN32)
  903. if(ENABLE_INET_PTON)
  904. check_function_exists(inet_pton HAVE_INET_PTON)
  905. # _WIN32_WINNT_VISTA (0x0600)
  906. add_definitions(-D_WIN32_WINNT=0x0600)
  907. else()
  908. # _WIN32_WINNT_WINXP (0x0501)
  909. add_definitions(-D_WIN32_WINNT=0x0501)
  910. endif()
  911. else()
  912. check_function_exists(inet_pton HAVE_INET_PTON)
  913. endif()
  914. check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
  915. if(HAVE_FSETXATTR)
  916. foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
  917. curl_internal_test(${CURL_TEST})
  918. endforeach()
  919. endif()
  920. # sigaction and sigsetjmp are special. Use special mechanism for
  921. # detecting those, but only if previous attempt failed.
  922. if(HAVE_SIGNAL_H)
  923. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  924. endif()
  925. if(NOT HAVE_SIGSETJMP)
  926. if(HAVE_SETJMP_H)
  927. check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
  928. if(HAVE_MACRO_SIGSETJMP)
  929. set(HAVE_SIGSETJMP 1)
  930. endif()
  931. endif()
  932. endif()
  933. # If there is no stricmp(), do not allow LDAP to parse URLs
  934. if(NOT HAVE_STRICMP)
  935. set(HAVE_LDAP_URL_PARSE 1)
  936. endif()
  937. # Do curl specific tests
  938. foreach(CURL_TEST
  939. HAVE_FCNTL_O_NONBLOCK
  940. HAVE_IOCTLSOCKET
  941. HAVE_IOCTLSOCKET_CAMEL
  942. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  943. HAVE_IOCTLSOCKET_FIONBIO
  944. HAVE_IOCTL_FIONBIO
  945. HAVE_IOCTL_SIOCGIFADDR
  946. HAVE_SETSOCKOPT_SO_NONBLOCK
  947. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
  948. TIME_WITH_SYS_TIME
  949. HAVE_O_NONBLOCK
  950. HAVE_GETHOSTBYADDR_R_5
  951. HAVE_GETHOSTBYADDR_R_7
  952. HAVE_GETHOSTBYADDR_R_8
  953. HAVE_GETHOSTBYADDR_R_5_REENTRANT
  954. HAVE_GETHOSTBYADDR_R_7_REENTRANT
  955. HAVE_GETHOSTBYADDR_R_8_REENTRANT
  956. HAVE_GETHOSTBYNAME_R_3
  957. HAVE_GETHOSTBYNAME_R_5
  958. HAVE_GETHOSTBYNAME_R_6
  959. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  960. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  961. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  962. HAVE_IN_ADDR_T
  963. HAVE_BOOL_T
  964. STDC_HEADERS
  965. RETSIGTYPE_TEST
  966. HAVE_INET_NTOA_R_DECL
  967. HAVE_INET_NTOA_R_DECL_REENTRANT
  968. HAVE_GETADDRINFO
  969. HAVE_FILE_OFFSET_BITS
  970. HAVE_VARIADIC_MACROS_C99
  971. HAVE_VARIADIC_MACROS_GCC
  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("SSL" SSL_ENABLED)
  1158. _add_if("IPv6" ENABLE_IPV6)
  1159. _add_if("unix-sockets" USE_UNIX_SOCKETS)
  1160. _add_if("libz" HAVE_LIBZ)
  1161. _add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
  1162. _add_if("IDN" HAVE_LIBIDN2)
  1163. _add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
  1164. ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
  1165. # TODO SSP1 (WinSSL) check is missing
  1166. _add_if("SSPI" USE_WINDOWS_SSPI)
  1167. _add_if("GSS-API" HAVE_GSSAPI)
  1168. # TODO SSP1 missing for SPNEGO
  1169. _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1170. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1171. _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
  1172. (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
  1173. # NTLM support requires crypto function adaptions from various SSL libs
  1174. # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
  1175. if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_SECTRANSP OR USE_MBEDTLS))
  1176. _add_if("NTLM" 1)
  1177. # TODO missing option (autoconf: --enable-ntlm-wb)
  1178. _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
  1179. endif()
  1180. # TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
  1181. _add_if("TLS-SRP" USE_TLS_SRP)
  1182. # TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
  1183. _add_if("HTTP2" USE_NGHTTP2)
  1184. string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
  1185. message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
  1186. # Clear list and try to detect available protocols
  1187. set(_items)
  1188. _add_if("HTTP" NOT CURL_DISABLE_HTTP)
  1189. _add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
  1190. _add_if("FTP" NOT CURL_DISABLE_FTP)
  1191. _add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
  1192. _add_if("FILE" NOT CURL_DISABLE_FILE)
  1193. _add_if("TELNET" NOT CURL_DISABLE_TELNET)
  1194. _add_if("LDAP" NOT CURL_DISABLE_LDAP)
  1195. # CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
  1196. # TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
  1197. _add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
  1198. ((USE_OPENLDAP AND SSL_ENABLED) OR
  1199. (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
  1200. _add_if("DICT" NOT CURL_DISABLE_DICT)
  1201. _add_if("TFTP" NOT CURL_DISABLE_TFTP)
  1202. _add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
  1203. _add_if("POP3" NOT CURL_DISABLE_POP3)
  1204. _add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
  1205. _add_if("IMAP" NOT CURL_DISABLE_IMAP)
  1206. _add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
  1207. _add_if("SMTP" NOT CURL_DISABLE_SMTP)
  1208. _add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
  1209. _add_if("SCP" USE_LIBSSH2)
  1210. _add_if("SFTP" USE_LIBSSH2)
  1211. _add_if("RTSP" NOT CURL_DISABLE_RTSP)
  1212. _add_if("RTMP" USE_LIBRTMP)
  1213. if(_items)
  1214. list(SORT _items)
  1215. endif()
  1216. string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
  1217. message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
  1218. # Clear list and collect SSL backends
  1219. set(_items)
  1220. _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
  1221. _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
  1222. _add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
  1223. _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
  1224. if(_items)
  1225. list(SORT _items)
  1226. endif()
  1227. string(REPLACE ";" " " SSL_BACKENDS "${_items}")
  1228. message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
  1229. # curl-config needs the following options to be set.
  1230. set(CC "${CMAKE_C_COMPILER}")
  1231. # TODO probably put a -D... options here?
  1232. set(CONFIGURE_OPTIONS "")
  1233. # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
  1234. set(CPPFLAG_CURL_STATICLIB "")
  1235. set(CURLVERSION "${CURL_VERSION}")
  1236. if(BUILD_SHARED_LIBS)
  1237. set(ENABLE_SHARED "yes")
  1238. set(ENABLE_STATIC "no")
  1239. else()
  1240. set(ENABLE_SHARED "no")
  1241. set(ENABLE_STATIC "yes")
  1242. endif()
  1243. set(exec_prefix "\${prefix}")
  1244. set(includedir "\${prefix}/include")
  1245. set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  1246. set(LIBCURL_LIBS "")
  1247. set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
  1248. foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
  1249. if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
  1250. set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
  1251. else()
  1252. set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
  1253. endif()
  1254. endforeach()
  1255. # "a" (Linux) or "lib" (Windows)
  1256. string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
  1257. set(prefix "${CMAKE_INSTALL_PREFIX}")
  1258. # Set this to "yes" to append all libraries on which -lcurl is dependent
  1259. set(REQUIRE_LIB_DEPS "no")
  1260. # SUPPORT_FEATURES
  1261. # SUPPORT_PROTOCOLS
  1262. set(VERSIONNUM "${CURL_VERSION_NUM}")
  1263. # Finally generate a "curl-config" matching this config
  1264. # Use:
  1265. # * ENABLE_SHARED
  1266. # * ENABLE_STATIC
  1267. configure_file("${CURL_SOURCE_DIR}/curl-config.in"
  1268. "${CURL_BINARY_DIR}/curl-config" @ONLY)
  1269. install(FILES "${CURL_BINARY_DIR}/curl-config"
  1270. DESTINATION ${CMAKE_INSTALL_BINDIR}
  1271. PERMISSIONS
  1272. OWNER_READ OWNER_WRITE OWNER_EXECUTE
  1273. GROUP_READ GROUP_EXECUTE
  1274. WORLD_READ WORLD_EXECUTE)
  1275. # Finally generate a pkg-config file matching this config
  1276. configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
  1277. "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
  1278. install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
  1279. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1280. # install headers
  1281. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  1282. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  1283. FILES_MATCHING PATTERN "*.h")
  1284. include(CMakePackageConfigHelpers)
  1285. write_basic_package_version_file(
  1286. "${version_config}"
  1287. VERSION ${CURL_VERSION}
  1288. COMPATIBILITY SameMajorVersion
  1289. )
  1290. # Use:
  1291. # * TARGETS_EXPORT_NAME
  1292. # * PROJECT_NAME
  1293. configure_package_config_file(CMake/curl-config.cmake.in
  1294. "${project_config}"
  1295. INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1296. )
  1297. install(
  1298. EXPORT "${TARGETS_EXPORT_NAME}"
  1299. NAMESPACE "${PROJECT_NAME}::"
  1300. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1301. )
  1302. install(
  1303. FILES ${version_config} ${project_config}
  1304. DESTINATION ${CURL_INSTALL_CMAKE_DIR}
  1305. )
  1306. # Workaround for MSVS10 to avoid the Dialog Hell
  1307. # FIXME: This could be removed with future version of CMake.
  1308. if(MSVC_VERSION EQUAL 1600)
  1309. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  1310. if(EXISTS "${CURL_SLN_FILENAME}")
  1311. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  1312. endif()
  1313. endif()
  1314. if(NOT TARGET uninstall)
  1315. configure_file(
  1316. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
  1317. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
  1318. IMMEDIATE @ONLY)
  1319. add_custom_target(uninstall
  1320. COMMAND ${CMAKE_COMMAND} -P
  1321. ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
  1322. endif()
  1323. endif()