CMakeLists.txt 49 KB

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