1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.haxx.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21###########################################################################
22# curl/libcurl CMake script
23# by Tetetest and Sukender (Benoit Neil)
24
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.
41cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
42set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
43include(Utilities)
44include(Macros)
45include(CMakeDependentOption)
46include(CheckCCompilerFlag)
47
48project(CURL C)
49
50message(WARNING "the curl cmake build system is poorly maintained. Be aware")
51
52file(READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
53string(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})
59
60include_regular_expression("^.*$")    # Sukender: Is it necessary?
61
62# Setup package meta-data
63# SET(PACKAGE "curl")
64message(STATUS "curl version=[${CURL_VERSION}]")
65# SET(PACKAGE_TARNAME "curl")
66# SET(PACKAGE_NAME "curl")
67# SET(PACKAGE_VERSION "-")
68# SET(PACKAGE_STRING "curl-")
69# SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/")
70set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
71set(OS "\"${CMAKE_SYSTEM_NAME}\"")
72
73include_directories(${CURL_SOURCE_DIR}/include)
74
75option(CURL_WERROR "Turn compiler warnings into errors" OFF)
76option(PICKY_COMPILER "Enable picky compiler options" ON)
77option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
78option(BUILD_SHARED_LIBS "Build shared libraries" ON)
79option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
80if(WIN32)
81  option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
82  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)
83endif()
84
85cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
86        ON "NOT ENABLE_ARES"
87        OFF)
88
89option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
90option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
91
92if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
93  if(PICKY_COMPILER)
94    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 -Wno-pedantic-ms-format)
95      # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
96      # test result in.
97      check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
98      if(OPT${_CCOPT})
99        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
100      endif()
101    endforeach()
102  endif()
103endif()
104
105if(ENABLE_DEBUG)
106  # DEBUGBUILD will be defined only for Debug builds
107  if(NOT CMAKE_VERSION VERSION_LESS 3.0)
108    set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
109  else()
110    set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUGBUILD)
111  endif()
112  set(ENABLE_CURLDEBUG ON)
113endif()
114
115if(ENABLE_CURLDEBUG)
116  set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
117endif()
118
119# For debug libs and exes, add "-d" postfix
120if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
121  set(CMAKE_DEBUG_POSTFIX "-d")
122endif()
123
124# initialize CURL_LIBS
125set(CURL_LIBS "")
126
127if(ENABLE_ARES)
128  set(USE_ARES 1)
129  find_package(CARES REQUIRED)
130  list(APPEND CURL_LIBS ${CARES_LIBRARY})
131  set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
132endif()
133
134include(CurlSymbolHiding)
135
136option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
137mark_as_advanced(HTTP_ONLY)
138option(CURL_DISABLE_FTP "disables FTP" OFF)
139mark_as_advanced(CURL_DISABLE_FTP)
140option(CURL_DISABLE_LDAP "disables LDAP" OFF)
141mark_as_advanced(CURL_DISABLE_LDAP)
142option(CURL_DISABLE_TELNET "disables Telnet" OFF)
143mark_as_advanced(CURL_DISABLE_TELNET)
144option(CURL_DISABLE_DICT "disables DICT" OFF)
145mark_as_advanced(CURL_DISABLE_DICT)
146option(CURL_DISABLE_FILE "disables FILE" OFF)
147mark_as_advanced(CURL_DISABLE_FILE)
148option(CURL_DISABLE_TFTP "disables TFTP" OFF)
149mark_as_advanced(CURL_DISABLE_TFTP)
150option(CURL_DISABLE_HTTP "disables HTTP" OFF)
151mark_as_advanced(CURL_DISABLE_HTTP)
152
153option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF)
154mark_as_advanced(CURL_DISABLE_LDAPS)
155
156option(CURL_DISABLE_RTSP "to disable RTSP" OFF)
157mark_as_advanced(CURL_DISABLE_RTSP)
158option(CURL_DISABLE_PROXY "to disable proxy" OFF)
159mark_as_advanced(CURL_DISABLE_PROXY)
160option(CURL_DISABLE_POP3 "to disable POP3" OFF)
161mark_as_advanced(CURL_DISABLE_POP3)
162option(CURL_DISABLE_IMAP "to disable IMAP" OFF)
163mark_as_advanced(CURL_DISABLE_IMAP)
164option(CURL_DISABLE_SMTP "to disable SMTP" OFF)
165mark_as_advanced(CURL_DISABLE_SMTP)
166option(CURL_DISABLE_GOPHER "to disable Gopher" OFF)
167mark_as_advanced(CURL_DISABLE_GOPHER)
168
169if(HTTP_ONLY)
170  set(CURL_DISABLE_FTP ON)
171  set(CURL_DISABLE_LDAP ON)
172  set(CURL_DISABLE_LDAPS ON)
173  set(CURL_DISABLE_TELNET ON)
174  set(CURL_DISABLE_DICT ON)
175  set(CURL_DISABLE_FILE ON)
176  set(CURL_DISABLE_TFTP ON)
177  set(CURL_DISABLE_RTSP ON)
178  set(CURL_DISABLE_POP3 ON)
179  set(CURL_DISABLE_IMAP ON)
180  set(CURL_DISABLE_SMTP ON)
181  set(CURL_DISABLE_GOPHER ON)
182endif()
183
184option(CURL_DISABLE_COOKIES "to disable cookies support" OFF)
185mark_as_advanced(CURL_DISABLE_COOKIES)
186
187option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
188mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
189option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
190mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
191option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
192mark_as_advanced(ENABLE_IPV6)
193if(ENABLE_IPV6 AND NOT WIN32)
194  include(CheckStructHasMember)
195  check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
196                          HAVE_SOCKADDR_IN6_SIN6_ADDR)
197  check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
198                          HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
199  if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
200    message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
201    # Force the feature off as this name is used as guard macro...
202    set(ENABLE_IPV6 OFF
203        CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
204  endif()
205endif()
206
207curl_nroff_check()
208find_package(Perl)
209
210cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
211    ON "NROFF_USEFUL;PERL_FOUND"
212    OFF)
213
214if(NOT PERL_FOUND)
215  message(STATUS "Perl not found, testing disabled.")
216  set(BUILD_TESTING OFF)
217endif()
218if(ENABLE_MANUAL)
219  set(USE_MANUAL ON)
220endif()
221
222# We need ansi c-flags, especially on HP
223set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
224set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
225
226if(CURL_STATIC_CRT)
227  set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
228  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
229endif()
230
231# Disable warnings on Borland to avoid changing 3rd party code.
232if(BORLAND)
233  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
234endif()
235
236# If we are on AIX, do the _ALL_SOURCE magic
237if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
238  set(_ALL_SOURCE 1)
239endif()
240
241# Include all the necessary files for macros
242include(CheckFunctionExists)
243include(CheckIncludeFile)
244include(CheckIncludeFiles)
245include(CheckLibraryExists)
246include(CheckSymbolExists)
247include(CheckTypeSize)
248include(CheckCSourceCompiles)
249include(CMakeDependentOption)
250
251# On windows preload settings
252if(WIN32)
253  set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
254  include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
255endif()
256
257if(ENABLE_THREADED_RESOLVER)
258  find_package(Threads REQUIRED)
259  if(WIN32)
260    set(USE_THREADS_WIN32 ON)
261  else()
262    set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
263    set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
264  endif()
265  set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
266endif()
267
268# Check for all needed libraries
269check_library_exists_concat("dl"     dlopen       HAVE_LIBDL)
270check_library_exists_concat("socket" connect      HAVE_LIBSOCKET)
271check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)
272
273# Yellowtab Zeta needs different libraries than BeOS 5.
274if(BEOS)
275  set(NOT_NEED_LIBNSL 1)
276  check_library_exists_concat("bind" gethostbyname HAVE_LIBBIND)
277  check_library_exists_concat("bnetapi" closesocket HAVE_LIBBNETAPI)
278endif()
279
280if(NOT NOT_NEED_LIBNSL)
281  check_library_exists_concat("nsl"    gethostbyname  HAVE_LIBNSL)
282endif()
283
284check_function_exists(gethostname HAVE_GETHOSTNAME)
285
286if(WIN32)
287  check_library_exists_concat("ws2_32" getch        HAVE_LIBWS2_32)
288  check_library_exists_concat("winmm"  getch        HAVE_LIBWINMM)
289  list(APPEND CURL_LIBS "advapi32")
290endif()
291
292# check SSL libraries
293# TODO support GNUTLS, NSS, POLARSSL, CYASSL
294
295if(APPLE)
296  option(CMAKE_USE_DARWINSSL "enable Apple OS native SSL/TLS" OFF)
297endif()
298if(WIN32)
299  option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
300  cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" ON
301    CMAKE_USE_WINSSL OFF)
302endif()
303option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
304
305set(openssl_default ON)
306if(WIN32 OR CMAKE_USE_DARWINSSL OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
307  set(openssl_default OFF)
308endif()
309option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default})
310
311count_true(enabled_ssl_options_count
312  CMAKE_USE_WINSSL
313  CMAKE_USE_DARWINSSL
314  CMAKE_USE_OPENSSL
315  CMAKE_USE_MBEDTLS
316)
317if(enabled_ssl_options_count GREATER "1")
318  set(CURL_WITH_MULTI_SSL ON)
319endif()
320
321if(CMAKE_USE_WINSSL)
322  set(SSL_ENABLED ON)
323  set(USE_SCHANNEL ON) # Windows native SSL/TLS support
324  set(USE_WINDOWS_SSPI ON) # CMAKE_USE_WINSSL implies CURL_WINDOWS_SSPI
325  list(APPEND CURL_LIBS "crypt32")
326endif()
327if(CURL_WINDOWS_SSPI)
328  set(USE_WINDOWS_SSPI ON)
329  set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
330endif()
331
332if(CMAKE_USE_DARWINSSL)
333  find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
334  if(NOT COREFOUNDATION_FRAMEWORK)
335      message(FATAL_ERROR "CoreFoundation framework not found")
336  endif()
337
338  find_library(SECURITY_FRAMEWORK "Security")
339  if(NOT SECURITY_FRAMEWORK)
340     message(FATAL_ERROR "Security framework not found")
341  endif()
342
343  set(SSL_ENABLED ON)
344  set(USE_DARWINSSL ON)
345  list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
346endif()
347
348if(CMAKE_USE_OPENSSL)
349  find_package(OpenSSL REQUIRED)
350  set(SSL_ENABLED ON)
351  set(USE_OPENSSL ON)
352  set(HAVE_LIBCRYPTO ON)
353  set(HAVE_LIBSSL ON)
354
355  # Depend on OpenSSL via imported targets if supported by the running
356  # version of CMake.  This allows our dependents to get our dependencies
357  # transitively.
358  if(NOT CMAKE_VERSION VERSION_LESS 3.4)
359    list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
360  else()
361    list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
362    include_directories(${OPENSSL_INCLUDE_DIR})
363  endif()
364
365  set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
366  check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
367  check_include_file("openssl/err.h"    HAVE_OPENSSL_ERR_H)
368  check_include_file("openssl/pem.h"    HAVE_OPENSSL_PEM_H)
369  check_include_file("openssl/rsa.h"    HAVE_OPENSSL_RSA_H)
370  check_include_file("openssl/ssl.h"    HAVE_OPENSSL_SSL_H)
371  check_include_file("openssl/x509.h"   HAVE_OPENSSL_X509_H)
372  check_include_file("openssl/rand.h"   HAVE_OPENSSL_RAND_H)
373  check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
374  check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
375  check_symbol_exists(RAND_egd    "${CURL_INCLUDES}" HAVE_RAND_EGD)
376endif()
377
378if(CMAKE_USE_MBEDTLS)
379  find_package(MbedTLS REQUIRED)
380  set(SSL_ENABLED ON)
381  set(USE_MBEDTLS ON)
382  list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
383  include_directories(${MBEDTLS_INCLUDE_DIRS})
384endif()
385
386option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
387if(USE_NGHTTP2)
388  find_package(NGHTTP2 REQUIRED)
389  include_directories(${NGHTTP2_INCLUDE_DIRS})
390  list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES})
391endif()
392
393if(NOT CURL_DISABLE_LDAP)
394  if(WIN32)
395    option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
396    if(USE_WIN32_LDAP)
397      check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32)
398      if(NOT HAVE_WLDAP32)
399        set(USE_WIN32_LDAP OFF)
400      endif()
401    endif()
402  endif()
403
404  option(CMAKE_USE_OPENLDAP "Use OpenLDAP code." OFF)
405  mark_as_advanced(CMAKE_USE_OPENLDAP)
406  set(CMAKE_LDAP_LIB "ldap" CACHE STRING "Name or full path to ldap library")
407  set(CMAKE_LBER_LIB "lber" CACHE STRING "Name or full path to lber library")
408
409  if(CMAKE_USE_OPENLDAP AND USE_WIN32_LDAP)
410    message(FATAL_ERROR "Cannot use USE_WIN32_LDAP and CMAKE_USE_OPENLDAP at the same time")
411  endif()
412
413  # Now that we know, we're not using windows LDAP...
414  if(USE_WIN32_LDAP)
415    check_include_file_concat("winldap.h" HAVE_WINLDAP_H)
416    check_include_file_concat("winber.h"  HAVE_WINBER_H)
417  else()
418    # Check for LDAP
419    set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
420    check_library_exists_concat(${CMAKE_LDAP_LIB} ldap_init HAVE_LIBLDAP)
421    check_library_exists_concat(${CMAKE_LBER_LIB} ber_init HAVE_LIBLBER)
422
423    set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES})
424    set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory")
425    if(CMAKE_LDAP_INCLUDE_DIR)
426      list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR})
427    endif()
428    check_include_file_concat("ldap.h"           HAVE_LDAP_H)
429    check_include_file_concat("lber.h"           HAVE_LBER_H)
430
431    if(NOT HAVE_LDAP_H)
432      message(STATUS "LDAP_H not found CURL_DISABLE_LDAP set ON")
433      set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
434      set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
435    elseif(NOT HAVE_LIBLDAP)
436      message(STATUS "LDAP library '${CMAKE_LDAP_LIB}' not found CURL_DISABLE_LDAP set ON")
437      set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
438      set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_BAK}) #LDAP includes won't be used
439    else()
440      if(CMAKE_USE_OPENLDAP)
441        set(USE_OPENLDAP ON)
442      endif()
443      if(CMAKE_LDAP_INCLUDE_DIR)
444        include_directories(${CMAKE_LDAP_INCLUDE_DIR})
445      endif()
446      set(NEED_LBER_H ON)
447      set(_HEADER_LIST)
448      if(HAVE_WINDOWS_H)
449        list(APPEND _HEADER_LIST "windows.h")
450      endif()
451      if(HAVE_SYS_TYPES_H)
452        list(APPEND _HEADER_LIST "sys/types.h")
453      endif()
454      list(APPEND _HEADER_LIST "ldap.h")
455
456      set(_SRC_STRING "")
457      foreach(_HEADER ${_HEADER_LIST})
458        set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
459      endforeach()
460
461      set(_SRC_STRING
462        "
463        ${_INCLUDE_STRING}
464        int main(int argc, char ** argv)
465        {
466          BerValue *bvp = NULL;
467          BerElement *bep = ber_init(bvp);
468          ber_free(bep, 1);
469          return 0;
470        }"
471      )
472      set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DLDAP_DEPRECATED=1")
473      list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
474      if(HAVE_LIBLBER)
475        list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
476      endif()
477      check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
478
479      if(NOT_NEED_LBER_H)
480        set(NEED_LBER_H OFF)
481      else()
482        set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
483      endif()
484    endif()
485  endif()
486endif()
487
488# No ldap, no ldaps.
489if(CURL_DISABLE_LDAP)
490  if(NOT CURL_DISABLE_LDAPS)
491    message(STATUS "LDAP needs to be enabled to support LDAPS")
492    set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
493  endif()
494endif()
495
496if(NOT CURL_DISABLE_LDAPS)
497  check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
498  check_include_file_concat("ldapssl.h"  HAVE_LDAPSSL_H)
499endif()
500
501# Check for idn
502check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2)
503
504# Check for symbol dlopen (same as HAVE_LIBDL)
505check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN)
506
507option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
508set(HAVE_LIBZ OFF)
509set(HAVE_ZLIB_H OFF)
510set(USE_ZLIB OFF)
511if(CURL_ZLIB)
512  find_package(ZLIB QUIET)
513  if(ZLIB_FOUND)
514    set(HAVE_ZLIB_H ON)
515    set(HAVE_LIBZ ON)
516    set(USE_ZLIB ON)
517
518    # Depend on ZLIB via imported targets if supported by the running
519    # version of CMake.  This allows our dependents to get our dependencies
520    # transitively.
521    if(NOT CMAKE_VERSION VERSION_LESS 3.4)
522      list(APPEND CURL_LIBS ZLIB::ZLIB)
523    else()
524      list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
525      include_directories(${ZLIB_INCLUDE_DIRS})
526    endif()
527    list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
528  endif()
529endif()
530
531option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
532set(HAVE_BROTLI OFF)
533if(CURL_BROTLI)
534  find_package(BROTLI QUIET)
535  if(BROTLI_FOUND)
536    set(HAVE_BROTLI ON)
537    list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
538    include_directories(${BROTLI_INCLUDE_DIRS})
539    list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
540  endif()
541endif()
542
543#libSSH2
544option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
545mark_as_advanced(CMAKE_USE_LIBSSH2)
546set(USE_LIBSSH2 OFF)
547set(HAVE_LIBSSH2 OFF)
548set(HAVE_LIBSSH2_H OFF)
549
550if(CMAKE_USE_LIBSSH2)
551  find_package(LibSSH2)
552  if(LIBSSH2_FOUND)
553    list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY})
554    set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY})
555    list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}")
556    include_directories("${LIBSSH2_INCLUDE_DIR}")
557    set(HAVE_LIBSSH2 ON)
558    set(USE_LIBSSH2 ON)
559
560    # find_package has already found the headers
561    set(HAVE_LIBSSH2_H ON)
562    set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h")
563    set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H")
564
565    # now check for specific libssh2 symbols as they were added in different versions
566    set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h")
567    check_function_exists(libssh2_version           HAVE_LIBSSH2_VERSION)
568    check_function_exists(libssh2_init              HAVE_LIBSSH2_INIT)
569    check_function_exists(libssh2_exit              HAVE_LIBSSH2_EXIT)
570    check_function_exists(libssh2_scp_send64        HAVE_LIBSSH2_SCP_SEND64)
571    check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
572    set(CMAKE_EXTRA_INCLUDE_FILES "")
573  endif()
574endif()
575
576option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
577mark_as_advanced(CMAKE_USE_GSSAPI)
578
579if(CMAKE_USE_GSSAPI)
580  find_package(GSS)
581
582  set(HAVE_GSSAPI ${GSS_FOUND})
583  if(GSS_FOUND)
584
585    message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
586
587    list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
588    check_include_file_concat("gssapi/gssapi.h"  HAVE_GSSAPI_GSSAPI_H)
589    check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
590    check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
591
592    if(GSS_FLAVOUR STREQUAL "Heimdal")
593      set(HAVE_GSSHEIMDAL ON)
594    else() # MIT
595      set(HAVE_GSSMIT ON)
596      set(_INCLUDE_LIST "")
597      if(HAVE_GSSAPI_GSSAPI_H)
598        list(APPEND _INCLUDE_LIST "gssapi/gssapi.h")
599      endif()
600      if(HAVE_GSSAPI_GSSAPI_GENERIC_H)
601        list(APPEND _INCLUDE_LIST "gssapi/gssapi_generic.h")
602      endif()
603      if(HAVE_GSSAPI_GSSAPI_KRB5_H)
604        list(APPEND _INCLUDE_LIST "gssapi/gssapi_krb5.h")
605      endif()
606
607      string(REPLACE ";" " " _COMPILER_FLAGS_STR "${GSS_COMPILER_FLAGS}")
608      string(REPLACE ";" " " _LINKER_FLAGS_STR "${GSS_LINKER_FLAGS}")
609
610      foreach(_dir ${GSS_LINK_DIRECTORIES})
611        set(_LINKER_FLAGS_STR "${_LINKER_FLAGS_STR} -L\"${_dir}\"")
612      endforeach()
613
614      set(CMAKE_REQUIRED_FLAGS "${_COMPILER_FLAGS_STR} ${_LINKER_FLAGS_STR}")
615      set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES})
616      check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" ${_INCLUDE_LIST} HAVE_GSS_C_NT_HOSTBASED_SERVICE)
617      if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
618        set(HAVE_OLD_GSSMIT ON)
619      endif()
620
621    endif()
622
623    include_directories(${GSS_INCLUDE_DIR})
624    link_directories(${GSS_LINK_DIRECTORIES})
625    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
626    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
627    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
628    list(APPEND CURL_LIBS ${GSS_LIBRARIES})
629
630  else()
631    message(WARNING "GSSAPI support has been requested but no supporting libraries found. Skipping.")
632  endif()
633endif()
634
635option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
636if(ENABLE_UNIX_SOCKETS)
637  include(CheckStructHasMember)
638  check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
639else()
640  unset(USE_UNIX_SOCKETS CACHE)
641endif()
642
643#
644# CA handling
645#
646set(CURL_CA_BUNDLE "auto" CACHE STRING
647    "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
648set(CURL_CA_FALLBACK OFF CACHE BOOL
649    "Set ON to use built-in CA store of TLS backend. Defaults to OFF")
650set(CURL_CA_PATH "auto" CACHE STRING
651    "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
652
653if("${CURL_CA_BUNDLE}" STREQUAL "")
654  message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
655elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
656  unset(CURL_CA_BUNDLE CACHE)
657elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
658  unset(CURL_CA_BUNDLE CACHE)
659  set(CURL_CA_BUNDLE_AUTODETECT TRUE)
660else()
661  set(CURL_CA_BUNDLE_SET TRUE)
662endif()
663
664if("${CURL_CA_PATH}" STREQUAL "")
665  message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
666elseif("${CURL_CA_PATH}" STREQUAL "none")
667  unset(CURL_CA_PATH CACHE)
668elseif("${CURL_CA_PATH}" STREQUAL "auto")
669  unset(CURL_CA_PATH CACHE)
670  set(CURL_CA_PATH_AUTODETECT TRUE)
671else()
672  set(CURL_CA_PATH_SET TRUE)
673endif()
674
675if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
676  # Skip autodetection of unset CA path because CA bundle is set explicitly
677elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
678  # Skip autodetection of unset CA bundle because CA path is set explicitly
679elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
680  # first try autodetecting a CA bundle, then a CA path
681
682  if(CURL_CA_BUNDLE_AUTODETECT)
683    set(SEARCH_CA_BUNDLE_PATHS
684        /etc/ssl/certs/ca-certificates.crt
685        /etc/pki/tls/certs/ca-bundle.crt
686        /usr/share/ssl/certs/ca-bundle.crt
687        /usr/local/share/certs/ca-root-nss.crt
688        /etc/ssl/cert.pem)
689
690    foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
691      if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
692        message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
693        set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
694        set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
695        break()
696      endif()
697    endforeach()
698  endif()
699
700  if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
701    if(EXISTS "/etc/ssl/certs")
702      set(CURL_CA_PATH "/etc/ssl/certs")
703      set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
704    endif()
705  endif()
706endif()
707
708if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
709  message(FATAL_ERROR
710          "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
711          "Set CURL_CA_PATH=none or enable one of those TLS backends.")
712endif()
713
714# Check for header files
715if(NOT UNIX)
716  check_include_file_concat("windows.h"      HAVE_WINDOWS_H)
717  check_include_file_concat("winsock.h"      HAVE_WINSOCK_H)
718  check_include_file_concat("ws2tcpip.h"     HAVE_WS2TCPIP_H)
719  check_include_file_concat("winsock2.h"     HAVE_WINSOCK2_H)
720  if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL)
721    set(CURL_LIBS ${CURL_LIBS} "crypt32")
722  endif()
723endif()
724
725check_include_file_concat("stdio.h"          HAVE_STDIO_H)
726check_include_file_concat("inttypes.h"       HAVE_INTTYPES_H)
727check_include_file_concat("sys/filio.h"      HAVE_SYS_FILIO_H)
728check_include_file_concat("sys/ioctl.h"      HAVE_SYS_IOCTL_H)
729check_include_file_concat("sys/param.h"      HAVE_SYS_PARAM_H)
730check_include_file_concat("sys/poll.h"       HAVE_SYS_POLL_H)
731check_include_file_concat("sys/resource.h"   HAVE_SYS_RESOURCE_H)
732check_include_file_concat("sys/select.h"     HAVE_SYS_SELECT_H)
733check_include_file_concat("sys/socket.h"     HAVE_SYS_SOCKET_H)
734check_include_file_concat("sys/sockio.h"     HAVE_SYS_SOCKIO_H)
735check_include_file_concat("sys/stat.h"       HAVE_SYS_STAT_H)
736check_include_file_concat("sys/time.h"       HAVE_SYS_TIME_H)
737check_include_file_concat("sys/types.h"      HAVE_SYS_TYPES_H)
738check_include_file_concat("sys/uio.h"        HAVE_SYS_UIO_H)
739check_include_file_concat("sys/un.h"         HAVE_SYS_UN_H)
740check_include_file_concat("sys/utime.h"      HAVE_SYS_UTIME_H)
741check_include_file_concat("sys/xattr.h"      HAVE_SYS_XATTR_H)
742check_include_file_concat("alloca.h"         HAVE_ALLOCA_H)
743check_include_file_concat("arpa/inet.h"      HAVE_ARPA_INET_H)
744check_include_file_concat("arpa/tftp.h"      HAVE_ARPA_TFTP_H)
745check_include_file_concat("assert.h"         HAVE_ASSERT_H)
746check_include_file_concat("crypto.h"         HAVE_CRYPTO_H)
747check_include_file_concat("des.h"            HAVE_DES_H)
748check_include_file_concat("err.h"            HAVE_ERR_H)
749check_include_file_concat("errno.h"          HAVE_ERRNO_H)
750check_include_file_concat("fcntl.h"          HAVE_FCNTL_H)
751check_include_file_concat("idn2.h"           HAVE_IDN2_H)
752check_include_file_concat("ifaddrs.h"        HAVE_IFADDRS_H)
753check_include_file_concat("io.h"             HAVE_IO_H)
754check_include_file_concat("krb.h"            HAVE_KRB_H)
755check_include_file_concat("libgen.h"         HAVE_LIBGEN_H)
756check_include_file_concat("locale.h"         HAVE_LOCALE_H)
757check_include_file_concat("net/if.h"         HAVE_NET_IF_H)
758check_include_file_concat("netdb.h"          HAVE_NETDB_H)
759check_include_file_concat("netinet/in.h"     HAVE_NETINET_IN_H)
760check_include_file_concat("netinet/tcp.h"    HAVE_NETINET_TCP_H)
761
762check_include_file_concat("pem.h"            HAVE_PEM_H)
763check_include_file_concat("poll.h"           HAVE_POLL_H)
764check_include_file_concat("pwd.h"            HAVE_PWD_H)
765check_include_file_concat("rsa.h"            HAVE_RSA_H)
766check_include_file_concat("setjmp.h"         HAVE_SETJMP_H)
767check_include_file_concat("sgtty.h"          HAVE_SGTTY_H)
768check_include_file_concat("signal.h"         HAVE_SIGNAL_H)
769check_include_file_concat("ssl.h"            HAVE_SSL_H)
770check_include_file_concat("stdbool.h"        HAVE_STDBOOL_H)
771check_include_file_concat("stdint.h"         HAVE_STDINT_H)
772check_include_file_concat("stdio.h"          HAVE_STDIO_H)
773check_include_file_concat("stdlib.h"         HAVE_STDLIB_H)
774check_include_file_concat("string.h"         HAVE_STRING_H)
775check_include_file_concat("strings.h"        HAVE_STRINGS_H)
776check_include_file_concat("stropts.h"        HAVE_STROPTS_H)
777check_include_file_concat("termio.h"         HAVE_TERMIO_H)
778check_include_file_concat("termios.h"        HAVE_TERMIOS_H)
779check_include_file_concat("time.h"           HAVE_TIME_H)
780check_include_file_concat("unistd.h"         HAVE_UNISTD_H)
781check_include_file_concat("utime.h"          HAVE_UTIME_H)
782check_include_file_concat("x509.h"           HAVE_X509_H)
783
784check_include_file_concat("process.h"        HAVE_PROCESS_H)
785check_include_file_concat("stddef.h"         HAVE_STDDEF_H)
786check_include_file_concat("dlfcn.h"          HAVE_DLFCN_H)
787check_include_file_concat("malloc.h"         HAVE_MALLOC_H)
788check_include_file_concat("memory.h"         HAVE_MEMORY_H)
789check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H)
790check_include_file_concat("stdint.h"        HAVE_STDINT_H)
791check_include_file_concat("sockio.h"        HAVE_SOCKIO_H)
792check_include_file_concat("sys/utsname.h"   HAVE_SYS_UTSNAME_H)
793
794check_type_size(size_t  SIZEOF_SIZE_T)
795check_type_size(ssize_t  SIZEOF_SSIZE_T)
796check_type_size("long long"  SIZEOF_LONG_LONG)
797check_type_size("long"  SIZEOF_LONG)
798check_type_size("short"  SIZEOF_SHORT)
799check_type_size("int"  SIZEOF_INT)
800check_type_size("__int64"  SIZEOF___INT64)
801check_type_size("long double"  SIZEOF_LONG_DOUBLE)
802check_type_size("time_t"  SIZEOF_TIME_T)
803if(NOT HAVE_SIZEOF_SSIZE_T)
804  if(SIZEOF_LONG EQUAL SIZEOF_SIZE_T)
805    set(ssize_t long)
806  endif()
807  if(NOT ssize_t AND SIZEOF___INT64 EQUAL SIZEOF_SIZE_T)
808    set(ssize_t __int64)
809  endif()
810endif()
811# off_t is sized later, after the HAVE_FILE_OFFSET_BITS test
812
813if(HAVE_SIZEOF_LONG_LONG)
814  set(HAVE_LONGLONG 1)
815  set(HAVE_LL 1)
816endif()
817
818find_file(RANDOM_FILE urandom /dev)
819mark_as_advanced(RANDOM_FILE)
820
821# Check for some functions that are used
822if(HAVE_LIBWS2_32)
823  set(CMAKE_REQUIRED_LIBRARIES ws2_32)
824elseif(HAVE_LIBSOCKET)
825  set(CMAKE_REQUIRED_LIBRARIES socket)
826endif()
827
828check_symbol_exists(basename      "${CURL_INCLUDES}" HAVE_BASENAME)
829check_symbol_exists(socket        "${CURL_INCLUDES}" HAVE_SOCKET)
830check_symbol_exists(select        "${CURL_INCLUDES}" HAVE_SELECT)
831check_symbol_exists(poll          "${CURL_INCLUDES}" HAVE_POLL)
832check_symbol_exists(strdup        "${CURL_INCLUDES}" HAVE_STRDUP)
833check_symbol_exists(strstr        "${CURL_INCLUDES}" HAVE_STRSTR)
834check_symbol_exists(strtok_r      "${CURL_INCLUDES}" HAVE_STRTOK_R)
835check_symbol_exists(strftime      "${CURL_INCLUDES}" HAVE_STRFTIME)
836check_symbol_exists(uname         "${CURL_INCLUDES}" HAVE_UNAME)
837check_symbol_exists(strcasecmp    "${CURL_INCLUDES}" HAVE_STRCASECMP)
838check_symbol_exists(stricmp       "${CURL_INCLUDES}" HAVE_STRICMP)
839check_symbol_exists(strcmpi       "${CURL_INCLUDES}" HAVE_STRCMPI)
840check_symbol_exists(strncmpi      "${CURL_INCLUDES}" HAVE_STRNCMPI)
841check_symbol_exists(alarm         "${CURL_INCLUDES}" HAVE_ALARM)
842if(NOT HAVE_STRNCMPI)
843  set(HAVE_STRCMPI)
844endif()
845check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
846check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
847check_symbol_exists(gettimeofday  "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
848check_symbol_exists(inet_addr     "${CURL_INCLUDES}" HAVE_INET_ADDR)
849check_symbol_exists(inet_ntoa     "${CURL_INCLUDES}" HAVE_INET_NTOA)
850check_symbol_exists(inet_ntoa_r   "${CURL_INCLUDES}" HAVE_INET_NTOA_R)
851check_symbol_exists(tcsetattr     "${CURL_INCLUDES}" HAVE_TCSETATTR)
852check_symbol_exists(tcgetattr     "${CURL_INCLUDES}" HAVE_TCGETATTR)
853check_symbol_exists(perror        "${CURL_INCLUDES}" HAVE_PERROR)
854check_symbol_exists(closesocket   "${CURL_INCLUDES}" HAVE_CLOSESOCKET)
855check_symbol_exists(setvbuf       "${CURL_INCLUDES}" HAVE_SETVBUF)
856check_symbol_exists(sigsetjmp     "${CURL_INCLUDES}" HAVE_SIGSETJMP)
857check_symbol_exists(getpass_r     "${CURL_INCLUDES}" HAVE_GETPASS_R)
858check_symbol_exists(strlcat       "${CURL_INCLUDES}" HAVE_STRLCAT)
859check_symbol_exists(getpwuid      "${CURL_INCLUDES}" HAVE_GETPWUID)
860check_symbol_exists(getpwuid_r    "${CURL_INCLUDES}" HAVE_GETPWUID_R)
861check_symbol_exists(geteuid       "${CURL_INCLUDES}" HAVE_GETEUID)
862check_symbol_exists(utime         "${CURL_INCLUDES}" HAVE_UTIME)
863check_symbol_exists(gmtime_r      "${CURL_INCLUDES}" HAVE_GMTIME_R)
864check_symbol_exists(localtime_r   "${CURL_INCLUDES}" HAVE_LOCALTIME_R)
865
866check_symbol_exists(gethostbyname   "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME)
867check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R)
868
869check_symbol_exists(signal        "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC)
870check_symbol_exists(SIGALRM       "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO)
871if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO)
872  set(HAVE_SIGNAL 1)
873endif()
874check_symbol_exists(uname          "${CURL_INCLUDES}" HAVE_UNAME)
875check_symbol_exists(strtoll        "${CURL_INCLUDES}" HAVE_STRTOLL)
876check_symbol_exists(_strtoi64      "${CURL_INCLUDES}" HAVE__STRTOI64)
877check_symbol_exists(strerror_r     "${CURL_INCLUDES}" HAVE_STRERROR_R)
878check_symbol_exists(siginterrupt   "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
879check_symbol_exists(perror         "${CURL_INCLUDES}" HAVE_PERROR)
880check_symbol_exists(fork           "${CURL_INCLUDES}" HAVE_FORK)
881check_symbol_exists(getaddrinfo    "${CURL_INCLUDES}" HAVE_GETADDRINFO)
882check_symbol_exists(freeaddrinfo   "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
883check_symbol_exists(freeifaddrs    "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
884check_symbol_exists(pipe           "${CURL_INCLUDES}" HAVE_PIPE)
885check_symbol_exists(ftruncate      "${CURL_INCLUDES}" HAVE_FTRUNCATE)
886check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME)
887check_symbol_exists(getrlimit      "${CURL_INCLUDES}" HAVE_GETRLIMIT)
888check_symbol_exists(setlocale      "${CURL_INCLUDES}" HAVE_SETLOCALE)
889check_symbol_exists(setmode        "${CURL_INCLUDES}" HAVE_SETMODE)
890check_symbol_exists(setrlimit      "${CURL_INCLUDES}" HAVE_SETRLIMIT)
891check_symbol_exists(fcntl          "${CURL_INCLUDES}" HAVE_FCNTL)
892check_symbol_exists(ioctl          "${CURL_INCLUDES}" HAVE_IOCTL)
893check_symbol_exists(setsockopt     "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
894check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
895
896# symbol exists in win32, but function does not.
897if(WIN32)
898  if(ENABLE_INET_PTON)
899    check_function_exists(inet_pton HAVE_INET_PTON)
900    # _WIN32_WINNT_VISTA (0x0600)
901    add_definitions(-D_WIN32_WINNT=0x0600)
902  else()
903    # _WIN32_WINNT_WINXP (0x0501)
904    add_definitions(-D_WIN32_WINNT=0x0501)
905  endif()
906else()
907  check_function_exists(inet_pton HAVE_INET_PTON)
908endif()
909
910check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
911if(HAVE_FSETXATTR)
912  foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
913    curl_internal_test(${CURL_TEST})
914  endforeach()
915endif()
916
917# sigaction and sigsetjmp are special. Use special mechanism for
918# detecting those, but only if previous attempt failed.
919if(HAVE_SIGNAL_H)
920  check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
921endif()
922
923if(NOT HAVE_SIGSETJMP)
924  if(HAVE_SETJMP_H)
925    check_symbol_exists(sigsetjmp "setjmp.h" HAVE_MACRO_SIGSETJMP)
926    if(HAVE_MACRO_SIGSETJMP)
927      set(HAVE_SIGSETJMP 1)
928    endif()
929  endif()
930endif()
931
932# If there is no stricmp(), do not allow LDAP to parse URLs
933if(NOT HAVE_STRICMP)
934  set(HAVE_LDAP_URL_PARSE 1)
935endif()
936
937# Do curl specific tests
938foreach(CURL_TEST
939    HAVE_FCNTL_O_NONBLOCK
940    HAVE_IOCTLSOCKET
941    HAVE_IOCTLSOCKET_CAMEL
942    HAVE_IOCTLSOCKET_CAMEL_FIONBIO
943    HAVE_IOCTLSOCKET_FIONBIO
944    HAVE_IOCTL_FIONBIO
945    HAVE_IOCTL_SIOCGIFADDR
946    HAVE_SETSOCKOPT_SO_NONBLOCK
947    HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
948    TIME_WITH_SYS_TIME
949    HAVE_O_NONBLOCK
950    HAVE_GETHOSTBYADDR_R_5
951    HAVE_GETHOSTBYADDR_R_7
952    HAVE_GETHOSTBYADDR_R_8
953    HAVE_GETHOSTBYADDR_R_5_REENTRANT
954    HAVE_GETHOSTBYADDR_R_7_REENTRANT
955    HAVE_GETHOSTBYADDR_R_8_REENTRANT
956    HAVE_GETHOSTBYNAME_R_3
957    HAVE_GETHOSTBYNAME_R_5
958    HAVE_GETHOSTBYNAME_R_6
959    HAVE_GETHOSTBYNAME_R_3_REENTRANT
960    HAVE_GETHOSTBYNAME_R_5_REENTRANT
961    HAVE_GETHOSTBYNAME_R_6_REENTRANT
962    HAVE_IN_ADDR_T
963    HAVE_BOOL_T
964    STDC_HEADERS
965    RETSIGTYPE_TEST
966    HAVE_INET_NTOA_R_DECL
967    HAVE_INET_NTOA_R_DECL_REENTRANT
968    HAVE_GETADDRINFO
969    HAVE_FILE_OFFSET_BITS
970    HAVE_VARIADIC_MACROS_C99
971    HAVE_VARIADIC_MACROS_GCC
972    )
973  curl_internal_test(${CURL_TEST})
974endforeach()
975
976if(HAVE_FILE_OFFSET_BITS)
977  set(_FILE_OFFSET_BITS 64)
978  set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
979endif()
980check_type_size("off_t"  SIZEOF_OFF_T)
981
982# include this header to get the type
983set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
984set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
985check_type_size("curl_off_t"  SIZEOF_CURL_OFF_T)
986set(CMAKE_EXTRA_INCLUDE_FILES "")
987
988set(CMAKE_REQUIRED_FLAGS)
989
990foreach(CURL_TEST
991    HAVE_GLIBC_STRERROR_R
992    HAVE_POSIX_STRERROR_R
993    )
994  curl_internal_test(${CURL_TEST})
995endforeach()
996
997# Check for reentrant
998foreach(CURL_TEST
999    HAVE_GETHOSTBYADDR_R_5
1000    HAVE_GETHOSTBYADDR_R_7
1001    HAVE_GETHOSTBYADDR_R_8
1002    HAVE_GETHOSTBYNAME_R_3
1003    HAVE_GETHOSTBYNAME_R_5
1004    HAVE_GETHOSTBYNAME_R_6
1005    HAVE_INET_NTOA_R_DECL_REENTRANT)
1006  if(NOT ${CURL_TEST})
1007    if(${CURL_TEST}_REENTRANT)
1008      set(NEED_REENTRANT 1)
1009    endif()
1010  endif()
1011endforeach()
1012
1013if(NEED_REENTRANT)
1014  foreach(CURL_TEST
1015      HAVE_GETHOSTBYADDR_R_5
1016      HAVE_GETHOSTBYADDR_R_7
1017      HAVE_GETHOSTBYADDR_R_8
1018      HAVE_GETHOSTBYNAME_R_3
1019      HAVE_GETHOSTBYNAME_R_5
1020      HAVE_GETHOSTBYNAME_R_6)
1021    set(${CURL_TEST} 0)
1022    if(${CURL_TEST}_REENTRANT)
1023      set(${CURL_TEST} 1)
1024    endif()
1025  endforeach()
1026endif()
1027
1028if(HAVE_INET_NTOA_R_DECL_REENTRANT)
1029  set(HAVE_INET_NTOA_R_DECL 1)
1030  set(NEED_REENTRANT 1)
1031endif()
1032
1033# Check clock_gettime(CLOCK_MONOTONIC, x) support
1034curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
1035
1036# Check compiler support of __builtin_available()
1037curl_internal_test(HAVE_BUILTIN_AVAILABLE)
1038
1039# Some other minor tests
1040
1041if(NOT HAVE_IN_ADDR_T)
1042  set(in_addr_t "unsigned long")
1043endif()
1044
1045# Fix libz / zlib.h
1046
1047if(NOT CURL_SPECIAL_LIBZ)
1048  if(NOT HAVE_LIBZ)
1049    set(HAVE_ZLIB_H 0)
1050  endif()
1051
1052  if(NOT HAVE_ZLIB_H)
1053    set(HAVE_LIBZ 0)
1054  endif()
1055endif()
1056
1057# Check for nonblocking
1058set(HAVE_DISABLED_NONBLOCKING 1)
1059if(HAVE_FIONBIO OR
1060    HAVE_IOCTLSOCKET OR
1061    HAVE_IOCTLSOCKET_CASE OR
1062    HAVE_O_NONBLOCK)
1063  set(HAVE_DISABLED_NONBLOCKING)
1064endif()
1065
1066if(RETSIGTYPE_TEST)
1067  set(RETSIGTYPE void)
1068else()
1069  set(RETSIGTYPE int)
1070endif()
1071
1072if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
1073  include(CheckCCompilerFlag)
1074  check_c_compiler_flag(-Wno-long-double HAVE_C_FLAG_Wno_long_double)
1075  if(HAVE_C_FLAG_Wno_long_double)
1076    # The Mac version of GCC warns about use of long double.  Disable it.
1077    get_source_file_property(MPRINTF_COMPILE_FLAGS mprintf.c COMPILE_FLAGS)
1078    if(MPRINTF_COMPILE_FLAGS)
1079      set(MPRINTF_COMPILE_FLAGS "${MPRINTF_COMPILE_FLAGS} -Wno-long-double")
1080    else()
1081      set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
1082    endif()
1083    set_source_files_properties(mprintf.c PROPERTIES
1084      COMPILE_FLAGS ${MPRINTF_COMPILE_FLAGS})
1085  endif()
1086endif()
1087
1088# TODO test which of these headers are required
1089if(WIN32)
1090  set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
1091else()
1092  set(CURL_PULL_SYS_TYPES_H ${HAVE_SYS_TYPES_H})
1093  set(CURL_PULL_SYS_SOCKET_H ${HAVE_SYS_SOCKET_H})
1094  set(CURL_PULL_SYS_POLL_H ${HAVE_SYS_POLL_H})
1095endif()
1096set(CURL_PULL_STDINT_H ${HAVE_STDINT_H})
1097set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H})
1098
1099include(CMake/OtherTests.cmake)
1100
1101add_definitions(-DHAVE_CONFIG_H)
1102
1103# For Windows, all compilers used by CMake should support large files
1104if(WIN32)
1105  set(USE_WIN32_LARGE_FILES ON)
1106
1107  # Use the manifest embedded in the Windows Resource
1108  set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1109endif()
1110
1111if(MSVC)
1112  # Disable default manifest added by CMake
1113  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1114
1115  add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1116  if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1117    string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
1118  else()
1119    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
1120  endif()
1121endif()
1122
1123if(CURL_WERROR)
1124  if(MSVC_VERSION)
1125    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
1126  else()
1127    # this assumes clang or gcc style options
1128    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
1129  endif()
1130endif()
1131
1132# Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
1133function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
1134  file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
1135  string(REPLACE "$(top_srcdir)"   "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1136  string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1137
1138  string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1139  string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1140  string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
1141
1142  string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace $() with ${}
1143  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.
1144  file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
1145
1146endfunction()
1147
1148include(GNUInstallDirs)
1149
1150set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
1151set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
1152set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
1153set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
1154set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
1155
1156if(USE_MANUAL)
1157  add_subdirectory(docs)
1158endif()
1159
1160add_subdirectory(lib)
1161
1162if(BUILD_CURL_EXE)
1163  add_subdirectory(src)
1164endif()
1165
1166include(CTest)
1167if(BUILD_TESTING)
1168  add_subdirectory(tests)
1169endif()
1170
1171# Helper to populate a list (_items) with a label when conditions (the remaining
1172# args) are satisfied
1173function(_add_if label)
1174  # TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
1175  if(${ARGN})
1176    set(_items ${_items} "${label}" PARENT_SCOPE)
1177  endif()
1178endfunction()
1179
1180# Clear list and try to detect available features
1181set(_items)
1182_add_if("WinSSL"        SSL_ENABLED AND USE_WINDOWS_SSPI)
1183_add_if("OpenSSL"       SSL_ENABLED AND USE_OPENSSL)
1184_add_if("DarwinSSL"     SSL_ENABLED AND USE_DARWINSSL)
1185_add_if("mbedTLS"       SSL_ENABLED AND USE_MBEDTLS)
1186_add_if("IPv6"          ENABLE_IPV6)
1187_add_if("unix-sockets"  USE_UNIX_SOCKETS)
1188_add_if("libz"          HAVE_LIBZ)
1189_add_if("AsynchDNS"     USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
1190_add_if("IDN"           HAVE_LIBIDN2)
1191_add_if("Largefile"     (CURL_SIZEOF_CURL_OFF_T GREATER 4) AND
1192                        ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
1193# TODO SSP1 (WinSSL) check is missing
1194_add_if("SSPI"          USE_WINDOWS_SSPI)
1195_add_if("GSS-API"       HAVE_GSSAPI)
1196# TODO SSP1 missing for SPNEGO
1197_add_if("SPNEGO"        NOT CURL_DISABLE_CRYPTO_AUTH AND
1198                        (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1199_add_if("Kerberos"      NOT CURL_DISABLE_CRYPTO_AUTH AND
1200                        (HAVE_GSSAPI OR USE_WINDOWS_SSPI))
1201# NTLM support requires crypto function adaptions from various SSL libs
1202# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
1203if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_DARWINSSL OR USE_MBEDTLS))
1204  _add_if("NTLM"        1)
1205  # TODO missing option (autoconf: --enable-ntlm-wb)
1206  _add_if("NTLM_WB"     NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
1207endif()
1208# TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
1209_add_if("TLS-SRP"       USE_TLS_SRP)
1210# TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
1211_add_if("HTTP2"         USE_NGHTTP2)
1212string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
1213message(STATUS "Enabled features: ${SUPPORT_FEATURES}")
1214
1215# Clear list and try to detect available protocols
1216set(_items)
1217_add_if("HTTP"          NOT CURL_DISABLE_HTTP)
1218_add_if("HTTPS"         NOT CURL_DISABLE_HTTP AND SSL_ENABLED)
1219_add_if("FTP"           NOT CURL_DISABLE_FTP)
1220_add_if("FTPS"          NOT CURL_DISABLE_FTP AND SSL_ENABLED)
1221_add_if("FILE"          NOT CURL_DISABLE_FILE)
1222_add_if("TELNET"        NOT CURL_DISABLE_TELNET)
1223_add_if("LDAP"          NOT CURL_DISABLE_LDAP)
1224# CURL_DISABLE_LDAP implies CURL_DISABLE_LDAPS
1225# TODO check HAVE_LDAP_SSL (in autoconf this is enabled with --enable-ldaps)
1226_add_if("LDAPS"         NOT CURL_DISABLE_LDAPS AND
1227                        ((USE_OPENLDAP AND SSL_ENABLED) OR
1228                        (NOT USE_OPENLDAP AND HAVE_LDAP_SSL)))
1229_add_if("DICT"          NOT CURL_DISABLE_DICT)
1230_add_if("TFTP"          NOT CURL_DISABLE_TFTP)
1231_add_if("GOPHER"        NOT CURL_DISABLE_GOPHER)
1232_add_if("POP3"          NOT CURL_DISABLE_POP3)
1233_add_if("POP3S"         NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
1234_add_if("IMAP"          NOT CURL_DISABLE_IMAP)
1235_add_if("IMAPS"         NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
1236_add_if("SMTP"          NOT CURL_DISABLE_SMTP)
1237_add_if("SMTPS"         NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
1238_add_if("SCP"           USE_LIBSSH2)
1239_add_if("SFTP"          USE_LIBSSH2)
1240_add_if("RTSP"          NOT CURL_DISABLE_RTSP)
1241_add_if("RTMP"          USE_LIBRTMP)
1242list(SORT _items)
1243string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
1244message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
1245
1246# curl-config needs the following options to be set.
1247set(CC                      "${CMAKE_C_COMPILER}")
1248# TODO probably put a -D... options here?
1249set(CONFIGURE_OPTIONS       "")
1250# TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
1251set(CPPFLAG_CURL_STATICLIB  "")
1252set(CURLVERSION             "${CURL_VERSION}")
1253if(BUILD_SHARED_LIBS)
1254  set(ENABLE_SHARED         "yes")
1255  set(ENABLE_STATIC         "no")
1256else()
1257  set(ENABLE_SHARED         "no")
1258  set(ENABLE_STATIC         "yes")
1259endif()
1260set(exec_prefix             "\${prefix}")
1261set(includedir              "\${prefix}/include")
1262set(LDFLAGS                 "${CMAKE_SHARED_LINKER_FLAGS}")
1263set(LIBCURL_LIBS            "")
1264set(libdir                  "${CMAKE_INSTALL_PREFIX}/lib")
1265foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
1266  if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
1267    set(LIBCURL_LIBS          "${LIBCURL_LIBS} ${_lib}")
1268  else()
1269    set(LIBCURL_LIBS          "${LIBCURL_LIBS} -l${_lib}")
1270  endif()
1271endforeach()
1272# "a" (Linux) or "lib" (Windows)
1273string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
1274set(prefix                  "${CMAKE_INSTALL_PREFIX}")
1275# Set this to "yes" to append all libraries on which -lcurl is dependent
1276set(REQUIRE_LIB_DEPS        "no")
1277# SUPPORT_FEATURES
1278# SUPPORT_PROTOCOLS
1279set(VERSIONNUM              "${CURL_VERSION_NUM}")
1280
1281# Finally generate a "curl-config" matching this config
1282# Use:
1283# * ENABLE_SHARED
1284# * ENABLE_STATIC
1285configure_file("${CURL_SOURCE_DIR}/curl-config.in"
1286               "${CURL_BINARY_DIR}/curl-config" @ONLY)
1287install(FILES "${CURL_BINARY_DIR}/curl-config"
1288        DESTINATION ${CMAKE_INSTALL_BINDIR}
1289        PERMISSIONS
1290          OWNER_READ OWNER_WRITE OWNER_EXECUTE
1291          GROUP_READ GROUP_EXECUTE
1292          WORLD_READ WORLD_EXECUTE)
1293
1294# Finally generate a pkg-config file matching this config
1295configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
1296               "${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
1297install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
1298        DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1299
1300# install headers
1301install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
1302    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
1303    FILES_MATCHING PATTERN "*.h")
1304
1305include(CMakePackageConfigHelpers)
1306write_basic_package_version_file(
1307    "${version_config}"
1308    VERSION ${CURL_VERSION}
1309    COMPATIBILITY SameMajorVersion
1310)
1311
1312# Use:
1313# * TARGETS_EXPORT_NAME
1314# * PROJECT_NAME
1315configure_package_config_file(CMake/curl-config.cmake.in
1316        "${project_config}"
1317        INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1318)
1319
1320install(
1321        EXPORT "${TARGETS_EXPORT_NAME}"
1322        NAMESPACE "${PROJECT_NAME}::"
1323        DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1324)
1325
1326install(
1327        FILES ${version_config} ${project_config}
1328        DESTINATION ${CURL_INSTALL_CMAKE_DIR}
1329)
1330
1331# Workaround for MSVS10 to avoid the Dialog Hell
1332# FIXME: This could be removed with future version of CMake.
1333if(MSVC_VERSION EQUAL 1600)
1334  set(CURL_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/CURL.sln")
1335  if(EXISTS "${CURL_SLN_FILENAME}")
1336    file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
1337  endif()
1338endif()
1339
1340if(NOT TARGET uninstall)
1341  configure_file(
1342      ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
1343      ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
1344      IMMEDIATE @ONLY)
1345
1346  add_custom_target(uninstall
1347      COMMAND ${CMAKE_COMMAND} -P
1348      ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
1349endif()
1350