CMakeLists.txt 43 KB

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