CMakeLists.txt 48 KB

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