2
0

CMakeLists.txt 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. # cURL/libcurl CMake script
  2. # by Tetetest and Sukender (Benoit Neil)
  3. # TODO:
  4. # The output .so file lacks the soname number which we currently have within the lib/Makefile.am file
  5. # Add full (4 or 5 libs) SSL support
  6. # 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).
  7. # Add CTests(?)
  8. # Check on all possible platforms
  9. # Test with as many configurations possible (With or without any option)
  10. # Create scripts that help keeping the CMake build system up to date (to reduce maintenance). According to Tetetest:
  11. # - lists of headers that 'configure' checks for;
  12. # - curl-specific tests (the ones that are in m4/curl-*.m4 files);
  13. # - (most obvious thing:) curl version numbers.
  14. # Add documentation subproject
  15. #
  16. # To check:
  17. # (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
  18. # (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.
  19. cmake_minimum_required(VERSION 2.6.2 FATAL_ERROR)
  20. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
  21. include(Utilities)
  22. project( CURL C )
  23. file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
  24. string (REGEX MATCH "LIBCURL_VERSION_MAJOR[ \t]+([0-9]+)"
  25. LIBCURL_VERSION_MJ ${CURL_VERSION_H_CONTENTS})
  26. string (REGEX MATCH "([0-9]+)"
  27. LIBCURL_VERSION_MJ ${LIBCURL_VERSION_MJ})
  28. string (REGEX MATCH
  29. "LIBCURL_VERSION_MINOR[ \t]+([0-9]+)"
  30. LIBCURL_VERSION_MI ${CURL_VERSION_H_CONTENTS})
  31. string (REGEX MATCH "([0-9]+)" LIBCURL_VERSION_MI ${LIBCURL_VERSION_MI})
  32. string (REGEX MATCH
  33. "LIBCURL_VERSION_PATCH[ \t]+([0-9]+)"
  34. LIBCURL_VERSION_PT ${CURL_VERSION_H_CONTENTS})
  35. string (REGEX MATCH "([0-9]+)" LIBCURL_VERSION_PT ${LIBCURL_VERSION_PT})
  36. set (CURL_MAJOR_VERSION ${LIBCURL_VERSION_MJ})
  37. set (CURL_MINOR_VERSION ${LIBCURL_VERSION_MI})
  38. set (CURL_PATCH_VERSION ${LIBCURL_VERSION_PT})
  39. include_regular_expression("^.*$") # Sukender: Is it necessary?
  40. # Setup package meta-data
  41. # SET(PACKAGE "curl")
  42. set(CURL_VERSION ${CURL_MAJOR_VERSION}.${CURL_MINOR_VERSION}.${CURL_PATCH_VERSION})
  43. message(STATUS "curl version=[${CURL_VERSION}]")
  44. # SET(PACKAGE_TARNAME "curl")
  45. # SET(PACKAGE_NAME "curl")
  46. # SET(PACKAGE_VERSION "-")
  47. # SET(PACKAGE_STRING "curl-")
  48. # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => http://curl.haxx.se/mail/")
  49. set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
  50. set(OS "\"${CMAKE_SYSTEM_NAME}\"")
  51. include_directories(${PROJECT_BINARY_DIR}/include/curl)
  52. include_directories( ${CURL_SOURCE_DIR}/include )
  53. option(BUILD_CURL_EXE "Set to ON to build cURL executable." ON)
  54. option(BUILD_CURL_TESTS "Set to ON to build cURL tests." ON)
  55. option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF)
  56. option(CURL_USE_ARES "Set to ON to enable c-ares support" OFF)
  57. # initialize CURL_LIBS
  58. set(CURL_LIBS "")
  59. if(CURL_USE_ARES)
  60. set(USE_ARES ${CURL_USE_ARES})
  61. find_package(CARES REQUIRED)
  62. list(APPEND CURL_LIBS ${CARES_LIBRARY} )
  63. set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
  64. endif()
  65. option(BUILD_DASHBOARD_REPORTS "Set to ON to activate reporting of cURL builds here http://www.cdash.org/CDashPublic/index.php?project=CURL" OFF)
  66. if(BUILD_DASHBOARD_REPORTS)
  67. #INCLUDE(Dart)
  68. include(CTest)
  69. endif(BUILD_DASHBOARD_REPORTS)
  70. if(MSVC)
  71. option(BUILD_RELEASE_DEBUG_DIRS "Set OFF to build each configuration to a separate directory" OFF)
  72. mark_as_advanced(BUILD_RELEASE_DEBUG_DIRS)
  73. endif()
  74. option(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide all symbols that aren't officially external)." ON)
  75. mark_as_advanced(CURL_HIDDEN_SYMBOLS)
  76. # IF(WIN32)
  77. # OPTION(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON)
  78. # MARK_AS_ADVANCED(CURL_WINDOWS_SSPI)
  79. # ENDIF()
  80. option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
  81. mark_as_advanced(HTTP_ONLY)
  82. option(CURL_DISABLE_FTP "disables FTP" OFF)
  83. mark_as_advanced(CURL_DISABLE_FTP)
  84. option(CURL_DISABLE_LDAP "disables LDAP" OFF)
  85. mark_as_advanced(CURL_DISABLE_LDAP)
  86. option(CURL_DISABLE_TELNET "disables Telnet" OFF)
  87. mark_as_advanced(CURL_DISABLE_TELNET)
  88. option(CURL_DISABLE_DICT "disables DICT" OFF)
  89. mark_as_advanced(CURL_DISABLE_DICT)
  90. option(CURL_DISABLE_FILE "disables FILE" OFF)
  91. mark_as_advanced(CURL_DISABLE_FILE)
  92. option(CURL_DISABLE_TFTP "disables TFTP" OFF)
  93. mark_as_advanced(CURL_DISABLE_TFTP)
  94. option(CURL_DISABLE_HTTP "disables HTTP" OFF)
  95. mark_as_advanced(CURL_DISABLE_HTTP)
  96. option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
  97. mark_as_advanced(CURL_DISABLE_LDAPS)
  98. if(HTTP_ONLY)
  99. set(CURL_DISABLE_FTP ON)
  100. set(CURL_DISABLE_LDAP ON)
  101. set(CURL_DISABLE_LDAPS ON)
  102. set(CURL_DISABLE_TELNET ON)
  103. set(CURL_DISABLE_DICT ON)
  104. set(CURL_DISABLE_FILE ON)
  105. set(CURL_DISABLE_TFTP ON)
  106. endif()
  107. option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
  108. mark_as_advanced(CURL_DISABLE_COOKIES)
  109. option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
  110. mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
  111. option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
  112. mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
  113. option(DISABLED_THREADSAFE "Set to explicitly specify we don't want to use thread-safe functions" OFF)
  114. mark_as_advanced(DISABLED_THREADSAFE)
  115. option(ENABLE_IPV6 "Define if you want to enable IPv6 support" OFF)
  116. mark_as_advanced(ENABLE_IPV6)
  117. if(WIN32)
  118. # Windows standard libraries are located in C:/Program Files/Microsoft SDKs/[...]
  119. # They are already included in the default MSVC LIBPATH => no find_library is needed!
  120. list_spaces_append_once(CMAKE_C_STANDARD_LIBRARIES wsock32.lib ws2_32.lib) # bufferoverflowu.lib
  121. if(CURL_DISABLE_LDAP)
  122. # Remove wldap32.lib from space-separated list
  123. string(REPLACE " " ";" _LIST ${CMAKE_C_STANDARD_LIBRARIES})
  124. list(REMOVE_ITEM _LIST "wldap32.lib")
  125. to_list_spaces(_LIST CMAKE_C_STANDARD_LIBRARIES)
  126. else()
  127. # Append wldap32.lib
  128. list_spaces_append_once(CMAKE_C_STANDARD_LIBRARIES wldap32.lib)
  129. endif()
  130. set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}" CACHE STRING "" FORCE)
  131. endif()
  132. # We need ansi c-flags, especially on HP
  133. set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  134. set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
  135. # Disable warnings on Borland to avoid changing 3rd party code.
  136. if(BORLAND)
  137. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
  138. endif(BORLAND)
  139. # If we are on AIX, do the _ALL_SOURCE magic
  140. if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  141. set(_ALL_SOURCE 1)
  142. endif(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  143. # Include all the necessary files for macros
  144. include (CheckFunctionExists)
  145. include (CheckIncludeFile)
  146. include (CheckIncludeFiles)
  147. include (CheckLibraryExists)
  148. include (CheckSymbolExists)
  149. include (CheckTypeSize)
  150. # On windows preload settings
  151. if(WIN32)
  152. include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
  153. endif(WIN32)
  154. # This macro checks if the symbol exists in the library and if it
  155. # does, it prepends library to the list.
  156. macro(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
  157. check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
  158. ${VARIABLE})
  159. if(${VARIABLE})
  160. set(CURL_LIBS ${LIBRARY} ${CURL_LIBS})
  161. endif(${VARIABLE})
  162. endmacro(CHECK_LIBRARY_EXISTS_CONCAT)
  163. # Check for all needed libraries
  164. check_library_exists_concat("dl" dlopen HAVE_LIBDL)
  165. check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
  166. check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
  167. # Yellowtab Zeta needs different libraries than BeOS 5.
  168. if(BEOS)
  169. set(NOT_NEED_LIBNSL 1)
  170. check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
  171. check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
  172. endif(BEOS)
  173. if(NOT NOT_NEED_LIBNSL)
  174. check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
  175. endif(NOT NOT_NEED_LIBNSL)
  176. check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
  177. check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
  178. check_library_exists("wldap32" cldap_open "" HAVE_WLDAP32)
  179. if(WIN32)
  180. set(CURL_DEFAULT_DISABLE_LDAP OFF)
  181. # some windows compilers do not have wldap32
  182. if(NOT HAVE_WLDAP32)
  183. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  184. message(STATUS "wldap32 not found CURL_DISABLE_LDAP set ON")
  185. option(CURL_LDAP_WIN "Use Windows LDAP implementation" OFF)
  186. else()
  187. option(CURL_LDAP_WIN "Use Windows LDAP implementation" ON)
  188. endif()
  189. mark_as_advanced(CURL_LDAP_WIN)
  190. endif()
  191. # IF(NOT CURL_SPECIAL_LIBZ)
  192. # CHECK_LIBRARY_EXISTS_CONCAT("z" inflateEnd HAVE_LIBZ)
  193. # ENDIF(NOT CURL_SPECIAL_LIBZ)
  194. # Check for idn
  195. check_library_exists_concat("idn" idna_to_ascii_lz HAVE_LIBIDN)
  196. # Check for LDAP
  197. check_library_exists_concat("ldap" ldap_init HAVE_LIBLDAP)
  198. # if(NOT HAVE_LIBLDAP)
  199. # SET(CURL_DISABLE_LDAP ON)
  200. # endif(NOT HAVE_LIBLDAP)
  201. # Check for symbol dlopen (same as HAVE_LIBDL)
  202. check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
  203. # For other tests to use the same libraries
  204. set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBS})
  205. option(CURL_ZLIB "Set to ON to enable building cURL with zlib support." ON)
  206. set(HAVE_LIBZ OFF)
  207. set(HAVE_ZLIB_H OFF)
  208. set(HAVE_ZLIB OFF)
  209. if(CURL_ZLIB) # AND CURL_CONFIG_HAS_BEEN_RUN_BEFORE
  210. find_package(ZLIB QUIET)
  211. if(ZLIB_FOUND)
  212. set(HAVE_ZLIB_H ON)
  213. set(HAVE_ZLIB ON)
  214. set(HAVE_LIBZ ON)
  215. endif()
  216. endif()
  217. option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ON)
  218. mark_as_advanced(CMAKE_USE_OPENSSL)
  219. if(CMAKE_USE_OPENSSL)
  220. if(WIN32)
  221. find_package(OpenSSL)
  222. if(OPENSSL_FOUND)
  223. set(USE_SSLEAY TRUE)
  224. set(USE_OPENSSL TRUE)
  225. list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES} )
  226. else()
  227. set(CMAKE_USE_OPENSSL FALSE)
  228. message(STATUS "OpenSSL NOT Found, disabling CMAKE_USE_OPENSSL")
  229. endif()
  230. else(WIN32)
  231. check_library_exists_concat("crypto" CRYPTO_lock HAVE_LIBCRYPTO)
  232. check_library_exists_concat("ssl" SSL_connect HAVE_LIBSSL)
  233. endif(WIN32)
  234. endif(CMAKE_USE_OPENSSL)
  235. # If we have features.h, then do the _BSD_SOURCE magic
  236. check_include_file("features.h" HAVE_FEATURES_H)
  237. # Check if header file exists and add it to the list.
  238. macro(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
  239. check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
  240. if(${VARIABLE})
  241. set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
  242. set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
  243. endif(${VARIABLE})
  244. endmacro(CHECK_INCLUDE_FILE_CONCAT)
  245. # Check for header files
  246. if(NOT UNIX)
  247. check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
  248. check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
  249. endif(NOT UNIX)
  250. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  251. if(NOT UNIX)
  252. check_include_file_concat("windows.h" HAVE_WINDOWS_H)
  253. check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
  254. endif(NOT UNIX)
  255. check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
  256. check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
  257. check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
  258. check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
  259. check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
  260. check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
  261. check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
  262. check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
  263. check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
  264. check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
  265. check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
  266. check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
  267. check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
  268. check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
  269. check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
  270. check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
  271. check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
  272. check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
  273. check_include_file_concat("assert.h" HAVE_ASSERT_H)
  274. check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
  275. check_include_file_concat("des.h" HAVE_DES_H)
  276. check_include_file_concat("err.h" HAVE_ERR_H)
  277. check_include_file_concat("errno.h" HAVE_ERRNO_H)
  278. check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
  279. check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
  280. check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
  281. check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
  282. check_include_file_concat("idn-free.h" HAVE_IDN_FREE_H)
  283. check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
  284. check_include_file_concat("io.h" HAVE_IO_H)
  285. check_include_file_concat("krb.h" HAVE_KRB_H)
  286. check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
  287. check_include_file_concat("libssh2.h" HAVE_LIBSSH2_H)
  288. check_include_file_concat("limits.h" HAVE_LIMITS_H)
  289. check_include_file_concat("locale.h" HAVE_LOCALE_H)
  290. check_include_file_concat("net/if.h" HAVE_NET_IF_H)
  291. check_include_file_concat("netdb.h" HAVE_NETDB_H)
  292. check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
  293. check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
  294. check_include_file_concat("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  295. check_include_file_concat("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
  296. check_include_file_concat("openssl/err.h" HAVE_OPENSSL_ERR_H)
  297. check_include_file_concat("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  298. check_include_file_concat("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H)
  299. check_include_file_concat("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  300. check_include_file_concat("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  301. check_include_file_concat("openssl/x509.h" HAVE_OPENSSL_X509_H)
  302. check_include_file_concat("pem.h" HAVE_PEM_H)
  303. check_include_file_concat("poll.h" HAVE_POLL_H)
  304. check_include_file_concat("pwd.h" HAVE_PWD_H)
  305. check_include_file_concat("rsa.h" HAVE_RSA_H)
  306. check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
  307. check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
  308. check_include_file_concat("signal.h" HAVE_SIGNAL_H)
  309. check_include_file_concat("ssl.h" HAVE_SSL_H)
  310. check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
  311. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  312. check_include_file_concat("stdio.h" HAVE_STDIO_H)
  313. check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
  314. check_include_file_concat("string.h" HAVE_STRING_H)
  315. check_include_file_concat("strings.h" HAVE_STRINGS_H)
  316. check_include_file_concat("stropts.h" HAVE_STROPTS_H)
  317. check_include_file_concat("termio.h" HAVE_TERMIO_H)
  318. check_include_file_concat("termios.h" HAVE_TERMIOS_H)
  319. check_include_file_concat("time.h" HAVE_TIME_H)
  320. check_include_file_concat("tld.h" HAVE_TLD_H)
  321. check_include_file_concat("unistd.h" HAVE_UNISTD_H)
  322. check_include_file_concat("utime.h" HAVE_UTIME_H)
  323. check_include_file_concat("x509.h" HAVE_X509_H)
  324. check_include_file_concat("process.h" HAVE_PROCESS_H)
  325. check_include_file_concat("stddef.h" HAVE_STDDEF_H)
  326. check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
  327. check_include_file_concat("malloc.h" HAVE_MALLOC_H)
  328. check_include_file_concat("memory.h" HAVE_MEMORY_H)
  329. check_include_file_concat("ldap.h" HAVE_LDAP_H)
  330. check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
  331. check_include_file_concat("stdint.h" HAVE_STDINT_H)
  332. check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
  333. check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
  334. check_include_file_concat("idna.h" HAVE_IDNA_H)
  335. if(CMAKE_USE_OPENSSL)
  336. check_include_file_concat("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  337. endif(CMAKE_USE_OPENSSL)
  338. if(NOT HAVE_LDAP_H)
  339. message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
  340. set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
  341. endif()
  342. # No ldap, no ldaps.
  343. if(CURL_DISABLE_LDAP)
  344. if(NOT CURL_DISABLE_LDAPS)
  345. message(STATUS "LDAP needs to be enabled to support LDAPS")
  346. set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
  347. endif()
  348. endif()
  349. check_type_size(size_t SIZEOF_SIZE_T)
  350. check_type_size(ssize_t SIZEOF_SSIZE_T)
  351. check_type_size("long long" SIZEOF_LONG_LONG)
  352. check_type_size("long" SIZEOF_LONG)
  353. check_type_size("short" SIZEOF_SHORT)
  354. check_type_size("int" SIZEOF_INT)
  355. check_type_size("__int64" SIZEOF___INT64)
  356. check_type_size("long double" SIZEOF_LONG_DOUBLE)
  357. check_type_size("time_t" SIZEOF_TIME_T)
  358. if(NOT HAVE_SIZEOF_SSIZE_T)
  359. if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  360. set(ssize_t long)
  361. endif(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
  362. if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  363. set(ssize_t __int64)
  364. endif(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
  365. endif(NOT HAVE_SIZEOF_SSIZE_T)
  366. # Different sizeofs, etc.
  367. # define CURL_SIZEOF_LONG 4
  368. # define CURL_TYPEOF_CURL_OFF_T long long
  369. # define CURL_FORMAT_CURL_OFF_T "lld"
  370. # define CURL_FORMAT_CURL_OFF_TU "llu"
  371. # define CURL_FORMAT_OFF_T "%lld"
  372. # define CURL_SIZEOF_CURL_OFF_T 8
  373. # define CURL_SUFFIX_CURL_OFF_T LL
  374. # define CURL_SUFFIX_CURL_OFF_TU ULL
  375. set(CURL_SIZEOF_LONG ${SIZEOF_LONG})
  376. if(SIZEOF_LONG EQUAL 8)
  377. set(CURL_TYPEOF_CURL_OFF_T long)
  378. set(CURL_SIZEOF_CURL_OFF_T 8)
  379. set(CURL_FORMAT_CURL_OFF_T "ld")
  380. set(CURL_FORMAT_CURL_OFF_TU "lu")
  381. set(CURL_FORMAT_OFF_T "%ld")
  382. set(CURL_SUFFIX_CURL_OFF_T L)
  383. set(CURL_SUFFIX_CURL_OFF_TU UL)
  384. endif(SIZEOF_LONG EQUAL 8)
  385. if(SIZEOF_LONG_LONG EQUAL 8)
  386. set(CURL_TYPEOF_CURL_OFF_T "long long")
  387. set(CURL_SIZEOF_CURL_OFF_T 8)
  388. set(CURL_FORMAT_CURL_OFF_T "lld")
  389. set(CURL_FORMAT_CURL_OFF_TU "llu")
  390. set(CURL_FORMAT_OFF_T "%lld")
  391. set(CURL_SUFFIX_CURL_OFF_T LL)
  392. set(CURL_SUFFIX_CURL_OFF_TU ULL)
  393. endif(SIZEOF_LONG_LONG EQUAL 8)
  394. if(NOT CURL_TYPEOF_CURL_OFF_T)
  395. set(CURL_TYPEOF_CURL_OFF_T ${ssize_t})
  396. set(CURL_SIZEOF_CURL_OFF_T ${SIZEOF_SSIZE_T})
  397. # TODO: need adjustment here.
  398. set(CURL_FORMAT_CURL_OFF_T "ld")
  399. set(CURL_FORMAT_CURL_OFF_TU "lu")
  400. set(CURL_FORMAT_OFF_T "%ld")
  401. set(CURL_SUFFIX_CURL_OFF_T L)
  402. set(CURL_SUFFIX_CURL_OFF_TU LU)
  403. endif(NOT CURL_TYPEOF_CURL_OFF_T)
  404. if(HAVE_SIZEOF_LONG_LONG)
  405. set(HAVE_LONGLONG 1)
  406. set(HAVE_LL 1)
  407. endif(HAVE_SIZEOF_LONG_LONG)
  408. find_file(RANDOM_FILE urandom /dev)
  409. mark_as_advanced(RANDOM_FILE)
  410. # Check for some functions that are used
  411. check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
  412. check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
  413. check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
  414. check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
  415. check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
  416. check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
  417. check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
  418. check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
  419. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  420. check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
  421. check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
  422. check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
  423. check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
  424. check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
  425. if(NOT HAVE_STRNCMPI)
  426. set(HAVE_STRCMPI)
  427. endif(NOT HAVE_STRNCMPI)
  428. check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
  429. check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
  430. check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
  431. check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
  432. check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
  433. check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
  434. check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
  435. check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
  436. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  437. check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
  438. check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
  439. check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
  440. check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
  441. check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
  442. check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
  443. check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
  444. check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
  445. if(CMAKE_USE_OPENSSL)
  446. check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  447. check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  448. check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
  449. check_symbol_exists(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}"
  450. HAVE_CRYPTO_CLEANUP_ALL_EX_DATA)
  451. if(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  452. set(USE_OPENSSL 1)
  453. set(USE_SSLEAY 1)
  454. endif(HAVE_LIBCRYPTO AND HAVE_LIBSSL)
  455. endif(CMAKE_USE_OPENSSL)
  456. check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
  457. check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
  458. check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
  459. check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
  460. check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
  461. check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
  462. if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  463. set(HAVE_SIGNAL 1)
  464. endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
  465. check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
  466. check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
  467. check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
  468. check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
  469. check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
  470. check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
  471. check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
  472. check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
  473. check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
  474. check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
  475. check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
  476. check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
  477. check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
  478. check_symbol_exists(idn_free "${CURL_INCLUDES}" HAVE_IDN_FREE)
  479. check_symbol_exists(idna_strerror "${CURL_INCLUDES}" HAVE_IDNA_STRERROR)
  480. check_symbol_exists(tld_strerror "${CURL_INCLUDES}" HAVE_TLD_STRERROR)
  481. check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
  482. check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
  483. check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
  484. check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
  485. check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
  486. # symbol exists in win32, but function does not.
  487. check_function_exists(inet_pton HAVE_INET_PTON)
  488. # sigaction and sigsetjmp are special. Use special mechanism for
  489. # detecting those, but only if previous attempt failed.
  490. if(HAVE_SIGNAL_H)
  491. check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
  492. endif(HAVE_SIGNAL_H)
  493. if(NOT HAVE_SIGSETJMP)
  494. if(HAVE_SETJMP_H)
  495. check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
  496. if(HAVE_MACRO_SIGSETJMP)
  497. set(HAVE_SIGSETJMP 1)
  498. endif(HAVE_MACRO_SIGSETJMP)
  499. endif(HAVE_SETJMP_H)
  500. endif(NOT HAVE_SIGSETJMP)
  501. # If there is no stricmp(), do not allow LDAP to parse URLs
  502. if(NOT HAVE_STRICMP)
  503. set(HAVE_LDAP_URL_PARSE 1)
  504. endif(NOT HAVE_STRICMP)
  505. # For other curl specific tests, use this macro.
  506. macro(CURL_INTERNAL_TEST CURL_TEST)
  507. if("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
  508. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  509. "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
  510. if(CMAKE_REQUIRED_LIBRARIES)
  511. set(CURL_TEST_ADD_LIBRARIES
  512. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  513. endif(CMAKE_REQUIRED_LIBRARIES)
  514. message(STATUS "Performing Curl Test ${CURL_TEST}")
  515. try_compile(${CURL_TEST}
  516. ${CMAKE_BINARY_DIR}
  517. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
  518. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  519. "${CURL_TEST_ADD_LIBRARIES}"
  520. OUTPUT_VARIABLE OUTPUT)
  521. if(${CURL_TEST})
  522. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  523. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  524. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  525. "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
  526. "${OUTPUT}\n")
  527. else(${CURL_TEST})
  528. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  529. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  530. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  531. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  532. "${OUTPUT}\n")
  533. endif(${CURL_TEST})
  534. endif("${CURL_TEST}" MATCHES "^${CURL_TEST}$")
  535. endmacro(CURL_INTERNAL_TEST)
  536. macro(CURL_INTERNAL_TEST_RUN CURL_TEST)
  537. if("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
  538. set(MACRO_CHECK_FUNCTION_DEFINITIONS
  539. "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}")
  540. if(CMAKE_REQUIRED_LIBRARIES)
  541. set(CURL_TEST_ADD_LIBRARIES
  542. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  543. endif(CMAKE_REQUIRED_LIBRARIES)
  544. message(STATUS "Performing Curl Test ${CURL_TEST}")
  545. try_run(${CURL_TEST} ${CURL_TEST}_COMPILE
  546. ${CMAKE_BINARY_DIR}
  547. ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
  548. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  549. "${CURL_TEST_ADD_LIBRARIES}"
  550. OUTPUT_VARIABLE OUTPUT)
  551. if(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  552. set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
  553. message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
  554. else(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  555. message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
  556. set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
  557. file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  558. "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
  559. "${OUTPUT}")
  560. if(${CURL_TEST}_COMPILE)
  561. file(APPEND
  562. "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  563. "There was a problem running this test\n")
  564. endif(${CURL_TEST}_COMPILE)
  565. file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
  566. "\n\n")
  567. endif(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
  568. endif("${CURL_TEST}_COMPILE" MATCHES "^${CURL_TEST}_COMPILE$")
  569. endmacro(CURL_INTERNAL_TEST_RUN)
  570. # Do curl specific tests
  571. foreach(CURL_TEST
  572. HAVE_FCNTL_O_NONBLOCK
  573. HAVE_IOCTLSOCKET
  574. HAVE_IOCTLSOCKET_CAMEL
  575. HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  576. HAVE_IOCTLSOCKET_FIONBIO
  577. HAVE_IOCTL_FIONBIO
  578. HAVE_IOCTL_SIOCGIFADDR
  579. HAVE_SETSOCKOPT_SO_NONBLOCK
  580. HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
  581. TIME_WITH_SYS_TIME
  582. HAVE_O_NONBLOCK
  583. HAVE_GETHOSTBYADDR_R_5
  584. HAVE_GETHOSTBYADDR_R_7
  585. HAVE_GETHOSTBYADDR_R_8
  586. HAVE_GETHOSTBYADDR_R_5_REENTRANT
  587. HAVE_GETHOSTBYADDR_R_7_REENTRANT
  588. HAVE_GETHOSTBYADDR_R_8_REENTRANT
  589. HAVE_GETHOSTBYNAME_R_3
  590. HAVE_GETHOSTBYNAME_R_5
  591. HAVE_GETHOSTBYNAME_R_6
  592. HAVE_GETHOSTBYNAME_R_3_REENTRANT
  593. HAVE_GETHOSTBYNAME_R_5_REENTRANT
  594. HAVE_GETHOSTBYNAME_R_6_REENTRANT
  595. HAVE_SOCKLEN_T
  596. HAVE_IN_ADDR_T
  597. HAVE_BOOL_T
  598. STDC_HEADERS
  599. RETSIGTYPE_TEST
  600. HAVE_INET_NTOA_R_DECL
  601. HAVE_INET_NTOA_R_DECL_REENTRANT
  602. HAVE_GETADDRINFO
  603. HAVE_FILE_OFFSET_BITS
  604. )
  605. curl_internal_test(${CURL_TEST})
  606. endforeach(CURL_TEST)
  607. if(HAVE_FILE_OFFSET_BITS)
  608. set(_FILE_OFFSET_BITS 64)
  609. endif(HAVE_FILE_OFFSET_BITS)
  610. foreach(CURL_TEST
  611. HAVE_GLIBC_STRERROR_R
  612. HAVE_POSIX_STRERROR_R
  613. )
  614. curl_internal_test_run(${CURL_TEST})
  615. endforeach(CURL_TEST)
  616. # Check for reentrant
  617. foreach(CURL_TEST
  618. HAVE_GETHOSTBYADDR_R_5
  619. HAVE_GETHOSTBYADDR_R_7
  620. HAVE_GETHOSTBYADDR_R_8
  621. HAVE_GETHOSTBYNAME_R_3
  622. HAVE_GETHOSTBYNAME_R_5
  623. HAVE_GETHOSTBYNAME_R_6
  624. HAVE_INET_NTOA_R_DECL_REENTRANT)
  625. if(NOT ${CURL_TEST})
  626. if(${CURL_TEST}_REENTRANT)
  627. set(NEED_REENTRANT 1)
  628. endif(${CURL_TEST}_REENTRANT)
  629. endif(NOT ${CURL_TEST})
  630. endforeach(CURL_TEST)
  631. if(NEED_REENTRANT)
  632. foreach(CURL_TEST
  633. HAVE_GETHOSTBYADDR_R_5
  634. HAVE_GETHOSTBYADDR_R_7
  635. HAVE_GETHOSTBYADDR_R_8
  636. HAVE_GETHOSTBYNAME_R_3
  637. HAVE_GETHOSTBYNAME_R_5
  638. HAVE_GETHOSTBYNAME_R_6)
  639. set(${CURL_TEST} 0)
  640. if(${CURL_TEST}_REENTRANT)
  641. set(${CURL_TEST} 1)
  642. endif(${CURL_TEST}_REENTRANT)
  643. endforeach(CURL_TEST)
  644. endif(NEED_REENTRANT)
  645. if(HAVE_INET_NTOA_R_DECL_REENTRANT)
  646. set(HAVE_INET_NTOA_R_DECL 1)
  647. set(NEED_REENTRANT 1)
  648. endif(HAVE_INET_NTOA_R_DECL_REENTRANT)
  649. # Some other minor tests
  650. if(NOT HAVE_IN_ADDR_T)
  651. set(in_addr_t "unsigned long")
  652. endif(NOT HAVE_IN_ADDR_T)
  653. # Fix libz / zlib.h
  654. if(NOT CURL_SPECIAL_LIBZ)
  655. if(NOT HAVE_LIBZ)
  656. set(HAVE_ZLIB_H 0)
  657. endif(NOT HAVE_LIBZ)
  658. if(NOT HAVE_ZLIB_H)
  659. set(HAVE_LIBZ 0)
  660. endif(NOT HAVE_ZLIB_H)
  661. endif(NOT CURL_SPECIAL_LIBZ)
  662. if(_FILE_OFFSET_BITS)
  663. set(_FILE_OFFSET_BITS 64)
  664. endif(_FILE_OFFSET_BITS)
  665. set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
  666. set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/curl/curl.h")
  667. check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
  668. set(CMAKE_EXTRA_INCLUDE_FILES)
  669. set(CMAKE_REQUIRED_FLAGS)
  670. # Check for nonblocking
  671. set(HAVE_DISABLED_NONBLOCKING 1)
  672. if(HAVE_FIONBIO OR
  673. HAVE_IOCTLSOCKET OR
  674. HAVE_IOCTLSOCKET_CASE OR
  675. HAVE_O_NONBLOCK)
  676. set(HAVE_DISABLED_NONBLOCKING)
  677. endif(HAVE_FIONBIO OR
  678. HAVE_IOCTLSOCKET OR
  679. HAVE_IOCTLSOCKET_CASE OR
  680. HAVE_O_NONBLOCK)
  681. if(RETSIGTYPE_TEST)
  682. set(RETSIGTYPE void)
  683. else(RETSIGTYPE_TEST)
  684. set(RETSIGTYPE int)
  685. endif(RETSIGTYPE_TEST)
  686. if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  687. include(CheckCCompilerFlag)
  688. check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
  689. if(HAVE_C_FLAG_Wno_long_double)
  690. # The Mac version of GCC warns about use of long double. Disable it.
  691. get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
  692. if(MPRINTF_COMPILE_FLAGS)
  693. set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
  694. else(MPRINTF_COMPILE_FLAGS)
  695. set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
  696. endif(MPRINTF_COMPILE_FLAGS)
  697. set_source_files_properties(mprintf.c PROPERTIES
  698. COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
  699. endif(HAVE_C_FLAG_Wno_long_double)
  700. endif(CMAKE_COMPILER_IS_GNUCC AND APPLE)
  701. if(HAVE_SOCKLEN_T)
  702. set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t")
  703. if(WIN32)
  704. set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h;ws2tcpip.h")
  705. elseif(HAVE_SYS_SOCKET_H)
  706. set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
  707. endif()
  708. check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T)
  709. set(CMAKE_EXTRA_INCLUDE_FILES)
  710. if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T)
  711. message(FATAL_ERROR
  712. "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log")
  713. endif()
  714. else()
  715. set(CURL_TYPEOF_CURL_SOCKLEN_T int)
  716. set(CURL_SIZEOF_CURL_SOCKLEN_T ${SIZEOF_INT})
  717. endif()
  718. include(CMake/OtherTests.cmake)
  719. add_definitions(-DHAVE_CONFIG_H)
  720. # For windows, do not allow the compiler to use default target (Vista).
  721. if(WIN32)
  722. add_definitions(-D_WIN32_WINNT=0x0501)
  723. endif(WIN32)
  724. if(MSVC)
  725. add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
  726. endif(MSVC)
  727. # Sets up the dependencies (zlib, OpenSSL, etc.) of a cURL subproject according to options.
  728. # TODO This is far to be complete!
  729. function(SETUP_CURL_DEPENDENCIES TARGET_NAME)
  730. if(CURL_ZLIB AND ZLIB_FOUND)
  731. include_directories(${ZLIB_INCLUDE_DIR})
  732. endif()
  733. if(CURL_ZLIB AND ZLIB_FOUND)
  734. target_link_libraries(${TARGET_NAME} ${ZLIB_LIBRARIES})
  735. #ADD_DEFINITIONS( -DHAVE_ZLIB_H -DHAVE_ZLIB -DHAVE_LIBZ )
  736. endif()
  737. if(CMAKE_USE_OPENSSL AND OPENSSL_FOUND)
  738. include_directories(${OPENSSL_INCLUDE_DIR})
  739. endif()
  740. if(CMAKE_USE_OPENSSL AND CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
  741. target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES})
  742. #ADD_DEFINITIONS( -DUSE_SSLEAY )
  743. endif()
  744. endfunction()
  745. # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
  746. function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
  747. file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
  748. string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  749. string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  750. string(REGEX REPLACE "\\\\\n" "§!§" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  751. string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  752. string(REPLACE "§!§" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
  753. string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
  754. 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.
  755. file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
  756. endfunction()
  757. add_subdirectory(lib)
  758. if(BUILD_CURL_EXE)
  759. add_subdirectory(src)
  760. endif()
  761. if(BUILD_CURL_TESTS)
  762. add_subdirectory(tests)
  763. endif()
  764. # This needs to be run very last so other parts of the scripts can take advantage of this.
  765. if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
  766. 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")
  767. endif()
  768. # Installation.
  769. # First, install generated curlbuild.h
  770. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/curl/curlbuild.h"
  771. DESTINATION include/curl )
  772. # Next, install other headers excluding curlbuild.h
  773. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
  774. DESTINATION include
  775. FILES_MATCHING PATTERN "*.h"
  776. PATTERN "curlbuild.h" EXCLUDE)