Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1 | #*************************************************************************** |
| 2 | # _ _ ____ _ |
| 3 | # Project ___| | | | _ \| | |
| 4 | # / __| | | | |_) | | |
| 5 | # | (__| |_| | _ <| |___ |
| 6 | # \___|\___/|_| \_\_____| |
| 7 | # |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame^] | 8 | # Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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 |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 12 | # are also available at https://curl.haxx.se/docs/copyright.html. |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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 | ########################################################################### |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 22 | # curl/libcurl CMake script |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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. |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 41 | cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 42 | set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}") |
| 43 | include(Utilities) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 44 | include(Macros) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 45 | include(CMakeDependentOption) |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 46 | include(CheckCCompilerFlag) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 47 | |
| 48 | project( CURL C ) |
| 49 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 50 | message(WARNING "the curl cmake build system is poorly maintained. Be aware") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 51 | |
| 52 | file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 53 | string (REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*" |
| 54 | CURL_VERSION ${CURL_VERSION_H_CONTENTS}) |
| 55 | string (REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION}) |
| 56 | string (REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+" |
| 57 | CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS}) |
| 58 | string (REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM}) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 59 | |
| 60 | include_regular_expression("^.*$") # Sukender: Is it necessary? |
| 61 | |
| 62 | # Setup package meta-data |
| 63 | # SET(PACKAGE "curl") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 64 | message(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 Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 69 | # SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.haxx.se/mail/") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 70 | set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}") |
| 71 | set(OS "\"${CMAKE_SYSTEM_NAME}\"") |
| 72 | |
| 73 | include_directories(${PROJECT_BINARY_DIR}/include/curl) |
| 74 | include_directories( ${CURL_SOURCE_DIR}/include ) |
| 75 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 76 | option(CURL_WERROR "Turn compiler warnings into errors" OFF) |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 77 | option(PICKY_COMPILER "Enable picky compiler options" ON) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 78 | option(BUILD_CURL_EXE "Set to ON to build curl executable." ON) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 79 | option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 80 | option(ENABLE_ARES "Set to ON to enable c-ares support" OFF) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 81 | if(WIN32) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 82 | 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 Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 84 | endif() |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 85 | |
| 86 | CMAKE_DEPENDENT_OPTION(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup" |
| 87 | ON "NOT ENABLE_ARES" |
| 88 | OFF) |
| 89 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 90 | option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF) |
| 91 | option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF) |
| 92 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 93 | if(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) |
| 104 | endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) |
| 105 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 106 | if (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) |
| 114 | endif() |
| 115 | |
| 116 | if (ENABLE_CURLDEBUG) |
| 117 | set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG) |
| 118 | endif() |
| 119 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 120 | # For debug libs and exes, add "-d" postfix |
| 121 | set(CMAKE_DEBUG_POSTFIX "-d" CACHE STRING "Set debug library postfix") |
| 122 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 123 | # initialize CURL_LIBS |
| 124 | set(CURL_LIBS "") |
| 125 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 126 | if(ENABLE_ARES) |
| 127 | set(USE_ARES 1) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 128 | find_package(CARES REQUIRED) |
| 129 | list(APPEND CURL_LIBS ${CARES_LIBRARY} ) |
| 130 | set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY}) |
| 131 | endif() |
| 132 | |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 133 | include(CurlSymbolHiding) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 134 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 135 | option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF) |
| 136 | mark_as_advanced(HTTP_ONLY) |
| 137 | option(CURL_DISABLE_FTP "disables FTP" OFF) |
| 138 | mark_as_advanced(CURL_DISABLE_FTP) |
| 139 | option(CURL_DISABLE_LDAP "disables LDAP" OFF) |
| 140 | mark_as_advanced(CURL_DISABLE_LDAP) |
| 141 | option(CURL_DISABLE_TELNET "disables Telnet" OFF) |
| 142 | mark_as_advanced(CURL_DISABLE_TELNET) |
| 143 | option(CURL_DISABLE_DICT "disables DICT" OFF) |
| 144 | mark_as_advanced(CURL_DISABLE_DICT) |
| 145 | option(CURL_DISABLE_FILE "disables FILE" OFF) |
| 146 | mark_as_advanced(CURL_DISABLE_FILE) |
| 147 | option(CURL_DISABLE_TFTP "disables TFTP" OFF) |
| 148 | mark_as_advanced(CURL_DISABLE_TFTP) |
| 149 | option(CURL_DISABLE_HTTP "disables HTTP" OFF) |
| 150 | mark_as_advanced(CURL_DISABLE_HTTP) |
| 151 | |
| 152 | option(CURL_DISABLE_LDAPS "to disable LDAPS" OFF) |
| 153 | mark_as_advanced(CURL_DISABLE_LDAPS) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 154 | |
| 155 | option(CURL_DISABLE_RTSP "to disable RTSP" OFF) |
| 156 | mark_as_advanced(CURL_DISABLE_RTSP) |
| 157 | option(CURL_DISABLE_PROXY "to disable proxy" OFF) |
| 158 | mark_as_advanced(CURL_DISABLE_PROXY) |
| 159 | option(CURL_DISABLE_POP3 "to disable POP3" OFF) |
| 160 | mark_as_advanced(CURL_DISABLE_POP3) |
| 161 | option(CURL_DISABLE_IMAP "to disable IMAP" OFF) |
| 162 | mark_as_advanced(CURL_DISABLE_IMAP) |
| 163 | option(CURL_DISABLE_SMTP "to disable SMTP" OFF) |
| 164 | mark_as_advanced(CURL_DISABLE_SMTP) |
| 165 | option(CURL_DISABLE_GOPHER "to disable Gopher" OFF) |
| 166 | mark_as_advanced(CURL_DISABLE_GOPHER) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 167 | |
| 168 | if(HTTP_ONLY) |
| 169 | set(CURL_DISABLE_FTP ON) |
| 170 | set(CURL_DISABLE_LDAP ON) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 171 | set(CURL_DISABLE_LDAPS ON) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 172 | set(CURL_DISABLE_TELNET ON) |
| 173 | set(CURL_DISABLE_DICT ON) |
| 174 | set(CURL_DISABLE_FILE ON) |
| 175 | set(CURL_DISABLE_TFTP ON) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 176 | 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 Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 181 | endif() |
| 182 | |
| 183 | option(CURL_DISABLE_COOKIES "to disable cookies support" OFF) |
| 184 | mark_as_advanced(CURL_DISABLE_COOKIES) |
| 185 | |
| 186 | option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF) |
| 187 | mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH) |
| 188 | option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF) |
| 189 | mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 190 | option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 191 | mark_as_advanced(ENABLE_IPV6) |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 192 | if(ENABLE_IPV6 AND NOT WIN32) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 193 | 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 Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 203 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 204 | endif() |
| 205 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 206 | CURL_NROFF_CHECK() |
| 207 | find_package(Perl) |
| 208 | |
| 209 | CMAKE_DEPENDENT_OPTION(ENABLE_MANUAL "to provide the built-in manual" |
| 210 | ON "NROFF_USEFUL;PERL_FOUND" |
| 211 | OFF) |
| 212 | |
| 213 | if(NOT PERL_FOUND) |
| 214 | message(STATUS "Perl not found, testing disabled.") |
| 215 | set(BUILD_TESTING OFF) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 216 | endif() |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 217 | if(ENABLE_MANUAL) |
| 218 | set(USE_MANUAL ON) |
| 219 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 220 | |
| 221 | # We need ansi c-flags, especially on HP |
| 222 | set(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}") |
| 223 | set(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS}) |
| 224 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 225 | if(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") |
| 228 | endif() |
| 229 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 230 | # Disable warnings on Borland to avoid changing 3rd party code. |
| 231 | if(BORLAND) |
| 232 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-") |
| 233 | endif(BORLAND) |
| 234 | |
| 235 | # If we are on AIX, do the _ALL_SOURCE magic |
| 236 | if(${CMAKE_SYSTEM_NAME} MATCHES AIX) |
| 237 | set(_ALL_SOURCE 1) |
| 238 | endif(${CMAKE_SYSTEM_NAME} MATCHES AIX) |
| 239 | |
| 240 | # Include all the necessary files for macros |
| 241 | include (CheckFunctionExists) |
| 242 | include (CheckIncludeFile) |
| 243 | include (CheckIncludeFiles) |
| 244 | include (CheckLibraryExists) |
| 245 | include (CheckSymbolExists) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 246 | include (CheckTypeSize) |
| 247 | include (CheckCSourceCompiles) |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 248 | include (CMakeDependentOption) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 249 | |
| 250 | # On windows preload settings |
| 251 | if(WIN32) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 252 | set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 253 | include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake) |
| 254 | endif(WIN32) |
| 255 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 256 | if(ENABLE_THREADED_RESOLVER) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 257 | find_package(Threads REQUIRED) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 258 | if(WIN32) |
| 259 | set(USE_THREADS_WIN32 ON) |
| 260 | else() |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 261 | set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT}) |
| 262 | set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT}) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 263 | endif() |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 264 | set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 265 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 266 | |
| 267 | # Check for all needed libraries |
| 268 | check_library_exists_concat("dl" dlopen HAVE_LIBDL) |
| 269 | check_library_exists_concat("socket" connect HAVE_LIBSOCKET) |
| 270 | check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL) |
| 271 | |
| 272 | # Yellowtab Zeta needs different libraries than BeOS 5. |
| 273 | if(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) |
| 277 | endif(BEOS) |
| 278 | |
| 279 | if(NOT NOT_NEED_LIBNSL) |
| 280 | check_library_exists_concat("nsl" gethostbyname HAVE_LIBNSL) |
| 281 | endif(NOT NOT_NEED_LIBNSL) |
| 282 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 283 | check_function_exists(gethostname HAVE_GETHOSTNAME) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 284 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 285 | if(WIN32) |
| 286 | check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32) |
| 287 | check_library_exists_concat("winmm" getch HAVE_LIBWINMM) |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame^] | 288 | list(APPEND CURL_LIBS "advapi32") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 289 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 290 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 291 | # check SSL libraries |
| 292 | # TODO support GNUTLS, NSS, POLARSSL, AXTLS, CYASSL |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 293 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 294 | if(APPLE) |
| 295 | option(CMAKE_USE_DARWINSSL "enable Apple OS native SSL/TLS" OFF) |
| 296 | endif() |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 297 | if(WIN32) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 298 | 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) |
| 301 | endif() |
| 302 | option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF) |
| 303 | |
| 304 | set(openssl_default ON) |
| 305 | if(WIN32 OR CMAKE_USE_DARWINSSL OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS) |
| 306 | set(openssl_default OFF) |
| 307 | endif() |
| 308 | option(CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default}) |
| 309 | |
| 310 | collect_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 | ) |
| 316 | if(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 Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 318 | endif() |
| 319 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 320 | if(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") |
| 325 | endif() |
| 326 | if(CURL_WINDOWS_SSPI) |
| 327 | set(USE_WINDOWS_SSPI ON) |
| 328 | set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32") |
| 329 | endif() |
| 330 | |
| 331 | if(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}") |
| 345 | endif() |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 346 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 347 | if(CMAKE_USE_OPENSSL) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 348 | 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 Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 360 | 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) |
| 367 | endif() |
| 368 | |
| 369 | if(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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 375 | endif() |
| 376 | |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 377 | option(USE_NGHTTP2 "Use Nghttp2 library" OFF) |
| 378 | if(USE_NGHTTP2) |
| 379 | find_package(NGHTTP2 REQUIRED) |
| 380 | include_directories(${NGHTTP2_INCLUDE_DIRS}) |
| 381 | list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES}) |
| 382 | endif() |
| 383 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 384 | if(NOT CURL_DISABLE_LDAP) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 385 | if(WIN32) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 386 | option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON) |
| 387 | if(USE_WIN32_LDAP) |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 388 | check_library_exists_concat("wldap32" cldap_open HAVE_WLDAP32) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 389 | if(NOT HAVE_WLDAP32) |
| 390 | set(USE_WIN32_LDAP OFF) |
| 391 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 392 | endif() |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 393 | 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 Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 403 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 404 | # Now that we know, we're not using windows LDAP... |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 405 | 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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 409 | # 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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 413 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 414 | set(CMAKE_REQUIRED_INCLUDES_BAK ${CMAKE_REQUIRED_INCLUDES}) |
| 415 | set(CMAKE_LDAP_INCLUDE_DIR "" CACHE STRING "Path to LDAP include directory") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 416 | if(CMAKE_LDAP_INCLUDE_DIR) |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 417 | list(APPEND CMAKE_REQUIRED_INCLUDES ${CMAKE_LDAP_INCLUDE_DIR}) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 418 | endif() |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 419 | check_include_file_concat("ldap.h" HAVE_LDAP_H) |
| 420 | check_include_file_concat("lber.h" HAVE_LBER_H) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 421 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 422 | 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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 430 | else() |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 431 | 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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 475 | endif() |
| 476 | endif() |
| 477 | |
| 478 | endif() |
| 479 | |
| 480 | # No ldap, no ldaps. |
| 481 | if(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() |
| 486 | endif() |
| 487 | |
| 488 | if(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) |
| 491 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 492 | |
| 493 | # Check for idn |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 494 | check_library_exists_concat("idn2" idn2_lookup_ul HAVE_LIBIDN2) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 495 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 496 | # Check for symbol dlopen (same as HAVE_LIBDL) |
| 497 | check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN) |
| 498 | |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 499 | option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 500 | set(HAVE_LIBZ OFF) |
| 501 | set(HAVE_ZLIB_H OFF) |
| 502 | set(HAVE_ZLIB OFF) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 503 | if(CURL_ZLIB) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 504 | 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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 509 | list(APPEND CURL_LIBS ${ZLIB_LIBRARIES}) |
| 510 | include_directories(${ZLIB_INCLUDE_DIRS}) |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 511 | list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS}) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 512 | endif() |
| 513 | endif() |
| 514 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame^] | 515 | option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF) |
| 516 | set(HAVE_BROTLI OFF) |
| 517 | if(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() |
| 525 | endif() |
| 526 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 527 | #libSSH2 |
| 528 | option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON) |
| 529 | mark_as_advanced(CMAKE_USE_LIBSSH2) |
| 530 | set(USE_LIBSSH2 OFF) |
| 531 | set(HAVE_LIBSSH2 OFF) |
| 532 | set(HAVE_LIBSSH2_H OFF) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 533 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 534 | if(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 Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 539 | list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 540 | include_directories("${LIBSSH2_INCLUDE_DIR}") |
| 541 | set(HAVE_LIBSSH2 ON) |
| 542 | set(USE_LIBSSH2 ON) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 543 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 544 | # 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) |
| 559 | endif(CMAKE_USE_LIBSSH2) |
| 560 | |
| 561 | option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF) |
| 562 | mark_as_advanced(CMAKE_USE_GSSAPI) |
| 563 | |
| 564 | if(CMAKE_USE_GSSAPI) |
| 565 | find_package(GSS) |
| 566 | |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 567 | set(HAVE_GSSAPI ${GSS_FOUND}) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 568 | if(GSS_FOUND) |
| 569 | |
| 570 | message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"") |
| 571 | |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 572 | list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRECTORIES}) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 573 | 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 Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 608 | include_directories(${GSS_INCLUDE_DIRECTORIES}) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 609 | 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() |
| 618 | endif() |
| 619 | |
| 620 | option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON) |
| 621 | if(ENABLE_UNIX_SOCKETS) |
| 622 | include(CheckStructHasMember) |
| 623 | check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS) |
| 624 | else() |
| 625 | unset(USE_UNIX_SOCKETS CACHE) |
| 626 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 627 | |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 628 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 629 | # |
| 630 | # CA handling |
| 631 | # |
| 632 | set(CURL_CA_BUNDLE "auto" CACHE STRING |
| 633 | "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.") |
| 634 | set(CURL_CA_FALLBACK OFF CACHE BOOL |
| 635 | "Set ON to use built-in CA store of TLS backend. Defaults to OFF") |
| 636 | set(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 | |
| 639 | if("${CURL_CA_BUNDLE}" STREQUAL "") |
| 640 | message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.") |
| 641 | elseif("${CURL_CA_BUNDLE}" STREQUAL "none") |
| 642 | unset(CURL_CA_BUNDLE CACHE) |
| 643 | elseif("${CURL_CA_BUNDLE}" STREQUAL "auto") |
| 644 | unset(CURL_CA_BUNDLE CACHE) |
| 645 | set(CURL_CA_BUNDLE_AUTODETECT TRUE) |
| 646 | else() |
| 647 | set(CURL_CA_BUNDLE_SET TRUE) |
| 648 | endif() |
| 649 | |
| 650 | if("${CURL_CA_PATH}" STREQUAL "") |
| 651 | message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.") |
| 652 | elseif("${CURL_CA_PATH}" STREQUAL "none") |
| 653 | unset(CURL_CA_PATH CACHE) |
| 654 | elseif("${CURL_CA_PATH}" STREQUAL "auto") |
| 655 | unset(CURL_CA_PATH CACHE) |
| 656 | set(CURL_CA_PATH_AUTODETECT TRUE) |
| 657 | else() |
| 658 | set(CURL_CA_PATH_SET TRUE) |
| 659 | endif() |
| 660 | |
| 661 | if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT) |
| 662 | # Skip autodetection of unset CA path because CA bundle is set explicitly |
| 663 | elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT) |
| 664 | # Skip autodetection of unset CA bundle because CA path is set explicitly |
| 665 | elseif(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() |
| 692 | endif() |
| 693 | |
| 694 | if(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.") |
| 698 | endif() |
| 699 | |
| 700 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 701 | # Check for header files |
| 702 | if(NOT UNIX) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 703 | check_include_file_concat("windows.h" HAVE_WINDOWS_H) |
| 704 | check_include_file_concat("winsock.h" HAVE_WINSOCK_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 705 | check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H) |
| 706 | check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 707 | if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL) |
| 708 | set(CURL_LIBS ${CURL_LIBS} "crypt32") |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 709 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 710 | endif(NOT UNIX) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 711 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 712 | check_include_file_concat("stdio.h" HAVE_STDIO_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 713 | check_include_file_concat("inttypes.h" HAVE_INTTYPES_H) |
| 714 | check_include_file_concat("sys/filio.h" HAVE_SYS_FILIO_H) |
| 715 | check_include_file_concat("sys/ioctl.h" HAVE_SYS_IOCTL_H) |
| 716 | check_include_file_concat("sys/param.h" HAVE_SYS_PARAM_H) |
| 717 | check_include_file_concat("sys/poll.h" HAVE_SYS_POLL_H) |
| 718 | check_include_file_concat("sys/resource.h" HAVE_SYS_RESOURCE_H) |
| 719 | check_include_file_concat("sys/select.h" HAVE_SYS_SELECT_H) |
| 720 | check_include_file_concat("sys/socket.h" HAVE_SYS_SOCKET_H) |
| 721 | check_include_file_concat("sys/sockio.h" HAVE_SYS_SOCKIO_H) |
| 722 | check_include_file_concat("sys/stat.h" HAVE_SYS_STAT_H) |
| 723 | check_include_file_concat("sys/time.h" HAVE_SYS_TIME_H) |
| 724 | check_include_file_concat("sys/types.h" HAVE_SYS_TYPES_H) |
| 725 | check_include_file_concat("sys/uio.h" HAVE_SYS_UIO_H) |
| 726 | check_include_file_concat("sys/un.h" HAVE_SYS_UN_H) |
| 727 | check_include_file_concat("sys/utime.h" HAVE_SYS_UTIME_H) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 728 | check_include_file_concat("sys/xattr.h" HAVE_SYS_XATTR_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 729 | check_include_file_concat("alloca.h" HAVE_ALLOCA_H) |
| 730 | check_include_file_concat("arpa/inet.h" HAVE_ARPA_INET_H) |
| 731 | check_include_file_concat("arpa/tftp.h" HAVE_ARPA_TFTP_H) |
| 732 | check_include_file_concat("assert.h" HAVE_ASSERT_H) |
| 733 | check_include_file_concat("crypto.h" HAVE_CRYPTO_H) |
| 734 | check_include_file_concat("des.h" HAVE_DES_H) |
| 735 | check_include_file_concat("err.h" HAVE_ERR_H) |
| 736 | check_include_file_concat("errno.h" HAVE_ERRNO_H) |
| 737 | check_include_file_concat("fcntl.h" HAVE_FCNTL_H) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 738 | check_include_file_concat("idn2.h" HAVE_IDN2_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 739 | check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H) |
| 740 | check_include_file_concat("io.h" HAVE_IO_H) |
| 741 | check_include_file_concat("krb.h" HAVE_KRB_H) |
| 742 | check_include_file_concat("libgen.h" HAVE_LIBGEN_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 743 | check_include_file_concat("locale.h" HAVE_LOCALE_H) |
| 744 | check_include_file_concat("net/if.h" HAVE_NET_IF_H) |
| 745 | check_include_file_concat("netdb.h" HAVE_NETDB_H) |
| 746 | check_include_file_concat("netinet/in.h" HAVE_NETINET_IN_H) |
| 747 | check_include_file_concat("netinet/tcp.h" HAVE_NETINET_TCP_H) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 748 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 749 | check_include_file_concat("pem.h" HAVE_PEM_H) |
| 750 | check_include_file_concat("poll.h" HAVE_POLL_H) |
| 751 | check_include_file_concat("pwd.h" HAVE_PWD_H) |
| 752 | check_include_file_concat("rsa.h" HAVE_RSA_H) |
| 753 | check_include_file_concat("setjmp.h" HAVE_SETJMP_H) |
| 754 | check_include_file_concat("sgtty.h" HAVE_SGTTY_H) |
| 755 | check_include_file_concat("signal.h" HAVE_SIGNAL_H) |
| 756 | check_include_file_concat("ssl.h" HAVE_SSL_H) |
| 757 | check_include_file_concat("stdbool.h" HAVE_STDBOOL_H) |
| 758 | check_include_file_concat("stdint.h" HAVE_STDINT_H) |
| 759 | check_include_file_concat("stdio.h" HAVE_STDIO_H) |
| 760 | check_include_file_concat("stdlib.h" HAVE_STDLIB_H) |
| 761 | check_include_file_concat("string.h" HAVE_STRING_H) |
| 762 | check_include_file_concat("strings.h" HAVE_STRINGS_H) |
| 763 | check_include_file_concat("stropts.h" HAVE_STROPTS_H) |
| 764 | check_include_file_concat("termio.h" HAVE_TERMIO_H) |
| 765 | check_include_file_concat("termios.h" HAVE_TERMIOS_H) |
| 766 | check_include_file_concat("time.h" HAVE_TIME_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 767 | check_include_file_concat("unistd.h" HAVE_UNISTD_H) |
| 768 | check_include_file_concat("utime.h" HAVE_UTIME_H) |
| 769 | check_include_file_concat("x509.h" HAVE_X509_H) |
| 770 | |
| 771 | check_include_file_concat("process.h" HAVE_PROCESS_H) |
| 772 | check_include_file_concat("stddef.h" HAVE_STDDEF_H) |
| 773 | check_include_file_concat("dlfcn.h" HAVE_DLFCN_H) |
| 774 | check_include_file_concat("malloc.h" HAVE_MALLOC_H) |
| 775 | check_include_file_concat("memory.h" HAVE_MEMORY_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 776 | check_include_file_concat("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H) |
| 777 | check_include_file_concat("stdint.h" HAVE_STDINT_H) |
| 778 | check_include_file_concat("sockio.h" HAVE_SOCKIO_H) |
| 779 | check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 780 | |
| 781 | check_type_size(size_t SIZEOF_SIZE_T) |
| 782 | check_type_size(ssize_t SIZEOF_SSIZE_T) |
| 783 | check_type_size("long long" SIZEOF_LONG_LONG) |
| 784 | check_type_size("long" SIZEOF_LONG) |
| 785 | check_type_size("short" SIZEOF_SHORT) |
| 786 | check_type_size("int" SIZEOF_INT) |
| 787 | check_type_size("__int64" SIZEOF___INT64) |
| 788 | check_type_size("long double" SIZEOF_LONG_DOUBLE) |
| 789 | check_type_size("time_t" SIZEOF_TIME_T) |
| 790 | if(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) |
| 797 | endif(NOT HAVE_SIZEOF_SSIZE_T) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 798 | # off_t is sized later, after the HAVE_FILE_OFFSET_BITS test |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 799 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 800 | if(HAVE_SIZEOF_LONG_LONG) |
| 801 | set(HAVE_LONGLONG 1) |
| 802 | set(HAVE_LL 1) |
| 803 | endif(HAVE_SIZEOF_LONG_LONG) |
| 804 | |
| 805 | find_file(RANDOM_FILE urandom /dev) |
| 806 | mark_as_advanced(RANDOM_FILE) |
| 807 | |
| 808 | # Check for some functions that are used |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 809 | if(HAVE_LIBWS2_32) |
| 810 | set(CMAKE_REQUIRED_LIBRARIES ws2_32) |
| 811 | elseif(HAVE_LIBSOCKET) |
| 812 | set(CMAKE_REQUIRED_LIBRARIES socket) |
| 813 | endif() |
| 814 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 815 | check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME) |
| 816 | check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 817 | # 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. |
| 819 | if(NOT APPLE) |
| 820 | check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL) |
| 821 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 822 | check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT) |
| 823 | check_symbol_exists(strdup "${CURL_INCLUDES}" HAVE_STRDUP) |
| 824 | check_symbol_exists(strstr "${CURL_INCLUDES}" HAVE_STRSTR) |
| 825 | check_symbol_exists(strtok_r "${CURL_INCLUDES}" HAVE_STRTOK_R) |
| 826 | check_symbol_exists(strftime "${CURL_INCLUDES}" HAVE_STRFTIME) |
| 827 | check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME) |
| 828 | check_symbol_exists(strcasecmp "${CURL_INCLUDES}" HAVE_STRCASECMP) |
| 829 | check_symbol_exists(stricmp "${CURL_INCLUDES}" HAVE_STRICMP) |
| 830 | check_symbol_exists(strcmpi "${CURL_INCLUDES}" HAVE_STRCMPI) |
| 831 | check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI) |
| 832 | check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM) |
| 833 | if(NOT HAVE_STRNCMPI) |
| 834 | set(HAVE_STRCMPI) |
| 835 | endif(NOT HAVE_STRNCMPI) |
| 836 | check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR) |
| 837 | check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R) |
| 838 | check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY) |
| 839 | check_symbol_exists(inet_addr "${CURL_INCLUDES}" HAVE_INET_ADDR) |
| 840 | check_symbol_exists(inet_ntoa "${CURL_INCLUDES}" HAVE_INET_NTOA) |
| 841 | check_symbol_exists(inet_ntoa_r "${CURL_INCLUDES}" HAVE_INET_NTOA_R) |
| 842 | check_symbol_exists(tcsetattr "${CURL_INCLUDES}" HAVE_TCSETATTR) |
| 843 | check_symbol_exists(tcgetattr "${CURL_INCLUDES}" HAVE_TCGETATTR) |
| 844 | check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR) |
| 845 | check_symbol_exists(closesocket "${CURL_INCLUDES}" HAVE_CLOSESOCKET) |
| 846 | check_symbol_exists(setvbuf "${CURL_INCLUDES}" HAVE_SETVBUF) |
| 847 | check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP) |
| 848 | check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R) |
| 849 | check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT) |
| 850 | check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID) |
| 851 | check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID) |
| 852 | check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 853 | check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R) |
| 854 | check_symbol_exists(localtime_r "${CURL_INCLUDES}" HAVE_LOCALTIME_R) |
| 855 | |
| 856 | check_symbol_exists(gethostbyname "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME) |
| 857 | check_symbol_exists(gethostbyname_r "${CURL_INCLUDES}" HAVE_GETHOSTBYNAME_R) |
| 858 | |
| 859 | check_symbol_exists(signal "${CURL_INCLUDES}" HAVE_SIGNAL_FUNC) |
| 860 | check_symbol_exists(SIGALRM "${CURL_INCLUDES}" HAVE_SIGNAL_MACRO) |
| 861 | if(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO) |
| 862 | set(HAVE_SIGNAL 1) |
| 863 | endif(HAVE_SIGNAL_FUNC AND HAVE_SIGNAL_MACRO) |
| 864 | check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME) |
| 865 | check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL) |
| 866 | check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64) |
| 867 | check_symbol_exists(strerror_r "${CURL_INCLUDES}" HAVE_STRERROR_R) |
| 868 | check_symbol_exists(siginterrupt "${CURL_INCLUDES}" HAVE_SIGINTERRUPT) |
| 869 | check_symbol_exists(perror "${CURL_INCLUDES}" HAVE_PERROR) |
| 870 | check_symbol_exists(fork "${CURL_INCLUDES}" HAVE_FORK) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 871 | check_symbol_exists(getaddrinfo "${CURL_INCLUDES}" HAVE_GETADDRINFO) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 872 | check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO) |
| 873 | check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS) |
| 874 | check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE) |
| 875 | check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE) |
| 876 | check_symbol_exists(getprotobyname "${CURL_INCLUDES}" HAVE_GETPROTOBYNAME) |
| 877 | check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 878 | check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE) |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 879 | check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 880 | check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT) |
| 881 | check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL) |
| 882 | check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL) |
| 883 | check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT) |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 884 | check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 885 | |
| 886 | # symbol exists in win32, but function does not. |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 887 | if(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() |
| 896 | else() |
| 897 | check_function_exists(inet_pton HAVE_INET_PTON) |
| 898 | endif() |
| 899 | |
| 900 | check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR) |
| 901 | if(HAVE_FSETXATTR) |
| 902 | foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6) |
| 903 | curl_internal_test_run(${CURL_TEST}) |
| 904 | endforeach(CURL_TEST) |
| 905 | endif(HAVE_FSETXATTR) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 906 | |
| 907 | # sigaction and sigsetjmp are special. Use special mechanism for |
| 908 | # detecting those, but only if previous attempt failed. |
| 909 | if(HAVE_SIGNAL_H) |
| 910 | check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION) |
| 911 | endif(HAVE_SIGNAL_H) |
| 912 | |
| 913 | if(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) |
| 920 | endif(NOT HAVE_SIGSETJMP) |
| 921 | |
| 922 | # If there is no stricmp(), do not allow LDAP to parse URLs |
| 923 | if(NOT HAVE_STRICMP) |
| 924 | set(HAVE_LDAP_URL_PARSE 1) |
| 925 | endif(NOT HAVE_STRICMP) |
| 926 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 927 | # Do curl specific tests |
| 928 | foreach(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}) |
| 963 | endforeach(CURL_TEST) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 964 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 965 | if(HAVE_FILE_OFFSET_BITS) |
| 966 | set(_FILE_OFFSET_BITS 64) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 967 | set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 968 | endif(HAVE_FILE_OFFSET_BITS) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 969 | check_type_size("off_t" SIZEOF_OFF_T) |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 970 | |
| 971 | # include this header to get the type |
| 972 | set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include") |
| 973 | set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h") |
| 974 | check_type_size("curl_off_t" SIZEOF_CURL_OFF_T) |
| 975 | set(CMAKE_EXTRA_INCLUDE_FILES "") |
| 976 | |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 977 | set(CMAKE_REQUIRED_FLAGS) |
| 978 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 979 | foreach(CURL_TEST |
| 980 | HAVE_GLIBC_STRERROR_R |
| 981 | HAVE_POSIX_STRERROR_R |
| 982 | ) |
| 983 | curl_internal_test_run(${CURL_TEST}) |
| 984 | endforeach(CURL_TEST) |
| 985 | |
| 986 | # Check for reentrant |
| 987 | foreach(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}) |
| 1000 | endforeach(CURL_TEST) |
| 1001 | |
| 1002 | if(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) |
| 1015 | endif(NEED_REENTRANT) |
| 1016 | |
| 1017 | if(HAVE_INET_NTOA_R_DECL_REENTRANT) |
| 1018 | set(HAVE_INET_NTOA_R_DECL 1) |
| 1019 | set(NEED_REENTRANT 1) |
| 1020 | endif(HAVE_INET_NTOA_R_DECL_REENTRANT) |
| 1021 | |
| 1022 | # Some other minor tests |
| 1023 | |
| 1024 | if(NOT HAVE_IN_ADDR_T) |
| 1025 | set(in_addr_t "unsigned long") |
| 1026 | endif(NOT HAVE_IN_ADDR_T) |
| 1027 | |
| 1028 | # Fix libz / zlib.h |
| 1029 | |
| 1030 | if(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) |
| 1038 | endif(NOT CURL_SPECIAL_LIBZ) |
| 1039 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1040 | # Check for nonblocking |
| 1041 | set(HAVE_DISABLED_NONBLOCKING 1) |
| 1042 | if(HAVE_FIONBIO OR |
| 1043 | HAVE_IOCTLSOCKET OR |
| 1044 | HAVE_IOCTLSOCKET_CASE OR |
| 1045 | HAVE_O_NONBLOCK) |
| 1046 | set(HAVE_DISABLED_NONBLOCKING) |
| 1047 | endif(HAVE_FIONBIO OR |
| 1048 | HAVE_IOCTLSOCKET OR |
| 1049 | HAVE_IOCTLSOCKET_CASE OR |
| 1050 | HAVE_O_NONBLOCK) |
| 1051 | |
| 1052 | if(RETSIGTYPE_TEST) |
| 1053 | set(RETSIGTYPE void) |
| 1054 | else(RETSIGTYPE_TEST) |
| 1055 | set(RETSIGTYPE int) |
| 1056 | endif(RETSIGTYPE_TEST) |
| 1057 | |
| 1058 | if(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) |
| 1072 | endif(CMAKE_COMPILER_IS_GNUCC AND APPLE) |
| 1073 | |
| 1074 | if(HAVE_SOCKLEN_T) |
| 1075 | set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1076 | 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 Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1081 | check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1082 | set(CMAKE_EXTRA_INCLUDE_FILES) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1083 | if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1084 | message(FATAL_ERROR |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1085 | "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log") |
| 1086 | endif() |
| 1087 | else() |
| 1088 | set(CURL_TYPEOF_CURL_SOCKLEN_T int) |
| 1089 | set(CURL_SIZEOF_CURL_SOCKLEN_T ${SIZEOF_INT}) |
| 1090 | endif() |
| 1091 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1092 | # TODO test which of these headers are required |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1093 | if(WIN32) |
| 1094 | set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H}) |
| 1095 | else() |
| 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}) |
| 1099 | endif() |
| 1100 | set(CURL_PULL_STDINT_H ${HAVE_STDINT_H}) |
| 1101 | set(CURL_PULL_INTTYPES_H ${HAVE_INTTYPES_H}) |
| 1102 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1103 | include(CMake/OtherTests.cmake) |
| 1104 | |
| 1105 | add_definitions(-DHAVE_CONFIG_H) |
| 1106 | |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 1107 | # For windows, all compilers used by cmake should support large files |
| 1108 | if(WIN32) |
| 1109 | set(USE_WIN32_LARGE_FILES ON) |
| 1110 | endif(WIN32) |
| 1111 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1112 | if(MSVC) |
| 1113 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1114 | 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 Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1119 | endif(MSVC) |
| 1120 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame^] | 1121 | if(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() |
| 1128 | endif(CURL_WERROR) |
| 1129 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1130 | # Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it). |
| 1131 | function(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 Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1136 | string(REGEX REPLACE "\\\\\n" "!π!α!" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1137 | string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1138 | string(REPLACE "!π!α!" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT}) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1139 | |
| 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 | |
| 1144 | endfunction() |
| 1145 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 1146 | if(WIN32 AND NOT CYGWIN) |
| 1147 | set(CURL_INSTALL_CMAKE_DIR CMake) |
| 1148 | else() |
| 1149 | set(CURL_INSTALL_CMAKE_DIR lib/cmake/curl) |
| 1150 | endif() |
| 1151 | |
| 1152 | if(USE_MANUAL) |
| 1153 | add_subdirectory(docs) |
| 1154 | endif() |
| 1155 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1156 | add_subdirectory(lib) |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 1157 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1158 | if(BUILD_CURL_EXE) |
| 1159 | add_subdirectory(src) |
| 1160 | endif() |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 1161 | |
| 1162 | include(CTest) |
| 1163 | if(BUILD_TESTING) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1164 | add_subdirectory(tests) |
| 1165 | endif() |
| 1166 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1167 | # Helper to populate a list (_items) with a label when conditions (the remaining |
| 1168 | # args) are satisfied |
| 1169 | function(_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() |
| 1174 | endfunction() |
| 1175 | |
| 1176 | # Clear list and try to detect available features |
| 1177 | set(_items) |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 1178 | _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI) |
| 1179 | _add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1180 | _add_if("DarwinSSL" SSL_ENABLED AND USE_DARWINSSL) |
| 1181 | _add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1182 | _add_if("IPv6" ENABLE_IPV6) |
| 1183 | _add_if("unix-sockets" USE_UNIX_SOCKETS) |
| 1184 | _add_if("libz" HAVE_LIBZ) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 1185 | _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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1189 | # TODO SSP1 (WinSSL) check is missing |
| 1190 | _add_if("SSPI" USE_WINDOWS_SSPI) |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 1191 | _add_if("GSS-API" HAVE_GSSAPI) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1192 | # TODO SSP1 missing for SPNEGO |
| 1193 | _add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 1194 | (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1195 | _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 1196 | (HAVE_GSSAPI OR USE_WINDOWS_SSPI)) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1197 | # NTLM support requires crypto function adaptions from various SSL libs |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1198 | # TODO alternative SSL libs tests for SSP1, GNUTLS, NSS |
| 1199 | if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_DARWINSSL OR USE_MBEDTLS)) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1200 | _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) |
| 1203 | endif() |
| 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) |
| 1208 | string(REPLACE ";" " " SUPPORT_FEATURES "${_items}") |
| 1209 | message(STATUS "Enabled features: ${SUPPORT_FEATURES}") |
| 1210 | |
| 1211 | # Clear list and try to detect available protocols |
| 1212 | set(_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) |
| 1238 | list(SORT _items) |
| 1239 | string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}") |
| 1240 | message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}") |
| 1241 | |
| 1242 | # curl-config needs the following options to be set. |
| 1243 | set(CC "${CMAKE_C_COMPILER}") |
| 1244 | # TODO probably put a -D... options here? |
| 1245 | set(CONFIGURE_OPTIONS "") |
| 1246 | # TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB? |
| 1247 | set(CPPFLAG_CURL_STATICLIB "") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1248 | set(CURLVERSION "${CURL_VERSION}") |
| 1249 | set(ENABLE_SHARED "yes") |
| 1250 | if(CURL_STATICLIB) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 1251 | set(ENABLE_STATIC "yes") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1252 | else() |
| 1253 | set(ENABLE_STATIC "no") |
| 1254 | endif() |
| 1255 | set(exec_prefix "\${prefix}") |
| 1256 | set(includedir "\${prefix}/include") |
| 1257 | set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 1258 | set(LIBCURL_LIBS "") |
| 1259 | set(libdir "${CMAKE_INSTALL_PREFIX}/lib") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1260 | foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS}) |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1261 | if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-") |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 1262 | set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}") |
| 1263 | else() |
| 1264 | set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}") |
| 1265 | endif() |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1266 | endforeach() |
| 1267 | # "a" (Linux) or "lib" (Windows) |
| 1268 | string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 1269 | set(prefix "${CMAKE_INSTALL_PREFIX}") |
| 1270 | # Set this to "yes" to append all libraries on which -lcurl is dependent |
| 1271 | set(REQUIRE_LIB_DEPS "no") |
| 1272 | # SUPPORT_FEATURES |
| 1273 | # SUPPORT_PROTOCOLS |
| 1274 | set(VERSIONNUM "${CURL_VERSION_NUM}") |
| 1275 | |
| 1276 | # Finally generate a "curl-config" matching this config |
| 1277 | configure_file("${CURL_SOURCE_DIR}/curl-config.in" |
| 1278 | "${CURL_BINARY_DIR}/curl-config" @ONLY) |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 1279 | install(FILES "${CURL_BINARY_DIR}/curl-config" |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1280 | 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 |
| 1287 | configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in" |
| 1288 | "${CURL_BINARY_DIR}/libcurl.pc" @ONLY) |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 1289 | install(FILES "${CURL_BINARY_DIR}/libcurl.pc" |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1290 | DESTINATION lib/pkgconfig) |
| 1291 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 1292 | # This needs to be run very last so other parts of the scripts can take advantage of this. |
| 1293 | if(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") |
| 1295 | endif() |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1296 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1297 | # install headers |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1298 | install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl" |
| 1299 | DESTINATION include |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1300 | FILES_MATCHING PATTERN "*.h") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1301 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 1302 | |
| 1303 | include(CMakePackageConfigHelpers) |
| 1304 | write_basic_package_version_file( |
| 1305 | "${PROJECT_BINARY_DIR}/curl-config-version.cmake" |
| 1306 | VERSION ${CURL_VERSION} |
| 1307 | COMPATIBILITY SameMajorVersion |
| 1308 | ) |
| 1309 | |
| 1310 | configure_file(CMake/curl-config.cmake |
| 1311 | "${PROJECT_BINARY_DIR}/curl-config.cmake" |
| 1312 | COPYONLY |
| 1313 | ) |
| 1314 | |
| 1315 | install( |
| 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 SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1321 | # Workaround for MSVS10 to avoid the Dialog Hell |
| 1322 | # FIXME: This could be removed with future version of CMake. |
| 1323 | if(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() |
| 1328 | endif() |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 1329 | |
| 1330 | if(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) |
| 1339 | endif() |