blob: bf25b1f792ff20569fc0c8ec2abdb4ba911f3381 [file] [log] [blame]
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
Elliott Hughes1ef06ba2018-05-30 15:43:58 -07008# Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07009#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
Alex Deymod15eaac2016-06-28 14:49:26 -070012# are also available at https://curl.haxx.se/docs/copyright.html.
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070013#
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###########################################################################
Elliott Hughescee03382017-06-23 12:17:18 -070022# curl/libcurl CMake script
Lucas Eckels9bd90e62012-08-06 15:07:02 -070023# by Tetetest and Sukender (Benoit Neil)
24
25# TODO:
26# The output .so file lacks the soname number which we currently have within the lib/Makefile.am file
27# Add full (4 or 5 libs) SSL support
28# 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).
29# Add CTests(?)
30# Check on all possible platforms
31# Test with as many configurations possible (With or without any option)
32# Create scripts that help keeping the CMake build system up to date (to reduce maintenance). According to Tetetest:
33# - lists of headers that 'configure' checks for;
34# - curl-specific tests (the ones that are in m4/curl-*.m4 files);
35# - (most obvious thing:) curl version numbers.
36# Add documentation subproject
37#
38# To check:
39# (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
40# (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.
Alex Deymo486467e2017-12-19 19:04:07 +010041cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
Lucas Eckels9bd90e62012-08-06 15:07:02 -070042set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
43include(Utilities)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070044include(Macros)
Elliott Hughescee03382017-06-23 12:17:18 -070045include(CMakeDependentOption)
Alex Deymo486467e2017-12-19 19:04:07 +010046include(CheckCCompilerFlag)
Lucas Eckels9bd90e62012-08-06 15:07:02 -070047
48project( CURL C )
49
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070050message(WARNING "the curl cmake build system is poorly maintained. Be aware")
Lucas Eckels9bd90e62012-08-06 15:07:02 -070051
52file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070053string (REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
54 CURL_VERSION ${CURL_VERSION_H_CONTENTS})
55string (REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
56string (REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
57 CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
58string (REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
Lucas Eckels9bd90e62012-08-06 15:07:02 -070059
60include_regular_expression("^.*$") # Sukender: Is it necessary?
61
62# Setup package meta-data
63# SET(PACKAGE "curl")
Lucas Eckels9bd90e62012-08-06 15:07:02 -070064message(STATUS "curl version=[${CURL_VERSION}]")
65# SET(PACKAGE_TARNAME "curl")
66# SET(PACKAGE_NAME "curl")
67# SET(PACKAGE_VERSION "-")
68# SET(PACKAGE_STRING "curl-")
Alex Deymod15eaac2016-06-28 14:49:26 -070069# SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/")
Lucas Eckels9bd90e62012-08-06 15:07:02 -070070set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
71set(OS "\"${CMAKE_SYSTEM_NAME}\"")
72
73include_directories(${PROJECT_BINARY_DIR}/include/curl)
74include_directories( ${CURL_SOURCE_DIR}/include )
75
Elliott Hughes82be86d2017-09-20 17:00:17 -070076option(CURL_WERROR "Turn compiler warnings into errors" OFF)
Alex Deymo486467e2017-12-19 19:04:07 +010077option(PICKY_COMPILER "Enable picky compiler options" ON)
Elliott Hughescee03382017-06-23 12:17:18 -070078option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
Lucas Eckels9bd90e62012-08-06 15:07:02 -070079option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070080option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
Elliott Hughescee03382017-06-23 12:17:18 -070081if(WIN32)
Elliott Hughes82be86d2017-09-20 17:00:17 -070082 option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
83 option(ENABLE_INET_PTON "Set to OFF to prevent usage of inet_pton when building against modern SDKs while still requiring compatibility with older Windows versions, such as Windows XP, Windows Server 2003 etc." ON)
Elliott Hughescee03382017-06-23 12:17:18 -070084endif()
Elliott Hughes82be86d2017-09-20 17:00:17 -070085
86CMAKE_DEPENDENT_OPTION(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
87 ON "NOT ENABLE_ARES"
88 OFF)
89
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070090option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
91option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
92
Alex Deymo486467e2017-12-19 19:04:07 +010093if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
94 if (PICKY_COMPILER)
95 foreach (_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wundef -Wno-format-nonliteral -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wno-sign-conversion -Wvla -Wdouble-promotion -Wno-system-headers)
96 # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
97 # test result in.
98 CHECK_C_COMPILER_FLAG(${_CCOPT} OPT${_CCOPT})
99 if(OPT${_CCOPT})
100 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
101 endif()
102 endforeach()
103 endif(PICKY_COMPILER)
104endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
105
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700106if (ENABLE_DEBUG)
107 # DEBUGBUILD will be defined only for Debug builds
108 if(NOT CMAKE_VERSION VERSION_LESS 3.0)
109 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
110 else()
111 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUGBUILD)
112 endif()
113 set(ENABLE_CURLDEBUG ON)
114endif()
115
116if (ENABLE_CURLDEBUG)
117 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
118endif()
119
Elliott Hughes82be86d2017-09-20 17:00:17 -0700120# For debug libs and exes, add "-d" postfix
121set(CMAKE_DEBUG_POSTFIX "-d" CACHE STRING "Set debug library postfix")
122
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700123# initialize CURL_LIBS
124set(CURL_LIBS "")
125
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700126if(ENABLE_ARES)
127 set(USE_ARES 1)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700128 find_package(CARES REQUIRED)
129 list(APPEND CURL_LIBS ${CARES_LIBRARY} )
130 set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
131endif()
132
Elliott Hughescee03382017-06-23 12:17:18 -0700133include(CurlSymbolHiding)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700134
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700135option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
136mark_as_advanced(HTTP_ONLY)
137option(CURL_DISABLE_FTP "disables FTP" OFF)
138mark_as_advanced(CURL_DISABLE_FTP)
139option(CURL_DISABLE_LDAP "disables LDAP" OFF)
140mark_as_advanced(CURL_DISABLE_LDAP)
141option(CURL_DISABLE_TELNET "disables Telnet" OFF)
142mark_as_advanced(CURL_DISABLE_TELNET)
143option(CURL_DISABLE_DICT "disables DICT" OFF)
144mark_as_advanced(CURL_DISABLE_DICT)
145option(CURL_DISABLE_FILE "disables FILE" OFF)
146mark_as_advanced(CURL_DISABLE_FILE)
147option(CURL_DISABLE_TFTP "disables TFTP" OFF)
148mark_as_advanced(CURL_DISABLE_TFTP)
149option(CURL_DISABLE_HTTP "disables HTTP" OFF)
150mark_as_advanced(CURL_DISABLE_HTTP)
151
152option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
153mark_as_advanced(CURL_DISABLE_LDAPS)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700154
155option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
156mark_as_advanced(CURL_DISABLE_RTSP)
157option(CURL_DISABLE_PROXY "to disable proxy" OFF)
158mark_as_advanced(CURL_DISABLE_PROXY)
159option(CURL_DISABLE_POP3 "to disable POP3" OFF)
160mark_as_advanced(CURL_DISABLE_POP3)
161option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
162mark_as_advanced(CURL_DISABLE_IMAP)
163option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
164mark_as_advanced(CURL_DISABLE_SMTP)
165option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
166mark_as_advanced(CURL_DISABLE_GOPHER)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700167
168if(HTTP_ONLY)
169 set(CURL_DISABLE_FTP ON)
170 set(CURL_DISABLE_LDAP ON)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700171 set(CURL_DISABLE_LDAPS ON)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700172 set(CURL_DISABLE_TELNET ON)
173 set(CURL_DISABLE_DICT ON)
174 set(CURL_DISABLE_FILE ON)
175 set(CURL_DISABLE_TFTP ON)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700176 set(CURL_DISABLE_RTSP ON)
177 set(CURL_DISABLE_POP3 ON)
178 set(CURL_DISABLE_IMAP ON)
179 set(CURL_DISABLE_SMTP ON)
180 set(CURL_DISABLE_GOPHER ON)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700181endif()
182
183option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
184mark_as_advanced(CURL_DISABLE_COOKIES)
185
186option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
187mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
188option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
189mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700190option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700191mark_as_advanced(ENABLE_IPV6)
Alex Deymod15eaac2016-06-28 14:49:26 -0700192if(ENABLE_IPV6 AND NOT WIN32)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700193 include(CheckStructHasMember)
194 check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
195 HAVE_SOCKADDR_IN6_SIN6_ADDR)
196 check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
197 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
198 if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
199 message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
200 # Force the feature off as this name is used as guard macro...
201 set(ENABLE_IPV6 OFF
202 CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700203 endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700204endif()
205
Alex Deymo486467e2017-12-19 19:04:07 +0100206CURL_NROFF_CHECK()
207find_package(Perl)
208
209CMAKE_DEPENDENT_OPTION(ENABLE_MANUAL "to provide the built-in manual"
210 ON "NROFF_USEFUL;PERL_FOUND"
211 OFF)
212
213if(NOT PERL_FOUND)
214 message(STATUS "Perl not found, testing disabled.")
215 set(BUILD_TESTING OFF)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700216endif()
Alex Deymo486467e2017-12-19 19:04:07 +0100217if(ENABLE_MANUAL)
218 set(USE_MANUAL ON)
219endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700220
221# We need ansi c-flags, especially on HP
222set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
223set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
224
Elliott Hughes82be86d2017-09-20 17:00:17 -0700225if(CURL_STATIC_CRT)
226 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
227 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
228endif()
229
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700230# Disable warnings on Borland to avoid changing 3rd party code.
231if(BORLAND)
232 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
233endif(BORLAND)
234
235# If we are on AIX, do the _ALL_SOURCE magic
236if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
237 set(_ALL_SOURCE 1)
238endif(${CMAKE_SYSTEM_NAME} MATCHES AIX)
239
240# Include all the necessary files for macros
241include (CheckFunctionExists)
242include (CheckIncludeFile)
243include (CheckIncludeFiles)
244include (CheckLibraryExists)
245include (CheckSymbolExists)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700246include (CheckTypeSize)
247include (CheckCSourceCompiles)
Alex Deymod15eaac2016-06-28 14:49:26 -0700248include (CMakeDependentOption)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700249
250# On windows preload settings
251if(WIN32)
Elliott Hughes82be86d2017-09-20 17:00:17 -0700252 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700253 include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
254endif(WIN32)
255
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700256if(ENABLE_THREADED_RESOLVER)
Elliott Hughes82be86d2017-09-20 17:00:17 -0700257 find_package(Threads REQUIRED)
Elliott Hughescee03382017-06-23 12:17:18 -0700258 if(WIN32)
259 set(USE_THREADS_WIN32 ON)
260 else()
Elliott Hughes82be86d2017-09-20 17:00:17 -0700261 set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
262 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700263 endif()
Elliott Hughes82be86d2017-09-20 17:00:17 -0700264 set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700265endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700266
267# Check for all needed libraries
268check_library_exists_concat("dl" dlopen HAVE_LIBDL)
269check_library_exists_concat("socket" connect HAVE_LIBSOCKET)
270check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
271
272# Yellowtab Zeta needs different libraries than BeOS 5.
273if(BEOS)
274 set(NOT_NEED_LIBNSL 1)
275 check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
276 check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
277endif(BEOS)
278
279if(NOT NOT_NEED_LIBNSL)
280 check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL)
281endif(NOT NOT_NEED_LIBNSL)
282
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700283check_function_exists(gethostname HAVE_GETHOSTNAME)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700284
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700285if(WIN32)
286 check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
287 check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
Elliott Hughes1ef06ba2018-05-30 15:43:58 -0700288 list(APPEND CURL_LIBS "advapi32")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700289endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700290
Elliott Hughes82be86d2017-09-20 17:00:17 -0700291# check SSL libraries
292# TODO support GNUTLS, NSS, POLARSSL, AXTLS, CYASSL
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700293
Elliott Hughes82be86d2017-09-20 17:00:17 -0700294if(APPLE)
295 option(CMAKE_USE_DARWINSSL "enable Apple OS native SSL/TLS" OFF)
296endif()
Alex Deymod15eaac2016-06-28 14:49:26 -0700297if(WIN32)
Elliott Hughes82be86d2017-09-20 17:00:17 -0700298 option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
299 cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
300 CMAKE_USE_WINSSL OFF)
301endif()
302option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
303
304set(openssl_default ON)
305if(WIN32 OR CMAKE_USE_DARWINSSL OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
306 set(openssl_default OFF)
307endif()
308option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default})
309
310collect_true(enabled_ssl_options enabled_ssl_options_count
311 CMAKE_USE_WINSSL
312 CMAKE_USE_DARWINSSL
313 CMAKE_USE_OPENSSL
314 CMAKE_USE_MBEDTLS
315)
316if(enabled_ssl_options_count GREATER 1)
317 message(FATAL_ERROR "Multiple SSL options specified: ${enabled_ssl_options}. Please pick at most one and disable the rest.")
Alex Deymod15eaac2016-06-28 14:49:26 -0700318endif()
319
Elliott Hughes82be86d2017-09-20 17:00:17 -0700320if(CMAKE_USE_WINSSL)
321 set(SSL_ENABLED ON)
322 set(USE_SCHANNEL ON) # Windows native SSL/TLS support
323 set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
324 list(APPEND CURL_LIBS "crypt32")
325endif()
326if(CURL_WINDOWS_SSPI)
327 set(USE_WINDOWS_SSPI ON)
328 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
329endif()
330
331if(CMAKE_USE_DARWINSSL)
332 find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
333 if(NOT COREFOUNDATION_FRAMEWORK)
334 message(FATAL_ERROR "CoreFoundation framework not found")
335 endif()
336
337 find_library(SECURITY_FRAMEWORK "Security")
338 if(NOT SECURITY_FRAMEWORK)
339 message(FATAL_ERROR "Security framework not found")
340 endif()
341
342 set(SSL_ENABLED ON)
343 set(USE_DARWINSSL ON)
344 list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
345endif()
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700346
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700347if(CMAKE_USE_OPENSSL)
Elliott Hughes82be86d2017-09-20 17:00:17 -0700348 find_package(OpenSSL REQUIRED)
349 set(SSL_ENABLED ON)
350 set(USE_OPENSSL ON)
351 set(HAVE_LIBCRYPTO ON)
352 set(HAVE_LIBSSL ON)
353 list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
354 include_directories(${OPENSSL_INCLUDE_DIR})
355 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
356 check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
357 check_include_file("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
358 check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
359 check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
Elliott Hughes82be86d2017-09-20 17:00:17 -0700360 check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
361 check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
362 check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
363 check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
364 check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
365 check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
366 check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)
367endif()
368
369if(CMAKE_USE_MBEDTLS)
370 find_package(MbedTLS REQUIRED)
371 set(SSL_ENABLED ON)
372 set(USE_MBEDTLS ON)
373 list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
374 include_directories(${MBEDTLS_INCLUDE_DIRS})
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700375endif()
376
Elliott Hughescee03382017-06-23 12:17:18 -0700377option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
378if(USE_NGHTTP2)
379 find_package(NGHTTP2 REQUIRED)
380 include_directories(${NGHTTP2_INCLUDE_DIRS})
381 list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
382endif()
383
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700384if(NOT CURL_DISABLE_LDAP)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700385 if(WIN32)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700386 option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
387 if(USE_WIN32_LDAP)
Alex Deymoe3149cc2016-10-05 11:18:42 -0700388 check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700389 if(NOT HAVE_WLDAP32)
390 set(USE_WIN32_LDAP OFF)
391 endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700392 endif()
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700393 endif()
394
395 option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
396 mark_as_advanced(CMAKE_USE_OPENLDAP)
397 set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
398 set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
399
400 if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
401 message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
402 endif()
Alex Deymoe3149cc2016-10-05 11:18:42 -0700403
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700404 # Now that we know, we're not using windows LDAP...
Alex Deymoe3149cc2016-10-05 11:18:42 -0700405 if(USE_WIN32_LDAP)
406 check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
407 check_include_file_concat("winber.h" HAVE_WINBER_H)
408 else()
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700409 # Check for LDAP
410 set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
411 check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
412 check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700413
Alex Deymoe3149cc2016-10-05 11:18:42 -0700414 set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
415 set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700416 if(CMAKE_LDAP_INCLUDE_DIR)
Alex Deymoe3149cc2016-10-05 11:18:42 -0700417 list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700418 endif()
Alex Deymoe3149cc2016-10-05 11:18:42 -0700419 check_include_file_concat("ldap.h" HAVE_LDAP_H)
420 check_include_file_concat("lber.h" HAVE_LBER_H)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700421
Alex Deymoe3149cc2016-10-05 11:18:42 -0700422 if(NOT HAVE_LDAP_H)
423 message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
424 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
425 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
426 elseif(NOT HAVE_LIBLDAP)
427 message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
428 set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
429 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700430 else()
Alex Deymoe3149cc2016-10-05 11:18:42 -0700431 if(CMAKE_USE_OPENLDAP)
432 set(USE_OPENLDAP ON)
433 endif()
434 if(CMAKE_LDAP_INCLUDE_DIR)
435 include_directories(${CMAKE_LDAP_INCLUDE_DIR})
436 endif()
437 set(NEED_LBER_H ON)
438 set(_HEADER_LIST)
439 if(HAVE_WINDOWS_H)
440 list(APPEND _HEADER_LIST "windows.h")
441 endif()
442 if(HAVE_SYS_TYPES_H)
443 list(APPEND _HEADER_LIST "sys/types.h")
444 endif()
445 list(APPEND _HEADER_LIST "ldap.h")
446
447 set(_SRC_STRING "")
448 foreach(_HEADER ${_HEADER_LIST})
449 set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
450 endforeach()
451
452 set(_SRC_STRING
453 "
454 ${_INCLUDE_STRING}
455 int main(int argc, char ** argv)
456 {
457 BerValue *bvp = NULL;
458 BerElement *bep = ber_init(bvp);
459 ber_free(bep, 1);
460 return 0;
461 }"
462 )
463 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
464 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
465 if(HAVE_LIBLBER)
466 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
467 endif()
468 check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
469
470 if(NOT_NEED_LBER_H)
471 set(NEED_LBER_H OFF)
472 else()
473 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
474 endif()
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700475 endif()
476 endif()
477
478endif()
479
480# No ldap, no ldaps.
481if(CURL_DISABLE_LDAP)
482 if(NOT CURL_DISABLE_LDAPS)
483 message(STATUS "LDAP needs to be enabled to support LDAPS")
484 set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
485 endif()
486endif()
487
488if(NOT CURL_DISABLE_LDAPS)
489 check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
490 check_include_file_concat("ldapssl.h" HAVE_LDAPSSL_H)
491endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700492
493# Check for idn
Elliott Hughescee03382017-06-23 12:17:18 -0700494check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700495
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700496# Check for symbol dlopen (same as HAVE_LIBDL)
497check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
498
Elliott Hughescee03382017-06-23 12:17:18 -0700499option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700500set(HAVE_LIBZ OFF)
501set(HAVE_ZLIB_H OFF)
502set(HAVE_ZLIB OFF)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700503if(CURL_ZLIB)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700504 find_package(ZLIB QUIET)
505 if(ZLIB_FOUND)
506 set(HAVE_ZLIB_H ON)
507 set(HAVE_ZLIB ON)
508 set(HAVE_LIBZ ON)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700509 list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
510 include_directories(${ZLIB_INCLUDE_DIRS})
Alex Deymod15eaac2016-06-28 14:49:26 -0700511 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700512 endif()
513endif()
514
Elliott Hughes1ef06ba2018-05-30 15:43:58 -0700515option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
516set(HAVE_BROTLI OFF)
517if(CURL_BROTLI)
518 find_package(BROTLI QUIET)
519 if(BROTLI_FOUND)
520 set(HAVE_BROTLI ON)
521 list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
522 include_directories(${BROTLI_INCLUDE_DIRS})
523 list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
524 endif()
525endif()
526
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700527#libSSH2
528option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
529mark_as_advanced(CMAKE_USE_LIBSSH2)
530set(USE_LIBSSH2 OFF)
531set(HAVE_LIBSSH2 OFF)
532set(HAVE_LIBSSH2_H OFF)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700533
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700534if(CMAKE_USE_LIBSSH2)
535 find_package(LibSSH2)
536 if(LIBSSH2_FOUND)
537 list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
538 set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
Alex Deymod15eaac2016-06-28 14:49:26 -0700539 list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700540 include_directories("${LIBSSH2_INCLUDE_DIR}")
541 set(HAVE_LIBSSH2 ON)
542 set(USE_LIBSSH2 ON)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700543
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700544 # find_package has already found the headers
545 set(HAVE_LIBSSH2_H ON)
546 set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
547 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
548
549 # now check for specific libssh2 symbols as they were added in different versions
550 set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
551 check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION)
552 check_function_exists(libssh2_init HAVE_LIBSSH2_INIT)
553 check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT)
554 check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
555 check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
556 set(CMAKE_EXTRA_INCLUDE_FILES "")
557
558 endif(LIBSSH2_FOUND)
559endif(CMAKE_USE_LIBSSH2)
560
561option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
562mark_as_advanced(CMAKE_USE_GSSAPI)
563
564if(CMAKE_USE_GSSAPI)
565 find_package(GSS)
566
Alex Deymod15eaac2016-06-28 14:49:26 -0700567 set(HAVE_GSSAPI ${GSS_FOUND})
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700568 if(GSS_FOUND)
569
570 message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
571
Alex Deymod15eaac2016-06-28 14:49:26 -0700572 list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRECTORIES})
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700573 check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
574 check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
575 check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
576
577 if(GSS_FLAVOUR STREQUAL "Heimdal")
578 set(HAVE_GSSHEIMDAL ON)
579 else() # MIT
580 set(HAVE_GSSMIT ON)
581 set(_INCLUDE_LIST "")
582 if(HAVE_GSSAPI_GSSAPI_H)
583 list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
584 endif()
585 if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
586 list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
587 endif()
588 if(HAVE_GSSAPI_GSSAPI_KRB5_H)
589 list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
590 endif()
591
592 string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
593 string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
594
595 foreach(_dir ${GSS_LINK_DIRECTORIES})
596 set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
597 endforeach()
598
599 set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
600 set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
601 check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
602 if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
603 set(HAVE_OLD_GSSMIT ON)
604 endif()
605
606 endif()
607
Alex Deymod15eaac2016-06-28 14:49:26 -0700608 include_directories(${GSS_INCLUDE_DIRECTORIES})
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700609 link_directories(${GSS_LINK_DIRECTORIES})
610 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
611 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
612 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
613 list(APPEND CURL_LIBS ${GSS_LIBRARIES})
614
615 else()
616 message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
617 endif()
618endif()
619
620option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
621if(ENABLE_UNIX_SOCKETS)
622 include(CheckStructHasMember)
623 check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
624else()
625 unset(USE_UNIX_SOCKETS CACHE)
626endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700627
Alex Deymod15eaac2016-06-28 14:49:26 -0700628
Elliott Hughes82be86d2017-09-20 17:00:17 -0700629#
630# CA handling
631#
632set(CURL_CA_BUNDLE "auto" CACHE STRING
633 "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
634set(CURL_CA_FALLBACK OFF CACHE BOOL
635 "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
636set(CURL_CA_PATH "auto" CACHE STRING
637 "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
638
639if("${CURL_CA_BUNDLE}" STREQUAL "")
640 message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
641elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
642 unset(CURL_CA_BUNDLE CACHE)
643elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
644 unset(CURL_CA_BUNDLE CACHE)
645 set(CURL_CA_BUNDLE_AUTODETECT TRUE)
646else()
647 set(CURL_CA_BUNDLE_SET TRUE)
648endif()
649
650if("${CURL_CA_PATH}" STREQUAL "")
651 message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
652elseif("${CURL_CA_PATH}" STREQUAL "none")
653 unset(CURL_CA_PATH CACHE)
654elseif("${CURL_CA_PATH}" STREQUAL "auto")
655 unset(CURL_CA_PATH CACHE)
656 set(CURL_CA_PATH_AUTODETECT TRUE)
657else()
658 set(CURL_CA_PATH_SET TRUE)
659endif()
660
661if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
662 # Skip autodetection of unset CA path because CA bundle is set explicitly
663elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
664 # Skip autodetection of unset CA bundle because CA path is set explicitly
665elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
666 # first try autodetecting a CA bundle, then a CA path
667
668 if(CURL_CA_BUNDLE_AUTODETECT)
669 set(SEARCH_CA_BUNDLE_PATHS
670 /etc/ssl/certs/ca-certificates.crt
671 /etc/pki/tls/certs/ca-bundle.crt
672 /usr/share/ssl/certs/ca-bundle.crt
673 /usr/local/share/certs/ca-root-nss.crt
674 /etc/ssl/cert.pem)
675
676 foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
677 if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
678 message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
679 set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
680 set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
681 break()
682 endif()
683 endforeach()
684 endif()
685
686 if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
687 if(EXISTS "/etc/ssl/certs")
688 set(CURL_CA_PATH "/etc/ssl/certs")
689 set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
690 endif()
691 endif()
692endif()
693
694if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
695 message(FATAL_ERROR
696 "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
697 "Set CURL_CA_PATH=none or enable one of those TLS backends.")
698endif()
699
700
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700701# Check for header files
702if(NOT UNIX)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700703 check_include_file_concat("windows.h" HAVE_WINDOWS_H)
704 check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700705 check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
706 check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
Elliott Hughes82be86d2017-09-20 17:00:17 -0700707 if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL)
708 set(CURL_LIBS ${CURL_LIBS} "crypt32")
Alex Deymod15eaac2016-06-28 14:49:26 -0700709 endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700710endif(NOT UNIX)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700711
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700712check_include_file_concat("stdio.h" HAVE_STDIO_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700713check_include_file_concat("inttypes.h" HAVE_INTTYPES_H)
714check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H)
715check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H)
716check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H)
717check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H)
718check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H)
719check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H)
720check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H)
721check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H)
722check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H)
723check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H)
724check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H)
725check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H)
726check_include_file_concat("sys/un.h" HAVE_SYS_UN_H)
727check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H)
Elliott Hughes82be86d2017-09-20 17:00:17 -0700728check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700729check_include_file_concat("alloca.h" HAVE_ALLOCA_H)
730check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H)
731check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H)
732check_include_file_concat("assert.h" HAVE_ASSERT_H)
733check_include_file_concat("crypto.h" HAVE_CRYPTO_H)
734check_include_file_concat("des.h" HAVE_DES_H)
735check_include_file_concat("err.h" HAVE_ERR_H)
736check_include_file_concat("errno.h" HAVE_ERRNO_H)
737check_include_file_concat("fcntl.h" HAVE_FCNTL_H)
Elliott Hughescee03382017-06-23 12:17:18 -0700738check_include_file_concat("idn2.h" HAVE_IDN2_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700739check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
740check_include_file_concat("io.h" HAVE_IO_H)
741check_include_file_concat("krb.h" HAVE_KRB_H)
742check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700743check_include_file_concat("locale.h" HAVE_LOCALE_H)
744check_include_file_concat("net/if.h" HAVE_NET_IF_H)
745check_include_file_concat("netdb.h" HAVE_NETDB_H)
746check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H)
747check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700748
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700749check_include_file_concat("pem.h" HAVE_PEM_H)
750check_include_file_concat("poll.h" HAVE_POLL_H)
751check_include_file_concat("pwd.h" HAVE_PWD_H)
752check_include_file_concat("rsa.h" HAVE_RSA_H)
753check_include_file_concat("setjmp.h" HAVE_SETJMP_H)
754check_include_file_concat("sgtty.h" HAVE_SGTTY_H)
755check_include_file_concat("signal.h" HAVE_SIGNAL_H)
756check_include_file_concat("ssl.h" HAVE_SSL_H)
757check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
758check_include_file_concat("stdint.h" HAVE_STDINT_H)
759check_include_file_concat("stdio.h" HAVE_STDIO_H)
760check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
761check_include_file_concat("string.h" HAVE_STRING_H)
762check_include_file_concat("strings.h" HAVE_STRINGS_H)
763check_include_file_concat("stropts.h" HAVE_STROPTS_H)
764check_include_file_concat("termio.h" HAVE_TERMIO_H)
765check_include_file_concat("termios.h" HAVE_TERMIOS_H)
766check_include_file_concat("time.h" HAVE_TIME_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700767check_include_file_concat("unistd.h" HAVE_UNISTD_H)
768check_include_file_concat("utime.h" HAVE_UTIME_H)
769check_include_file_concat("x509.h" HAVE_X509_H)
770
771check_include_file_concat("process.h" HAVE_PROCESS_H)
772check_include_file_concat("stddef.h" HAVE_STDDEF_H)
773check_include_file_concat("dlfcn.h" HAVE_DLFCN_H)
774check_include_file_concat("malloc.h" HAVE_MALLOC_H)
775check_include_file_concat("memory.h" HAVE_MEMORY_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700776check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
777check_include_file_concat("stdint.h" HAVE_STDINT_H)
778check_include_file_concat("sockio.h" HAVE_SOCKIO_H)
779check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700780
781check_type_size(size_t SIZEOF_SIZE_T)
782check_type_size(ssize_t SIZEOF_SSIZE_T)
783check_type_size("long long" SIZEOF_LONG_LONG)
784check_type_size("long" SIZEOF_LONG)
785check_type_size("short" SIZEOF_SHORT)
786check_type_size("int" SIZEOF_INT)
787check_type_size("__int64" SIZEOF___INT64)
788check_type_size("long double" SIZEOF_LONG_DOUBLE)
789check_type_size("time_t" SIZEOF_TIME_T)
790if(NOT HAVE_SIZEOF_SSIZE_T)
791 if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
792 set(ssize_t long)
793 endif(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
794 if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
795 set(ssize_t __int64)
796 endif(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
797endif(NOT HAVE_SIZEOF_SSIZE_T)
Elliott Hughescee03382017-06-23 12:17:18 -0700798# off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700799
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700800if(HAVE_SIZEOF_LONG_LONG)
801 set(HAVE_LONGLONG 1)
802 set(HAVE_LL 1)
803endif(HAVE_SIZEOF_LONG_LONG)
804
805find_file(RANDOM_FILE urandom /dev)
806mark_as_advanced(RANDOM_FILE)
807
808# Check for some functions that are used
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700809if(HAVE_LIBWS2_32)
810 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
811elseif(HAVE_LIBSOCKET)
812 set(CMAKE_REQUIRED_LIBRARIES socket)
813endif()
814
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700815check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
816check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
Elliott Hughescee03382017-06-23 12:17:18 -0700817# poll on macOS is unreliable, it first did not exist, then was broken until
818# fixed in 10.9 only to break again in 10.12.
819if(NOT APPLE)
820 check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
821endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700822check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
823check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP)
824check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR)
825check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R)
826check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME)
827check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
828check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP)
829check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP)
830check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI)
831check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
832check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
833if(NOT HAVE_STRNCMPI)
834 set(HAVE_STRCMPI)
835endif(NOT HAVE_STRNCMPI)
836check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
837check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
838check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
839check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR)
840check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA)
841check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
842check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR)
843check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR)
844check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
845check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
846check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF)
847check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
848check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
849check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
850check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
851check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
852check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700853check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
854check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
855
856check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
857check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
858
859check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
860check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
861if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
862 set(HAVE_SIGNAL 1)
863endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
864check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
865check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
866check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
867check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R)
868check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
869check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR)
870check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700871check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700872check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
873check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
874check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
875check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
876check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
877check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700878check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
Alex Deymo486467e2017-12-19 19:04:07 +0100879check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700880check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
881check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
882check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
883check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
Alex Deymo486467e2017-12-19 19:04:07 +0100884check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700885
886# symbol exists in win32, but function does not.
Elliott Hughes82be86d2017-09-20 17:00:17 -0700887if(WIN32)
888 if(ENABLE_INET_PTON)
889 check_function_exists(inet_pton HAVE_INET_PTON)
890 # _WIN32_WINNT_VISTA (0x0600)
891 add_definitions(-D_WIN32_WINNT=0x0600)
892 else()
893 # _WIN32_WINNT_WINXP (0x0501)
894 add_definitions(-D_WIN32_WINNT=0x0501)
895 endif()
896else()
897 check_function_exists(inet_pton HAVE_INET_PTON)
898endif()
899
900check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
901if(HAVE_FSETXATTR)
902 foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
903 curl_internal_test_run(${CURL_TEST})
904 endforeach(CURL_TEST)
905endif(HAVE_FSETXATTR)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700906
907# sigaction and sigsetjmp are special. Use special mechanism for
908# detecting those, but only if previous attempt failed.
909if(HAVE_SIGNAL_H)
910 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
911endif(HAVE_SIGNAL_H)
912
913if(NOT HAVE_SIGSETJMP)
914 if(HAVE_SETJMP_H)
915 check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
916 if(HAVE_MACRO_SIGSETJMP)
917 set(HAVE_SIGSETJMP 1)
918 endif(HAVE_MACRO_SIGSETJMP)
919 endif(HAVE_SETJMP_H)
920endif(NOT HAVE_SIGSETJMP)
921
922# If there is no stricmp(), do not allow LDAP to parse URLs
923if(NOT HAVE_STRICMP)
924 set(HAVE_LDAP_URL_PARSE 1)
925endif(NOT HAVE_STRICMP)
926
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700927# Do curl specific tests
928foreach(CURL_TEST
929 HAVE_FCNTL_O_NONBLOCK
930 HAVE_IOCTLSOCKET
931 HAVE_IOCTLSOCKET_CAMEL
932 HAVE_IOCTLSOCKET_CAMEL_FIONBIO
933 HAVE_IOCTLSOCKET_FIONBIO
934 HAVE_IOCTL_FIONBIO
935 HAVE_IOCTL_SIOCGIFADDR
936 HAVE_SETSOCKOPT_SO_NONBLOCK
937 HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
938 TIME_WITH_SYS_TIME
939 HAVE_O_NONBLOCK
940 HAVE_GETHOSTBYADDR_R_5
941 HAVE_GETHOSTBYADDR_R_7
942 HAVE_GETHOSTBYADDR_R_8
943 HAVE_GETHOSTBYADDR_R_5_REENTRANT
944 HAVE_GETHOSTBYADDR_R_7_REENTRANT
945 HAVE_GETHOSTBYADDR_R_8_REENTRANT
946 HAVE_GETHOSTBYNAME_R_3
947 HAVE_GETHOSTBYNAME_R_5
948 HAVE_GETHOSTBYNAME_R_6
949 HAVE_GETHOSTBYNAME_R_3_REENTRANT
950 HAVE_GETHOSTBYNAME_R_5_REENTRANT
951 HAVE_GETHOSTBYNAME_R_6_REENTRANT
952 HAVE_SOCKLEN_T
953 HAVE_IN_ADDR_T
954 HAVE_BOOL_T
955 STDC_HEADERS
956 RETSIGTYPE_TEST
957 HAVE_INET_NTOA_R_DECL
958 HAVE_INET_NTOA_R_DECL_REENTRANT
959 HAVE_GETADDRINFO
960 HAVE_FILE_OFFSET_BITS
961 )
962 curl_internal_test(${CURL_TEST})
963endforeach(CURL_TEST)
Elliott Hughescee03382017-06-23 12:17:18 -0700964
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700965if(HAVE_FILE_OFFSET_BITS)
966 set(_FILE_OFFSET_BITS 64)
Elliott Hughescee03382017-06-23 12:17:18 -0700967 set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700968endif(HAVE_FILE_OFFSET_BITS)
Elliott Hughescee03382017-06-23 12:17:18 -0700969check_type_size("off_t" SIZEOF_OFF_T)
Alex Deymo486467e2017-12-19 19:04:07 +0100970
971# include this header to get the type
972set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
973set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
974check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
975set(CMAKE_EXTRA_INCLUDE_FILES "")
976
Elliott Hughescee03382017-06-23 12:17:18 -0700977set(CMAKE_REQUIRED_FLAGS)
978
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700979foreach(CURL_TEST
980 HAVE_GLIBC_STRERROR_R
981 HAVE_POSIX_STRERROR_R
982 )
983 curl_internal_test_run(${CURL_TEST})
984endforeach(CURL_TEST)
985
986# Check for reentrant
987foreach(CURL_TEST
988 HAVE_GETHOSTBYADDR_R_5
989 HAVE_GETHOSTBYADDR_R_7
990 HAVE_GETHOSTBYADDR_R_8
991 HAVE_GETHOSTBYNAME_R_3
992 HAVE_GETHOSTBYNAME_R_5
993 HAVE_GETHOSTBYNAME_R_6
994 HAVE_INET_NTOA_R_DECL_REENTRANT)
995 if(NOT ${CURL_TEST})
996 if(${CURL_TEST}_REENTRANT)
997 set(NEED_REENTRANT 1)
998 endif(${CURL_TEST}_REENTRANT)
999 endif(NOT ${CURL_TEST})
1000endforeach(CURL_TEST)
1001
1002if(NEED_REENTRANT)
1003 foreach(CURL_TEST
1004 HAVE_GETHOSTBYADDR_R_5
1005 HAVE_GETHOSTBYADDR_R_7
1006 HAVE_GETHOSTBYADDR_R_8
1007 HAVE_GETHOSTBYNAME_R_3
1008 HAVE_GETHOSTBYNAME_R_5
1009 HAVE_GETHOSTBYNAME_R_6)
1010 set(${CURL_TEST} 0)
1011 if(${CURL_TEST}_REENTRANT)
1012 set(${CURL_TEST} 1)
1013 endif(${CURL_TEST}_REENTRANT)
1014 endforeach(CURL_TEST)
1015endif(NEED_REENTRANT)
1016
1017if(HAVE_INET_NTOA_R_DECL_REENTRANT)
1018 set(HAVE_INET_NTOA_R_DECL 1)
1019 set(NEED_REENTRANT 1)
1020endif(HAVE_INET_NTOA_R_DECL_REENTRANT)
1021
1022# Some other minor tests
1023
1024if(NOT HAVE_IN_ADDR_T)
1025 set(in_addr_t "unsigned long")
1026endif(NOT HAVE_IN_ADDR_T)
1027
1028# Fix libz / zlib.h
1029
1030if(NOT CURL_SPECIAL_LIBZ)
1031 if(NOT HAVE_LIBZ)
1032 set(HAVE_ZLIB_H 0)
1033 endif(NOT HAVE_LIBZ)
1034
1035 if(NOT HAVE_ZLIB_H)
1036 set(HAVE_LIBZ 0)
1037 endif(NOT HAVE_ZLIB_H)
1038endif(NOT CURL_SPECIAL_LIBZ)
1039
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001040# Check for nonblocking
1041set(HAVE_DISABLED_NONBLOCKING 1)
1042if(HAVE_FIONBIO OR
1043 HAVE_IOCTLSOCKET OR
1044 HAVE_IOCTLSOCKET_CASE OR
1045 HAVE_O_NONBLOCK)
1046 set(HAVE_DISABLED_NONBLOCKING)
1047endif(HAVE_FIONBIO OR
1048 HAVE_IOCTLSOCKET OR
1049 HAVE_IOCTLSOCKET_CASE OR
1050 HAVE_O_NONBLOCK)
1051
1052if(RETSIGTYPE_TEST)
1053 set(RETSIGTYPE void)
1054else(RETSIGTYPE_TEST)
1055 set(RETSIGTYPE int)
1056endif(RETSIGTYPE_TEST)
1057
1058if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1059 include(CheckCCompilerFlag)
1060 check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1061 if(HAVE_C_FLAG_Wno_long_double)
1062 # The Mac version of GCC warns about use of long double. Disable it.
1063 get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1064 if(MPRINTF_COMPILE_FLAGS)
1065 set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1066 else(MPRINTF_COMPILE_FLAGS)
1067 set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1068 endif(MPRINTF_COMPILE_FLAGS)
1069 set_source_files_properties(mprintf.c PROPERTIES
1070 COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1071 endif(HAVE_C_FLAG_Wno_long_double)
1072endif(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1073
1074if(HAVE_SOCKLEN_T)
1075 set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001076 if(WIN32)
1077 set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h;ws2tcpip.h")
1078 elseif(HAVE_SYS_SOCKET_H)
1079 set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
1080 endif()
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001081 check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001082 set(CMAKE_EXTRA_INCLUDE_FILES)
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001083 if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001084 message(FATAL_ERROR
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001085 "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log")
1086 endif()
1087else()
1088 set(CURL_TYPEOF_CURL_SOCKLEN_T int)
1089 set(CURL_SIZEOF_CURL_SOCKLEN_T ${SIZEOF_INT})
1090endif()
1091
Elliott Hughes82be86d2017-09-20 17:00:17 -07001092# TODO test which of these headers are required
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001093if(WIN32)
1094 set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
1095else()
1096 set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
1097 set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
1098 set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
1099endif()
1100set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
1101set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
1102
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001103include(CMake/OtherTests.cmake)
1104
1105add_definitions(-DHAVE_CONFIG_H)
1106
Elliott Hughescee03382017-06-23 12:17:18 -07001107# For windows, all compilers used by cmake should support large files
1108if(WIN32)
1109 set(USE_WIN32_LARGE_FILES ON)
1110endif(WIN32)
1111
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001112if(MSVC)
1113 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
Elliott Hughes82be86d2017-09-20 17:00:17 -07001114 if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1115 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1116 else(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1117 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1118 endif(CMAKE_C_FLAGS MATCHES "/W[0-4]")
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001119endif(MSVC)
1120
Elliott Hughes1ef06ba2018-05-30 15:43:58 -07001121if(CURL_WERROR)
1122 if(MSVC_VERSION)
1123 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1124 else()
1125 # this assumes clang or gcc style options
1126 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1127 endif()
1128endif(CURL_WERROR)
1129
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001130# Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1131function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
1132 file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1133 string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1134 string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1135
Elliott Hughes82be86d2017-09-20 17:00:17 -07001136 string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001137 string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
Elliott Hughes82be86d2017-09-20 17:00:17 -07001138 string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001139
1140 string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) # Replace $() with ${}
1141 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.
1142 file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1143
1144endfunction()
1145
Alex Deymo486467e2017-12-19 19:04:07 +01001146if(WIN32 AND NOT CYGWIN)
1147 set(CURL_INSTALL_CMAKE_DIR CMake)
1148else()
1149 set(CURL_INSTALL_CMAKE_DIR lib/cmake/curl)
1150endif()
1151
1152if(USE_MANUAL)
1153 add_subdirectory(docs)
1154endif()
1155
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001156add_subdirectory(lib)
Alex Deymo486467e2017-12-19 19:04:07 +01001157
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001158if(BUILD_CURL_EXE)
1159 add_subdirectory(src)
1160endif()
Alex Deymoe3149cc2016-10-05 11:18:42 -07001161
1162include(CTest)
1163if(BUILD_TESTING)
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001164 add_subdirectory(tests)
1165endif()
1166
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001167# Helper to populate a list (_items) with a label when conditions (the remaining
1168# args) are satisfied
1169function(_add_if label)
1170 # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
1171 if(${ARGN})
1172 set(_items ${_items} "${label}" PARENT_SCOPE)
1173 endif()
1174endfunction()
1175
1176# Clear list and try to detect available features
1177set(_items)
Alex Deymod15eaac2016-06-28 14:49:26 -07001178_add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
1179_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
Elliott Hughes82be86d2017-09-20 17:00:17 -07001180_add_if("DarwinSSL" SSL_ENABLED AND USE_DARWINSSL)
1181_add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001182_add_if("IPv6" ENABLE_IPV6)
1183_add_if("unix-sockets" USE_UNIX_SOCKETS)
1184_add_if("libz" HAVE_LIBZ)
Elliott Hughescee03382017-06-23 12:17:18 -07001185_add_if("AsynchDNS" USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1186_add_if("IDN" HAVE_LIBIDN2)
1187_add_if("Largefile" (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
1188 ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001189# TODO SSP1 (WinSSL) check is missing
1190_add_if("SSPI" USE_WINDOWS_SSPI)
Alex Deymod15eaac2016-06-28 14:49:26 -07001191_add_if("GSS-API" HAVE_GSSAPI)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001192# TODO SSP1 missing for SPNEGO
1193_add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
Alex Deymod15eaac2016-06-28 14:49:26 -07001194 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001195_add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
Alex Deymod15eaac2016-06-28 14:49:26 -07001196 (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001197# NTLM support requires crypto function adaptions from various SSL libs
Elliott Hughes82be86d2017-09-20 17:00:17 -07001198# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
1199if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_DARWINSSL OR USE_MBEDTLS))
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001200 _add_if("NTLM" 1)
1201 # TODO missing option (autoconf: --enable-ntlm-wb)
1202 _add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
1203endif()
1204# TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
1205_add_if("TLS-SRP" USE_TLS_SRP)
1206# TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
1207_add_if("HTTP2" USE_NGHTTP2)
1208string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1209message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1210
1211# Clear list and try to detect available protocols
1212set(_items)
1213_add_if("HTTP" NOT CURL_DISABLE_HTTP)
1214_add_if("HTTPS" NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1215_add_if("FTP" NOT CURL_DISABLE_FTP)
1216_add_if("FTPS" NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1217_add_if("FILE" NOT CURL_DISABLE_FILE)
1218_add_if("TELNET" NOT CURL_DISABLE_TELNET)
1219_add_if("LDAP" NOT CURL_DISABLE_LDAP)
1220# CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1221# TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
1222_add_if("LDAPS" NOT CURL_DISABLE_LDAPS AND
1223 ((USE_OPENLDAP AND SSL_ENABLED) OR
1224 (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1225_add_if("DICT" NOT CURL_DISABLE_DICT)
1226_add_if("TFTP" NOT CURL_DISABLE_TFTP)
1227_add_if("GOPHER" NOT CURL_DISABLE_GOPHER)
1228_add_if("POP3" NOT CURL_DISABLE_POP3)
1229_add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1230_add_if("IMAP" NOT CURL_DISABLE_IMAP)
1231_add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1232_add_if("SMTP" NOT CURL_DISABLE_SMTP)
1233_add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1234_add_if("SCP" USE_LIBSSH2)
1235_add_if("SFTP" USE_LIBSSH2)
1236_add_if("RTSP" NOT CURL_DISABLE_RTSP)
1237_add_if("RTMP" USE_LIBRTMP)
1238list(SORT _items)
1239string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1240message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1241
1242# curl-config needs the following options to be set.
1243set(CC "${CMAKE_C_COMPILER}")
1244# TODO probably put a -D... options here?
1245set(CONFIGURE_OPTIONS "")
1246# TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
1247set(CPPFLAG_CURL_STATICLIB "")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001248set(CURLVERSION "${CURL_VERSION}")
1249set(ENABLE_SHARED "yes")
1250if(CURL_STATICLIB)
Elliott Hughescee03382017-06-23 12:17:18 -07001251 set(ENABLE_STATIC "yes")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001252else()
1253 set(ENABLE_STATIC "no")
1254endif()
1255set(exec_prefix "\${prefix}")
1256set(includedir "\${prefix}/include")
1257set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
1258set(LIBCURL_LIBS "")
1259set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001260foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
Elliott Hughes82be86d2017-09-20 17:00:17 -07001261 if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
Elliott Hughescee03382017-06-23 12:17:18 -07001262 set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
1263 else()
1264 set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
1265 endif()
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001266endforeach()
1267# "a" (Linux) or "lib" (Windows)
1268string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1269set(prefix "${CMAKE_INSTALL_PREFIX}")
1270# Set this to "yes" to append all libraries on which -lcurl is dependent
1271set(REQUIRE_LIB_DEPS "no")
1272# SUPPORT_FEATURES
1273# SUPPORT_PROTOCOLS
1274set(VERSIONNUM "${CURL_VERSION_NUM}")
1275
1276# Finally generate a "curl-config" matching this config
1277configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1278 "${CURL_BINARY_DIR}/curl-config" @ONLY)
Alex Deymod15eaac2016-06-28 14:49:26 -07001279install(FILES "${CURL_BINARY_DIR}/curl-config"
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001280 DESTINATION bin
1281 PERMISSIONS
1282 OWNER_READ OWNER_WRITE OWNER_EXECUTE
1283 GROUP_READ GROUP_EXECUTE
1284 WORLD_READ WORLD_EXECUTE)
1285
1286# Finally generate a pkg-config file matching this config
1287configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1288 "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
Alex Deymod15eaac2016-06-28 14:49:26 -07001289install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001290 DESTINATION lib/pkgconfig)
1291
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001292# This needs to be run very last so other parts of the scripts can take advantage of this.
1293if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
1294 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")
1295endif()
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001296
Elliott Hughes82be86d2017-09-20 17:00:17 -07001297# install headers
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001298install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1299 DESTINATION include
Elliott Hughes82be86d2017-09-20 17:00:17 -07001300 FILES_MATCHING PATTERN "*.h")
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001301
Alex Deymo486467e2017-12-19 19:04:07 +01001302
1303include(CMakePackageConfigHelpers)
1304write_basic_package_version_file(
1305 "${PROJECT_BINARY_DIR}/curl-config-version.cmake"
1306 VERSION ${CURL_VERSION}
1307 COMPATIBILITY SameMajorVersion
1308)
1309
1310configure_file(CMake/curl-config.cmake
1311 "${PROJECT_BINARY_DIR}/curl-config.cmake"
1312 COPYONLY
1313)
1314
1315install(
1316 FILES ${PROJECT_BINARY_DIR}/curl-config.cmake
1317 ${PROJECT_BINARY_DIR}/curl-config-version.cmake
1318 DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1319)
1320
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001321# Workaround for MSVS10 to avoid the Dialog Hell
1322# FIXME: This could be removed with future version of CMake.
1323if(MSVC_VERSION EQUAL 1600)
1324 set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1325 if(EXISTS "${CURL_SLN_FILENAME}")
1326 file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1327 endif()
1328endif()
Elliott Hughes82be86d2017-09-20 17:00:17 -07001329
1330if(NOT TARGET uninstall)
1331 configure_file(
1332 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1333 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1334 IMMEDIATE @ONLY)
1335
1336 add_custom_target(uninstall
1337 COMMAND ${CMAKE_COMMAND} -P
1338 ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
1339endif()