CMakeLists.txt 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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_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_RTSP ON CACHE INTERNAL "Disable curl rtsp protocol?")
  20. set(CURL_DISABLE_SMTP ON CACHE INTERNAL "Disable curl smtp protocol?")
  21. set(CURL_DISABLE_TELNET ON CACHE INTERNAL "Disable curl telnet protocol?")
  22. set(CURL_DISABLE_TFTP ON CACHE INTERNAL "Disable curl tftp protocol?")
  23. set(CURL_DISABLE_VERBOSE_STRING OFF CACHE INTERNAL "Do not disable curl verbosity")
  24. set(CURL_HIDDEN_SYMBOLS OFF CACHE INTERNAL "No curl hidden symbols")
  25. set(CURL_LDAP_WIN OFF CACHE INTERNAL "No curl Windows LDAP")
  26. set(CURL_STATICLIB ON CACHE INTERNAL "Static curl")
  27. set(CURL_USE_ARES OFF CACHE INTERNAL "No curl c-ares support")
  28. set(DISABLED_THREADSAFE OFF CACHE INTERNAL "Curl can use thread-safe functions")
  29. set(ENABLE_IPV6 OFF CACHE INTERNAL "Curl IPv6 support")
  30. set(HTTP_ONLY OFF CACHE INTERNAL "Curl is not http-only")
  31. # Windows Vista and above have inet_pton, but this will link on
  32. # older versions and then the executable will fail to launch at
  33. # runtime on older versions because no DLL provides the symbol.
  34. if(WIN32)
  35. set(HAVE_INET_PTON 0 CACHE INTERNAL "Do not use inet_pton")
  36. endif()
  37. # Disable warnings to avoid changing 3rd party code.
  38. if(CMAKE_C_COMPILER_ID MATCHES
  39. "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
  40. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
  41. elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
  42. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
  43. endif()
  44. #***************************************************************************
  45. # _ _ ____ _
  46. # Project ___| | | | _ \| |
  47. # / __| | | | |_) | |
  48. # | (__| |_| | _ <| |___
  49. # \___|\___/|_| \_\_____|
  50. #
  51. # Copyright (C) 1998 - 2014, Daniel Stenberg, <[email protected]>, et al.
  52. #
  53. # This software is licensed as described in the file COPYING, which
  54. # you should have received as part of this distribution. The terms
  55. # are also available at http://curl.haxx.se/docs/copyright.html.
  56. #
  57. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  58. # copies of the Software, and permit persons to whom the Software is
  59. # furnished to do so, under the terms of the COPYING file.
  60. #
  61. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  62. # KIND, either express or implied.
  63. #
  64. ###########################################################################
  65. # cURL/libcurl CMake script
  66. # by Tetetest and Sukender (Benoit Neil)
  67. # TODO:
  68. # The output .so file lacks the soname number which we currently have within the lib/Makefile.am file
  69. # Add full (4 or 5 libs) SSL support
  70. # 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).
  71. # Add CTests(?)
  72. # Check on all possible platforms
  73. # Test with as many configurations possible (With or without any option)
  74. # Create scripts that help keeping the CMake build system up to date (to reduce maintenance). According to Tetetest:
  75. # - lists of headers that 'configure' checks for;
  76. # - curl-specific tests (the ones that are in m4/curl-*.m4 files);
  77. # - (most obvious thing:) curl version numbers.
  78. # Add documentation subproject
  79. #
  80. # To check:
  81. # (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
  82. # (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.
  83. cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
  84. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
  85. include(Utilities)
  86. include(Macros)
  87. project( CURL C )
  88. if(0) # This code not needed for building within CMake.
  89. message(WARNING "the curl cmake build system is poorly maintained. Be aware")
  90. endif()
  91. file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
  92. string (REGEX MATCH "LIBCURL_VERSION_MAJOR[ \t]+([0-9]+)"
  93. LIBCURL_VERSION_MJ ${CURL_VERSION_H_CONTENTS})
  94. string (REGEX MATCH "([0-9]+)"
  95. LIBCURL_VERSION_MJ ${LIBCURL_VERSION_MJ})
  96. string (REGEX MATCH
  97. "LIBCURL_VERSION_MINOR[ \t]+([0-9]+)"
  98. LIBCURL_VERSION_MI ${CURL_VERSION_H_CONTENTS})
  99. string (REGEX MATCH "([0-9]+)" LIBCURL_VERSION_MI ${LIBCURL_VERSION_MI})
  100. string (REGEX MATCH
  101. "LIBCURL_VERSION_PATCH[ \t]+([0-9]+)"
  102. LIBCURL_VERSION_PT ${CURL_VERSION_H_CONTENTS})
  103. string (REGEX MATCH "([0-9]+)" LIBCURL_VERSION_PT ${LIBCURL_VERSION_PT})
  104. set (CURL_MAJOR_VERSION ${LIBCURL_VERSION_MJ})
  105. set (CURL_MINOR_VERSION ${LIBCURL_VERSION_MI})
  106. set (CURL_PATCH_VERSION ${LIBCURL_VERSION_PT})
  107. include_regular_expression("^.*$") # Sukender: Is it necessary?
  108. # Setup package meta-data
  109. # SET(PACKAGE "curl")
  110. set(CURL_VERSION ${CURL_MAJOR_VERSION}.${CURL_MINOR_VERSION}.${CURL_PATCH_VERSION})
  111. if(0) # This code not needed for building within CMake.
  112. message(STATUS "curl version=[${CURL_VERSION}]")
  113. endif()
  114. # SET(PACKAGE_TARNAME "curl")
  115. # SET(PACKAGE_NAME "curl")
  116. # SET(PACKAGE_VERSION "-")
  117. # SET(PACKAGE_STRING "curl-")
  118. # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => http://curl.haxx.se/mail/")
  119. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  120. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  121. include_directories(${PROJECT_BINARY_DIR}/include/curl)
  122. include_directories( ${CURL_SOURCE_DIR}/include )
  123. option(BUILD_CURL_EXE "Set to ON to build cURL executable." ON)
  124. option(BUILD_CURL_TESTS "Set to ON to build cURL tests." ON)
  125. option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF)
  126. option(CURL_USE_ARES "Set to ON to enable c-ares support" OFF)
  127. # initialize CURL_LIBS
  128. set(CURL_LIBS "")
  129. if(CURL_USE_ARES)
  130. set(USE_ARES ${CURL_USE_ARES})
  131. find_package(CARES REQUIRED)
  132. list(APPEND CURL_LIBS ${CARES_LIBRARY} )
  133. set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
  134. endif()
  135. option(BUILD_DASHBOARD_REPORTS "Set to ON to activate reporting of cURL builds here http://www.cdash.org/CDashPublic/index.php?project=CURL" OFF)
  136. if(BUILD_DASHBOARD_REPORTS)
  137. #INCLUDE(Dart)
  138. include(CTest)
  139. endif(BUILD_DASHBOARD_REPORTS)
  140. if(MSVC)
  141. option(BUILD_RELEASE_DEBUG_DIRS "Set OFF to build each configuration to a separate directory" OFF)
  142. mark_as_advanced(BUILD_RELEASE_DEBUG_DIRS)
  143. endif()
  144. option(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide all symbols that aren't officially external)." ON)
  145. mark_as_advanced(CURL_HIDDEN_SYMBOLS)
  146. # IF(WIN32)
  147. # OPTION(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON)
  148. # MARK_AS_ADVANCED(CURL_WINDOWS_SSPI)
  149. # ENDIF()
  150. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  151. mark_as_advanced(HTTP_ONLY)
  152. option(CURL_DISABLE_FTP "disables FTP" OFF)
  153. mark_as_advanced(CURL_DISABLE_FTP)
  154. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  155. mark_as_advanced(CURL_DISABLE_LDAP)
  156. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  157. mark_as_advanced(CURL_DISABLE_TELNET)
  158. option(CURL_DISABLE_DICT "disables DICT" OFF)
  159. mark_as_advanced(CURL_DISABLE_DICT)
  160. option(CURL_DISABLE_FILE "disables FILE" OFF)
  161. mark_as_advanced(CURL_DISABLE_FILE)
  162. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  163. mark_as_advanced(CURL_DISABLE_TFTP)
  164. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  165. mark_as_advanced(CURL_DISABLE_HTTP)
  166. option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
  167. mark_as_advanced(CURL_DISABLE_LDAPS)
  168. option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
  169. mark_as_advanced(CURL_DISABLE_RTSP)
  170. option(CURL_DISABLE_PROXY "to disable proxy" OFF)
  171. mark_as_advanced(CURL_DISABLE_PROXY)
  172. option(CURL_DISABLE_POP3 "to disable POP3" OFF)
  173. mark_as_advanced(CURL_DISABLE_POP3)
  174. option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
  175. mark_as_advanced(CURL_DISABLE_IMAP)
  176. option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
  177. mark_as_advanced(CURL_DISABLE_SMTP)
  178. option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
  179. mark_as_advanced(CURL_DISABLE_GOPHER)
  180. if(HTTP_ONLY)
  181. set(CURL_DISABLE_FTP ON)
  182. set(CURL_DISABLE_LDAP ON)
  183. set(CURL_DISABLE_LDAPS ON)
  184. set(CURL_DISABLE_TELNET ON)
  185. set(CURL_DISABLE_DICT ON)
  186. set(CURL_DISABLE_FILE ON)
  187. set(CURL_DISABLE_TFTP ON)
  188. set(CURL_DISABLE_RTSP ON)
  189. set(CURL_DISABLE_POP3 ON)
  190. set(CURL_DISABLE_IMAP ON)
  191. set(CURL_DISABLE_SMTP ON)
  192. set(CURL_DISABLE_GOPHER ON)
  193. endif()
  194. option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
  195. mark_as_advanced(CURL_DISABLE_COOKIES)
  196. option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
  197. mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
  198. option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
  199. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  200. option(DISABLED_THREADSAFE "Set to explicitly specify we don't want to use thread-safe functions" OFF)
  201. mark_as_advanced(DISABLED_THREADSAFE)
  202. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" OFF)
  203. mark_as_advanced(ENABLE_IPV6)
  204. # We need ansi c-flags, especially on HP
  205. set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  206. set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
  207. # Disable warnings on Borland to avoid changing 3rd party code.
  208. if(BORLAND)
  209. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  210. endif(BORLAND)
  211. # If we are on AIX, do the _ALL_SOURCE magic
  212. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  213. set(_ALL_SOURCE 1)
  214. endif(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  215. # Include all the necessary files for macros
  216. include (CheckFunctionExists)
  217. include (CheckIncludeFile)
  218. include (CheckIncludeFiles)
  219. include (CheckLibraryExists)
  220. include (CheckSymbolExists)
  221. include (CheckTypeSize)
  222. include (CheckCSourceCompiles)
  223. # On windows preload settings
  224. if(WIN32)
  225. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  226. endif(WIN32)
  227. # Check for all needed libraries
  228. if(0) # This code not needed for building within CMake.
  229. check_library_exists_concat("dl" dlopen HAVE_LIBDL)
  230. else()
  231. # Use the cmake-defined dl libs as dl is should not be used
  232. # on HPUX, but rather dld this avoids a warning
  233. list(APPEND CURL_LIBS ${CMAKE_DL_LIBS})
  234. endif()
  235. check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
  236. check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
  237. # Yellowtab Zeta needs different libraries than BeOS 5.
  238. if(BEOS)
  239. set(NOT_NEED_LIBNSL 1)
  240. check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
  241. check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
  242. endif(BEOS)
  243. check_library_exists_concat("network" recv HAVE_LIBNETWORK)
  244. if(NOT NOT_NEED_LIBNSL)
  245. check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
  246. endif(NOT NOT_NEED_LIBNSL)
  247. if(WIN32)
  248. check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
  249. check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
  250. endif()
  251. if(NOT CURL_DISABLE_LDAP)
  252. if(WIN32)
  253. option(CURL_LDAP_WIN "Use Windows LDAP implementation" ON)
  254. if(CURL_LDAP_WIN)
  255. check_library_exists("wldap32" cldap_open "" HAVE_WLDAP32)
  256. if(NOT HAVE_WLDAP32)
  257. set(CURL_LDAP_WIN OFF)
  258. endif()
  259. endif()
  260. endif()
  261. option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
  262. mark_as_advanced(CMAKE_USE_OPENLDAP)
  263. set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
  264. set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
  265. if(CMAKE_USE_OPENLDAP AND CURL_LDAP_WIN)
  266. message(FATAL_ERROR "Cannot use CURL_LDAP_WIN and CMAKE_USE_OPENLDAP at the same time")
  267. endif()
  268. # Now that we know, we're not using windows LDAP...
  269. if(NOT CURL_LDAP_WIN)
  270. # Check for LDAP
  271. check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
  272. check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
  273. else()
  274. check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
  275. check_include_file_concat("winber.h" HAVE_WINBER_H)
  276. endif()
  277. set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
  278. if(CMAKE_LDAP_INCLUDE_DIR)
  279. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
  280. endif()
  281. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  282. check_include_file_concat("lber.h" HAVE_LBER_H)
  283. if(NOT HAVE_LDAP_H)
  284. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  285. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  286. elseif(NOT HAVE_LIBLDAP)
  287. message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
  288. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  289. else()
  290. if(CMAKE_USE_OPENLDAP)
  291. set(USE_OPENLDAP ON)
  292. endif()
  293. if(CMAKE_LDAP_INCLUDE_DIR)
  294. include_directories(${CMAKE_LDAP_INCLUDE_DIR})
  295. endif()
  296. set(NEED_LBER_H ON)
  297. set(_HEADER_LIST)
  298. if(HAVE_WINDOWS_H)
  299. list(APPEND _HEADER_LIST "windows.h")
  300. endif()
  301. if(HAVE_SYS_TYPES_H)
  302. list(APPEND _HEADER_LIST "sys/types.h")
  303. endif()
  304. list(APPEND _HEADER_LIST "ldap.h")
  305. set(_SRC_STRING "")
  306. foreach(_HEADER ${_HEADER_LIST})
  307. set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
  308. endforeach()
  309. set(_SRC_STRING
  310. "
  311. ${_INCLUDE_STRING}
  312. int main(int argc, char ** argv)
  313. {
  314. BerValue *bvp = NULL;
  315. BerElement *bep = ber_init(bvp);
  316. ber_free(bep, 1);
  317. return 0;
  318. }"
  319. )
  320. set(CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1" "-DWIN32_LEAN_AND_MEAN")
  321. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
  322. if(HAVE_LIBLBER)
  323. list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
  324. endif()
  325. check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
  326. if(NOT_NEED_LBER_H)
  327. set(NEED_LBER_H OFF)
  328. else()
  329. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
  330. endif()
  331. endif()
  332. endif()
  333. # No ldap, no ldaps.
  334. if(CURL_DISABLE_LDAP)
  335. if(NOT CURL_DISABLE_LDAPS)
  336. message(STATUS "LDAP needs to be enabled to support LDAPS")
  337. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  338. endif()
  339. endif()
  340. if(NOT CURL_DISABLE_LDAPS)
  341. check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
  342. check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
  343. endif()
  344. # Check for idn
  345. check_library_exists_concat("idn" idna_to_ascii_lz HAVE_LIBIDN)
  346. # Check for symbol dlopen (same as HAVE_LIBDL)
  347. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  348. # For other tests to use the same libraries
  349. set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBS})
  350. if(0) # This code not needed for building within CMake.
  351. option(CURL_ZLIB "Set to ON to enable building cURL with zlib support." ON)
  352. set(HAVE_LIBZ OFF)
  353. set(HAVE_ZLIB_H OFF)
  354. set(HAVE_ZLIB OFF)
  355. if(CURL_ZLIB)
  356. find_package(ZLIB QUIET)
  357. if(ZLIB_FOUND)
  358. set(HAVE_ZLIB_H ON)
  359. set(HAVE_ZLIB ON)
  360. set(HAVE_LIBZ ON)
  361. list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
  362. endif()
  363. endif()
  364. endif()
  365. #-----------------------------------------------------------------------------
  366. # CMake-specific curl code.
  367. if(CURL_SPECIAL_LIBZ)
  368. set(CURL_LIBS ${CURL_LIBS} "${CURL_SPECIAL_LIBZ}")
  369. include_directories(${CURL_SPECIAL_LIBZ_INCLUDES})
  370. set(HAVE_LIBZ 0)
  371. set(HAVE_ZLIB_H 0)
  372. endif()
  373. #-----------------------------------------------------------------------------
  374. set(USE_SSLEAY OFF)
  375. set(USE_OPENSSL OFF)
  376. set(HAVE_LIBCRYPTO OFF)
  377. set(HAVE_LIBSSL OFF)
  378. if(CMAKE_USE_OPENSSL)
  379. find_package(OpenSSL)
  380. if(OPENSSL_FOUND)
  381. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
  382. set(USE_SSLEAY ON)
  383. set(USE_OPENSSL ON)
  384. set(HAVE_LIBCRYPTO ON)
  385. set(HAVE_LIBSSL ON)
  386. include_directories(${OPENSSL_INCLUDE_DIR})
  387. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  388. check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  389. check_include_file("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
  390. check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
  391. check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  392. check_include_file("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H)
  393. check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  394. check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  395. check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
  396. check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  397. # Optionally build with a specific CA cert bundle.
  398. if(CURL_CA_BUNDLE)
  399. add_definitions(-DCURL_CA_BUNDLE="${CURL_CA_BUNDLE}")
  400. endif()
  401. # Optionally build with a specific CA cert dir.
  402. if(CURL_CA_PATH)
  403. add_definitions(-DCURL_CA_PATH="${CURL_CA_PATH}")
  404. endif()
  405. endif(OPENSSL_FOUND)
  406. elseif(WIN32)
  407. # Use Windows SSL/TLS native implementation.
  408. add_definitions(-DUSE_SCHANNEL)
  409. set(USE_WINDOWS_SSPI 1)
  410. elseif(APPLE)
  411. # Use OS X SSL/TLS native implementation if available on target version.
  412. if(CMAKE_OSX_DEPLOYMENT_TARGET)
  413. set(OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
  414. else()
  415. execute_process(
  416. COMMAND sw_vers -productVersion
  417. OUTPUT_VARIABLE OSX_VERSION
  418. OUTPUT_STRIP_TRAILING_WHITESPACE
  419. )
  420. endif()
  421. if(NOT OSX_VERSION VERSION_LESS 10.6 AND
  422. CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
  423. add_definitions(-DUSE_DARWINSSL)
  424. list(APPEND CURL_LIBS
  425. "-framework CoreFoundation"
  426. "-framework Security"
  427. )
  428. endif()
  429. endif()
  430. #libSSH2
  431. option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
  432. mark_as_advanced(CMAKE_USE_LIBSSH2)
  433. set(USE_LIBSSH2 OFF)
  434. set(HAVE_LIBSSH2 OFF)
  435. set(HAVE_LIBSSH2_H OFF)
  436. if(CMAKE_USE_LIBSSH2)
  437. find_package(LibSSH2)
  438. if(LIBSSH2_FOUND)
  439. list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
  440. set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
  441. set(CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
  442. set(HAVE_LIBSSH2 ON)
  443. set(USE_LIBSSH2 ON)
  444. # find_package has already found the headers
  445. set(HAVE_LIBSSH2_H ON)
  446. set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
  447. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
  448. # now check for specific libssh2 symbols as they were added in different versions
  449. set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
  450. check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
  451. check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
  452. check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
  453. check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
  454. check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
  455. set(CMAKE_EXTRA_INCLUDE_FILES "")
  456. endif(LIBSSH2_FOUND)
  457. endif(CMAKE_USE_LIBSSH2)
  458. # If we have features.h, then do the _BSD_SOURCE magic
  459. check_include_file("features.h" HAVE_FEATURES_H)
  460. # Check for header files
  461. if(NOT UNIX)
  462. check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
  463. check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
  464. endif(NOT UNIX)
  465. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  466. if(NOT UNIX)
  467. check_include_file_concat("windows.h" HAVE_WINDOWS_H)
  468. check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
  469. endif(NOT UNIX)
  470. check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
  471. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  472. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  473. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  474. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  475. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  476. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  477. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  478. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  479. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  480. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  481. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  482. check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
  483. check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
  484. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  485. check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
  486. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  487. check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
  488. check_include_file_concat("assert.h" HAVE_ASSERT_H)
  489. check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
  490. check_include_file_concat("des.h" HAVE_DES_H)
  491. check_include_file_concat("err.h" HAVE_ERR_H)
  492. check_include_file_concat("errno.h" HAVE_ERRNO_H)
  493. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  494. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  495. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  496. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  497. check_include_file_concat("idn-free.h" HAVE_IDN_FREE_H)
  498. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  499. check_include_file_concat("io.h" HAVE_IO_H)
  500. check_include_file_concat("krb.h" HAVE_KRB_H)
  501. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  502. check_include_file_concat("limits.h" HAVE_LIMITS_H)
  503. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  504. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  505. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  506. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  507. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
  508. check_include_file_concat("pem.h" HAVE_PEM_H)
  509. check_include_file_concat("poll.h" HAVE_POLL_H)
  510. check_include_file_concat("pwd.h" HAVE_PWD_H)
  511. check_include_file_concat("rsa.h" HAVE_RSA_H)
  512. check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
  513. check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
  514. check_include_file_concat("signal.h" HAVE_SIGNAL_H)
  515. check_include_file_concat("ssl.h" HAVE_SSL_H)
  516. check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
  517. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  518. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  519. check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
  520. check_include_file_concat("string.h" HAVE_STRING_H)
  521. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  522. check_include_file_concat("stropts.h" HAVE_STROPTS_H)
  523. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  524. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  525. check_include_file_concat("time.h" HAVE_TIME_H)
  526. check_include_file_concat("tld.h" HAVE_TLD_H)
  527. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  528. check_include_file_concat("utime.h" HAVE_UTIME_H)
  529. check_include_file_concat("x509.h" HAVE_X509_H)
  530. check_include_file_concat("process.h" HAVE_PROCESS_H)
  531. check_include_file_concat("stddef.h" HAVE_STDDEF_H)
  532. check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
  533. check_include_file_concat("malloc.h" HAVE_MALLOC_H)
  534. check_include_file_concat("memory.h" HAVE_MEMORY_H)
  535. check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
  536. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  537. check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
  538. check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
  539. check_include_file_concat("idna.h" HAVE_IDNA_H)
  540. check_type_size(size_t SIZEOF_SIZE_T)
  541. check_type_size(ssize_t SIZEOF_SSIZE_T)
  542. check_type_size("long long" SIZEOF_LONG_LONG)
  543. check_type_size("long" SIZEOF_LONG)
  544. check_type_size("short" SIZEOF_SHORT)
  545. check_type_size("int" SIZEOF_INT)
  546. check_type_size("__int64" SIZEOF___INT64)
  547. check_type_size("time_t" SIZEOF_TIME_T)
  548. check_type_size("off_t" SIZEOF_OFF_T)
  549. # Make public versions of some type sizes for curlbuild.h.
  550. foreach(t INT LONG LONG_LONG SSIZE_T)
  551. string(REPLACE "SIZEOF_" "CURL_SIZEOF_" CURL_SIZEOF_${t}_CODE "${SIZEOF_${t}_CODE}")
  552. endforeach()
  553. if(HAVE_SIZEOF_LONG_LONG)
  554. set(HAVE_LONGLONG 1)
  555. set(HAVE_LL 1)
  556. endif(HAVE_SIZEOF_LONG_LONG)
  557. find_file(RANDOM_FILE urandom /dev)
  558. mark_as_advanced(RANDOM_FILE)
  559. # Check for some functions that are used
  560. check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
  561. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  562. check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
  563. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  564. check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
  565. check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
  566. check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
  567. check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
  568. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  569. check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
  570. check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
  571. check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
  572. check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
  573. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  574. if(NOT HAVE_STRNCMPI)
  575. set(HAVE_STRCMPI)
  576. endif(NOT HAVE_STRNCMPI)
  577. check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
  578. check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
  579. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  580. check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
  581. check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
  582. check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
  583. check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
  584. check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
  585. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  586. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  587. check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
  588. check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
  589. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  590. check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
  591. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  592. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  593. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  594. if(CMAKE_USE_OPENSSL)
  595. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  596. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  597. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  598. check_symbol_exists(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}"
  599. HAVE_CRYPTO_CLEANUP_ALL_EX_DATA)
  600. if(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  601. set(USE_OPENSSL 1)
  602. set(USE_SSLEAY 1)
  603. endif(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  604. endif(CMAKE_USE_OPENSSL)
  605. check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
  606. check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
  607. check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
  608. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  609. check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
  610. check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
  611. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  612. set(HAVE_SIGNAL 1)
  613. endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  614. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  615. check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
  616. check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
  617. check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
  618. check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
  619. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  620. check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
  621. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  622. check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
  623. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  624. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  625. check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
  626. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  627. check_symbol_exists(idn_free "${CURL_INCLUDES}" HAVE_IDN_FREE)
  628. check_symbol_exists(idna_strerror "${CURL_INCLUDES}" HAVE_IDNA_STRERROR)
  629. check_symbol_exists(tld_strerror "${CURL_INCLUDES}" HAVE_TLD_STRERROR)
  630. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  631. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  632. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  633. check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
  634. check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
  635. # symbol exists in win32, but function does not.
  636. check_function_exists(inet_pton HAVE_INET_PTON)
  637. # sigaction and sigsetjmp are special. Use special mechanism for
  638. # detecting those, but only if previous attempt failed.
  639. if(HAVE_SIGNAL_H)
  640. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  641. endif(HAVE_SIGNAL_H)
  642. if(NOT HAVE_SIGSETJMP)
  643. if(HAVE_SETJMP_H)
  644. check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
  645. if(HAVE_MACRO_SIGSETJMP)
  646. set(HAVE_SIGSETJMP 1)
  647. endif(HAVE_MACRO_SIGSETJMP)
  648. endif(HAVE_SETJMP_H)
  649. endif(NOT HAVE_SIGSETJMP)
  650. # If there is no stricmp(), do not allow LDAP to parse URLs
  651. if(NOT HAVE_STRICMP)
  652. set(HAVE_LDAP_URL_PARSE 1)
  653. endif(NOT HAVE_STRICMP)
  654. # Do curl specific tests
  655. if(HAVE_LIBWS2_32)
  656. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  657. endif()
  658. foreach(CURL_TEST
  659. HAVE_FCNTL_O_NONBLOCK
  660. HAVE_IOCTLSOCKET
  661. HAVE_IOCTLSOCKET_CAMEL
  662. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  663. HAVE_IOCTLSOCKET_FIONBIO
  664. HAVE_IOCTL_FIONBIO
  665. HAVE_IOCTL_SIOCGIFADDR
  666. HAVE_SETSOCKOPT_SO_NONBLOCK
  667. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
  668. TIME_WITH_SYS_TIME
  669. HAVE_O_NONBLOCK
  670. HAVE_GETHOSTBYADDR_R_5
  671. HAVE_GETHOSTBYADDR_R_7
  672. HAVE_GETHOSTBYADDR_R_8
  673. HAVE_GETHOSTBYADDR_R_5_REENTRANT
  674. HAVE_GETHOSTBYADDR_R_7_REENTRANT
  675. HAVE_GETHOSTBYADDR_R_8_REENTRANT
  676. HAVE_GETHOSTBYNAME_R_3
  677. HAVE_GETHOSTBYNAME_R_5
  678. HAVE_GETHOSTBYNAME_R_6
  679. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  680. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  681. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  682. HAVE_SOCKLEN_T
  683. HAVE_IN_ADDR_T
  684. HAVE_BOOL_T
  685. STDC_HEADERS
  686. RETSIGTYPE_TEST
  687. HAVE_INET_NTOA_R_DECL
  688. HAVE_INET_NTOA_R_DECL_REENTRANT
  689. HAVE_GETADDRINFO
  690. HAVE_FILE_OFFSET_BITS
  691. )
  692. curl_internal_test(${CURL_TEST})
  693. endforeach(CURL_TEST)
  694. if(HAVE_FILE_OFFSET_BITS)
  695. set(_FILE_OFFSET_BITS 64)
  696. endif(HAVE_FILE_OFFSET_BITS)
  697. foreach(CURL_TEST
  698. HAVE_GLIBC_STRERROR_R
  699. HAVE_POSIX_STRERROR_R
  700. )
  701. curl_internal_test_run(${CURL_TEST})
  702. endforeach(CURL_TEST)
  703. # Check for reentrant
  704. foreach(CURL_TEST
  705. HAVE_GETHOSTBYADDR_R_5
  706. HAVE_GETHOSTBYADDR_R_7
  707. HAVE_GETHOSTBYADDR_R_8
  708. HAVE_GETHOSTBYNAME_R_3
  709. HAVE_GETHOSTBYNAME_R_5
  710. HAVE_GETHOSTBYNAME_R_6
  711. HAVE_INET_NTOA_R_DECL_REENTRANT)
  712. if(NOT ${CURL_TEST})
  713. if(${CURL_TEST}_REENTRANT)
  714. set(NEED_REENTRANT 1)
  715. endif(${CURL_TEST}_REENTRANT)
  716. endif(NOT ${CURL_TEST})
  717. endforeach(CURL_TEST)
  718. if(NEED_REENTRANT)
  719. foreach(CURL_TEST
  720. HAVE_GETHOSTBYADDR_R_5
  721. HAVE_GETHOSTBYADDR_R_7
  722. HAVE_GETHOSTBYADDR_R_8
  723. HAVE_GETHOSTBYNAME_R_3
  724. HAVE_GETHOSTBYNAME_R_5
  725. HAVE_GETHOSTBYNAME_R_6)
  726. set(${CURL_TEST} 0)
  727. if(${CURL_TEST}_REENTRANT)
  728. set(${CURL_TEST} 1)
  729. endif(${CURL_TEST}_REENTRANT)
  730. endforeach(CURL_TEST)
  731. endif(NEED_REENTRANT)
  732. if(HAVE_INET_NTOA_R_DECL_REENTRANT)
  733. set(HAVE_INET_NTOA_R_DECL 1)
  734. set(NEED_REENTRANT 1)
  735. endif(HAVE_INET_NTOA_R_DECL_REENTRANT)
  736. # Some other minor tests
  737. if(NOT HAVE_IN_ADDR_T)
  738. set(in_addr_t "unsigned long")
  739. endif(NOT HAVE_IN_ADDR_T)
  740. # Fix libz / zlib.h
  741. if(NOT CURL_SPECIAL_LIBZ)
  742. if(NOT HAVE_LIBZ)
  743. set(HAVE_ZLIB_H 0)
  744. endif(NOT HAVE_LIBZ)
  745. if(NOT HAVE_ZLIB_H)
  746. set(HAVE_LIBZ 0)
  747. endif(NOT HAVE_ZLIB_H)
  748. endif(NOT CURL_SPECIAL_LIBZ)
  749. if(_FILE_OFFSET_BITS)
  750. set(_FILE_OFFSET_BITS 64)
  751. endif(_FILE_OFFSET_BITS)
  752. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  753. set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/curl/curl.h")
  754. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  755. set(CMAKE_EXTRA_INCLUDE_FILES)
  756. set(CMAKE_REQUIRED_FLAGS)
  757. # Check for nonblocking
  758. set(HAVE_DISABLED_NONBLOCKING 1)
  759. if(HAVE_FIONBIO OR
  760. HAVE_IOCTLSOCKET OR
  761. HAVE_IOCTLSOCKET_CASE OR
  762. HAVE_O_NONBLOCK)
  763. set(HAVE_DISABLED_NONBLOCKING)
  764. endif(HAVE_FIONBIO OR
  765. HAVE_IOCTLSOCKET OR
  766. HAVE_IOCTLSOCKET_CASE OR
  767. HAVE_O_NONBLOCK)
  768. if(RETSIGTYPE_TEST)
  769. set(RETSIGTYPE void)
  770. else(RETSIGTYPE_TEST)
  771. set(RETSIGTYPE int)
  772. endif(RETSIGTYPE_TEST)
  773. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  774. include(CheckCCompilerFlag)
  775. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  776. if(HAVE_C_FLAG_Wno_long_double)
  777. # The Mac version of GCC warns about use of long double. Disable it.
  778. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  779. if(MPRINTF_COMPILE_FLAGS)
  780. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  781. else(MPRINTF_COMPILE_FLAGS)
  782. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  783. endif(MPRINTF_COMPILE_FLAGS)
  784. set_source_files_properties(mprintf.c PROPERTIES
  785. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  786. endif(HAVE_C_FLAG_Wno_long_double)
  787. endif(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  788. if(HAVE_SOCKLEN_T)
  789. set(CURL_HAVE_SOCKLEN_T 1)
  790. set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t")
  791. if(WIN32)
  792. set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h;ws2tcpip.h")
  793. elseif(HAVE_SYS_SOCKET_H)
  794. set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
  795. endif()
  796. check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T)
  797. set(CMAKE_EXTRA_INCLUDE_FILES)
  798. if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T)
  799. message(FATAL_ERROR
  800. "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log")
  801. endif()
  802. else()
  803. set(CURL_HAVE_SOCKLEN_T 0)
  804. endif()
  805. # TODO test which of these headers are required for the typedefs used in curlbuild.h
  806. if(WIN32)
  807. set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
  808. else()
  809. set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
  810. set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
  811. set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
  812. endif()
  813. set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
  814. set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
  815. include(CMake/OtherTests.cmake)
  816. add_definitions(-DHAVE_CONFIG_H)
  817. # For windows, do not allow the compiler to use default target (Vista).
  818. if(WIN32)
  819. add_definitions(-D_WIN32_WINNT=0x0501)
  820. endif(WIN32)
  821. if(MSVC)
  822. add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  823. endif(MSVC)
  824. # Sets up the dependencies (zlib, OpenSSL, etc.) of a cURL subproject according to options.
  825. # TODO This is far to be complete!
  826. function(SETUP_CURL_DEPENDENCIES TARGET_NAME)
  827. if(CURL_ZLIB AND ZLIB_FOUND)
  828. include_directories(${ZLIB_INCLUDE_DIR})
  829. endif()
  830. if(CMAKE_USE_OPENSSL AND OPENSSL_FOUND)
  831. include_directories(${OPENSSL_INCLUDE_DIR})
  832. endif()
  833. if(CMAKE_USE_LIBSSH2 AND LIBSSH2_FOUND)
  834. include_directories(${LIBSSH2_INCLUDE_DIR})
  835. endif()
  836. target_link_libraries(${TARGET_NAME} ${CURL_LIBS})
  837. endfunction()
  838. # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
  839. function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
  840. file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
  841. string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  842. string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  843. string(REGEX REPLACE "\\\\\n" "§!§" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  844. string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  845. string(REPLACE "§!§" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  846. string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
  847. 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.
  848. file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
  849. endfunction()
  850. add_subdirectory(lib)
  851. if(BUILD_CURL_EXE)
  852. add_subdirectory(src)
  853. endif()
  854. if(BUILD_CURL_TESTS)
  855. add_subdirectory(tests)
  856. endif()
  857. #-----------------------------------------------------------------------------
  858. # CMake-specific curl code.
  859. add_executable(LIBCURL curltest.c)
  860. target_link_libraries(LIBCURL cmcurl)
  861. if(CMAKE_CURL_TEST_URL)
  862. add_test(curl LIBCURL ${CMAKE_CURL_TEST_URL})
  863. endif()
  864. install(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmcurl)
  865. #-----------------------------------------------------------------------------
  866. if(0) # This code not needed for building within CMake.
  867. # This needs to be run very last so other parts of the scripts can take advantage of this.
  868. if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
  869. 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")
  870. endif()
  871. # Installation.
  872. # First, install generated curlbuild.h
  873. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/curl/curlbuild.h"
  874. DESTINATION include/curl )
  875. # Next, install other headers excluding curlbuild.h
  876. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  877. DESTINATION include
  878. FILES_MATCHING PATTERN "*.h"
  879. PATTERN "curlbuild.h" EXCLUDE)
  880. # Workaround for MSVS10 to avoid the Dialog Hell
  881. # FIXME: This could be removed with future version of CMake.
  882. if(MSVC_VERSION EQUAL 1600)
  883. set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
  884. if(EXISTS "${CURL_SLN_FILENAME}")
  885. file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
  886. endif()
  887. endif()
  888. endif()