Skip to content

Commit 88450c1

Browse files
authored
Merge pull request libgit2#4283 from tiennou/generic-tls
CMake: make HTTPS support more generic
2 parents 28c8950 + c9bb68c commit 88450c1

File tree

23 files changed

+207
-109
lines changed

23 files changed

+207
-109
lines changed

CMakeLists.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ INCLUDE(CheckStructHasMember)
2828
INCLUDE(AddCFlagIfSupported)
2929
INCLUDE(FindPkgConfig)
3030
INCLUDE(FindThreads)
31+
INCLUDE(FeatureSummary)
3132

3233
# Build options
3334
#
@@ -44,6 +45,7 @@ OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
4445
OPTION( USE_SHA1DC "Use SHA-1 with collision detection" OFF )
4546
OPTION( USE_ICONV "Link with and use iconv library" OFF )
4647
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
48+
OPTION( USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON )
4749
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
4850
OPTION( VALGRIND "Configure build for valgrind" OFF )
4951
OPTION( CURL "Use curl for HTTP if available" ON)
@@ -54,12 +56,6 @@ IF (UNIX AND NOT APPLE)
5456
OPTION( ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF )
5557
ENDIF()
5658

57-
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
58-
SET( USE_ICONV ON )
59-
FIND_PACKAGE(Security)
60-
FIND_PACKAGE(CoreFoundation REQUIRED)
61-
ENDIF()
62-
6359
IF(MSVC)
6460
# This option is only available when building with MSVC. By default, libgit2
6561
# is build using the cdecl calling convention, which is useful if you're
@@ -90,10 +86,6 @@ IF(MSVC)
9086
OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
9187
ENDIF()
9288

93-
IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
94-
OPTION( USE_OPENSSL "Link with and use openssl library" ON )
95-
ENDIF()
96-
9789
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
9890
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
9991
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
@@ -334,3 +326,10 @@ ENDIF ()
334326
IF (BUILD_EXAMPLES)
335327
ADD_SUBDIRECTORY(examples)
336328
ENDIF ()
329+
330+
IF(CMAKE_VERSION VERSION_GREATER 3)
331+
FEATURE_SUMMARY(WHAT ENABLED_FEATURES DISABLED_FEATURES)
332+
ELSE()
333+
PRINT_ENABLED_FEATURES()
334+
PRINT_DISABLED_FEATURES()
335+
ENDIF()
Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_DIRS)
2-
SET(COREFOUNDATION_FOUND TRUE)
3-
ELSE ()
4-
FIND_PATH(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
5-
FIND_LIBRARY(COREFOUNDATION_DIRS NAMES CoreFoundation)
6-
IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_DIRS)
7-
SET(COREFOUNDATION_FOUND TRUE)
8-
ENDIF ()
1+
# Find CoreFoundation.framework
2+
# This will define :
3+
#
4+
# COREFOUNDATION_FOUND
5+
# COREFOUNDATION_LIBRARIES
6+
# COREFOUNDATION_LDFLAGS
7+
#
8+
9+
FIND_PATH(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
10+
FIND_LIBRARY(COREFOUNDATION_LIBRARIES NAMES CoreFoundation)
11+
IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES)
12+
IF (NOT CoreFoundation_FIND_QUIETLY)
13+
MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_LIBRARIES}")
14+
ENDIF()
15+
SET(COREFOUNDATION_FOUND TRUE)
16+
SET(COREFOUNDATION_LDFLAGS "-framework CoreFoundation")
917
ENDIF ()
18+
19+
IF (CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND)
20+
MESSAGE(FATAL "-- CoreFoundation not found")
21+
ENDIF()
22+
23+
MARK_AS_ADVANCED(
24+
COREFOUNDATION_INCLUDE_DIR
25+
COREFOUNDATION_LIBRARIES
26+
)

cmake/Modules/FindSecurity.cmake

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1-
IF (SECURITY_INCLUDE_DIR AND SECURITY_DIRS)
2-
SET(SECURITY_FOUND TRUE)
3-
ELSE ()
4-
FIND_PATH(SECURITY_INCLUDE_DIR NAMES Security/Security.h)
5-
FIND_LIBRARY(SECURITY_DIRS NAMES Security)
6-
IF (SECURITY_INCLUDE_DIR AND SECURITY_DIRS)
7-
SET(SECURITY_FOUND TRUE)
8-
ENDIF ()
1+
# Find Security.framework
2+
# This will define :
3+
#
4+
# SECURITY_FOUND
5+
# SECURITY_LIBRARIES
6+
# SECURITY_LDFLAGS
7+
# SECURITY_HAS_SSLCREATECONTEXT
8+
#
9+
10+
FIND_PATH(SECURITY_INCLUDE_DIR NAMES Security/Security.h)
11+
FIND_LIBRARY(SECURITY_LIBRARIES NAMES Security)
12+
IF (SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES)
13+
IF (NOT Security_FIND_QUIETLY)
14+
MESSAGE("-- Found Security ${SECURITY_LIBRARIES}")
15+
ENDIF()
16+
SET(SECURITY_FOUND TRUE)
17+
SET(SECURITY_LDFLAGS "-framework Security")
18+
CHECK_LIBRARY_EXISTS("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT)
919
ENDIF ()
20+
21+
IF (Security_FIND_REQUIRED AND NOT SECURITY_FOUND)
22+
MESSAGE(FATAL "-- Security not found")
23+
ENDIF()
24+
25+
MARK_AS_ADVANCED(
26+
SECURITY_INCLUDE_DIR
27+
SECURITY_LIBRARIES
28+
)

src/CMakeLists.txt

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
IF(DEBUG_POOL)
22
SET(GIT_DEBUG_POOL 1)
33
ENDIF()
4+
ADD_FEATURE_INFO(debugpool GIT_DEBUG_POOL "debug pool allocator")
45

56
# Add the features.h file as a dummy. This is required for Xcode
67
# to successfully build the libgit2 library when using only
@@ -50,6 +51,7 @@ ENDIF(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR})
5051
IF (ENABLE_TRACE STREQUAL "ON")
5152
SET(GIT_TRACE 1)
5253
ENDIF()
54+
ADD_FEATURE_INFO(tracing GIT_TRACE "tracing support")
5355

5456
CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
5557
IF (HAVE_REGCOMP_L)
@@ -93,26 +95,7 @@ IF(THREADSAFE)
9395
LIST(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT})
9496
LIST(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
9597
ENDIF()
96-
97-
IF (SECURITY_FOUND)
98-
# OS X 10.7 and older do not have some functions we use, fall back to OpenSSL there
99-
CHECK_LIBRARY_EXISTS("${SECURITY_DIRS}" SSLCreateContext "Security/SecureTransport.h" HAVE_NEWER_SECURITY)
100-
IF (HAVE_NEWER_SECURITY)
101-
MESSAGE("-- Found Security ${SECURITY_DIRS}")
102-
LIST(APPEND LIBGIT2_PC_LIBS "-framework Security")
103-
LIST(APPEND LIBGIT2_LIBS ${SECURITY_DIRS})
104-
ELSE()
105-
MESSAGE("-- Security framework is too old, falling back to OpenSSL")
106-
SET(SECURITY_FOUND "NO")
107-
SET(USE_OPENSSL "ON")
108-
ENDIF()
109-
ENDIF()
110-
111-
IF (COREFOUNDATION_FOUND)
112-
MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}")
113-
LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation")
114-
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_DIRS})
115-
ENDIF()
98+
ADD_FEATURE_INFO(threadsafe THREADSAFE "threadsafe support")
11699

117100

118101
IF (WIN32 AND EMBED_SSH_PATH)
@@ -124,7 +107,6 @@ ENDIF()
124107

125108
IF (WIN32 AND WINHTTP)
126109
SET(GIT_WINHTTP 1)
127-
SET(GIT_HTTPS 1)
128110

129111
# Since MinGW does not come with headers or an import library for winhttp,
130112
# we have to include a private header and generate our own import library
@@ -145,8 +127,8 @@ ELSE ()
145127
PKG_CHECK_MODULES(CURL libcurl)
146128
ENDIF ()
147129

148-
IF (NOT AMIGA AND USE_OPENSSL)
149-
FIND_PACKAGE(OpenSSL)
130+
IF (NOT AMIGA AND (USE_HTTPS STREQUAL "OpenSSL" OR USE_HTTPS STREQUAL "ON"))
131+
FIND_PACKAGE(OpenSSL QUIET)
150132
ENDIF ()
151133

152134
IF (CURL_FOUND)
@@ -156,28 +138,96 @@ ELSE ()
156138
LIST(APPEND LIBGIT2_LIBS ${CURL_LIBRARIES})
157139
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
158140
ENDIF()
141+
ADD_FEATURE_INFO(cURL GIT_CURL "cURL for HTTP proxy support")
142+
ENDIF()
143+
144+
IF (USE_HTTPS)
145+
IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
146+
FIND_PACKAGE(Security)
147+
FIND_PACKAGE(CoreFoundation)
148+
ENDIF()
149+
150+
# Auto-select TLS backend
151+
IF (USE_HTTPS STREQUAL ON)
152+
IF (SECURITY_FOUND)
153+
IF (SECURITY_HAS_SSLCREATECONTEXT)
154+
SET(HTTPS_BACKEND "SecureTransport")
155+
ELSE()
156+
MESSAGE("-- Security framework is too old, falling back to OpenSSL")
157+
SET(HTTPS_BACKEND "OpenSSL")
158+
ENDIF()
159+
ELSEIF (WINHTTP)
160+
SET(HTTPS_BACKEND "WinHTTP")
161+
ELSE()
162+
SET(HTTPS_BACKEND "OpenSSL")
163+
ENDIF()
164+
ELSE()
165+
# Backend was explicitly set
166+
SET(HTTPS_BACKEND ${USE_HTTPS})
167+
ENDIF()
168+
169+
# Check that we can find what's required for the selected backend
170+
IF (HTTPS_BACKEND STREQUAL "SecureTransport")
171+
IF (NOT COREFOUNDATION_FOUND)
172+
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found")
173+
ENDIF()
174+
IF (NOT SECURITY_FOUND)
175+
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found")
176+
ENDIF()
177+
IF (NOT SECURITY_HAS_SSLCREATECONTEXT)
178+
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported")
179+
ENDIF()
180+
181+
SET(GIT_SECURE_TRANSPORT 1)
182+
LIST(APPEND LIBGIT2_INCLUDES ${SECURITY_INCLUDE_DIR})
183+
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LIBRARIES} ${SECURITY_LIBRARIES})
184+
LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
185+
ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL")
186+
IF (NOT OPENSSL_FOUND)
187+
MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
188+
ENDIF()
189+
190+
SET(GIT_OPENSSL 1)
191+
LIST(APPEND LIBGIT2_INCLUDES ${OPENSSL_INCLUDE_DIR})
192+
LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
193+
LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
194+
ELSEIF (HTTPS_BACKEND STREQUAL "WinHTTP")
195+
# WinHTTP setup was handled in the WinHTTP-specific block above
196+
ELSE()
197+
MESSAGE(FATAL_ERROR "Asked for backend ${HTTPS_BACKEND} but it wasn't found")
198+
ENDIF()
199+
200+
ADD_FEATURE_INFO(HTTPS ON "using ${HTTPS_BACKEND}")
201+
SET(GIT_HTTPS 1)
202+
ELSE()
203+
ADD_FEATURE_INFO(HTTPS OFF "no support")
159204
ENDIF()
160205

161206
# Specify sha1 implementation
162207
IF (USE_SHA1DC)
208+
ADD_FEATURE_INFO(SHA ON "using SHA1DC")
163209
SET(GIT_SHA1_COLLISIONDETECT 1)
164210
ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
165211
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
166212
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
167213
FILE(GLOB SRC_SHA1 hash/hash_collisiondetect.c hash/sha1dc/*)
168214
ELSEIF (WIN32 AND NOT MINGW)
215+
ADD_FEATURE_INFO(SHA ON "using SHA1_WIN32")
169216
SET(GIT_SHA1_WIN32 1)
170217
FILE(GLOB SRC_SHA1 hash/hash_win32.c)
171218
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
219+
ADD_FEATURE_INFO(SHA ON "using CommonCrypto")
172220
SET(GIT_SHA1_COMMON_CRYPTO 1)
173221
ELSEIF (OPENSSL_FOUND)
222+
ADD_FEATURE_INFO(SHA ON "using OpenSSL")
174223
SET(GIT_SHA1_OPENSSL 1)
175224
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
176225
LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
177226
ELSE()
178227
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
179228
ENDIF ()
180229
ELSE()
230+
ADD_FEATURE_INFO(SHA ON "using generic")
181231
FILE(GLOB SRC_SHA1 hash/hash_generic.c)
182232
ENDIF()
183233

@@ -195,11 +245,13 @@ IF (USE_EXT_HTTP_PARSER AND HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUA
195245
LIST(APPEND LIBGIT2_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
196246
LIST(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
197247
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
248+
ADD_FEATURE_INFO(http-parser ON "http-parser support")
198249
ELSE()
199250
MESSAGE(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
200251
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")
201252
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
202253
LIST(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
254+
ADD_FEATURE_INFO(http-parser ON "http-parser support (bundled)")
203255
ENDIF()
204256

205257
# Optional external dependency: zlib
@@ -213,11 +265,13 @@ IF (ZLIB_FOUND)
213265
ELSE()
214266
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
215267
ENDIF()
268+
ADD_FEATURE_INFO(zlib ON "Zlib support")
216269
ELSE()
217270
MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
218271
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib")
219272
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
220273
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
274+
ADD_FEATURE_INFO(zlib ON "Zlib support (bundled)")
221275
ENDIF()
222276

223277
# Optional external dependency: libssh2
@@ -239,6 +293,7 @@ IF (LIBSSH2_FOUND)
239293
ELSE()
240294
MESSAGE(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
241295
ENDIF()
296+
ADD_FEATURE_INFO(SSH GIT_SSH "SSH transport support")
242297

243298
# Optional external dependency: libgssapi
244299
IF (USE_GSSAPI)
@@ -248,9 +303,10 @@ IF (GSSAPI_FOUND)
248303
SET(GIT_GSSAPI 1)
249304
LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES})
250305
ENDIF()
306+
ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support")
251307

252308
# Optional external dependency: iconv
253-
IF (USE_ICONV)
309+
IF (USE_ICONV OR CMAKE_SYSTEM_NAME MATCHES "Darwin")
254310
FIND_PACKAGE(Iconv)
255311
ENDIF()
256312
IF (ICONV_FOUND)
@@ -259,20 +315,7 @@ IF (ICONV_FOUND)
259315
LIST(APPEND LIBGIT2_LIBS ${ICONV_LIBRARIES})
260316
LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
261317
ENDIF()
262-
263-
IF (SECURITY_FOUND)
264-
SET(GIT_SECURE_TRANSPORT 1)
265-
SET(GIT_HTTPS 1)
266-
LIST(APPEND LIBGIT2_INCLUDES ${SECURITY_INCLUDE_DIR})
267-
ENDIF ()
268-
269-
IF (OPENSSL_FOUND)
270-
SET(GIT_OPENSSL 1)
271-
SET(GIT_HTTPS 1)
272-
LIST(APPEND LIBGIT2_INCLUDES ${OPENSSL_INCLUDE_DIR})
273-
LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
274-
ENDIF()
275-
318+
ADD_FEATURE_INFO(iconv GIT_USE_ICONV "iconv encoding conversion support")
276319

277320

278321
IF (THREADSAFE)
@@ -320,7 +363,10 @@ ELSE()
320363
ENDIF()
321364
FILE(GLOB SRC_OS unix/*.c unix/*.h)
322365
ENDIF()
323-
FILE(GLOB SRC_GIT2 *.c *.h transports/*.c transports/*.h xdiff/*.c xdiff/*.h)
366+
FILE(GLOB SRC_GIT2 *.c *.h
367+
streams/*.c streams/*.h
368+
transports/*.c transports/*.h
369+
xdiff/*.c xdiff/*.h)
324370

325371
# Determine architecture of the machine
326372
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)

src/global.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "sysdir.h"
1212
#include "filter.h"
1313
#include "merge_driver.h"
14-
#include "openssl_stream.h"
14+
#include "streams/openssl.h"
1515
#include "thread-utils.h"
1616
#include "git2/global.h"
1717
#include "transports/ssh.h"

src/global.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ typedef struct {
2525
git_thread *current_thread;
2626
} git_global_st;
2727

28-
#ifdef GIT_OPENSSL
29-
# include <openssl/ssl.h>
30-
extern SSL_CTX *git__ssl_ctx;
31-
#endif
32-
3328
git_global_st *git__global_state(void);
3429

3530
extern git_mutex git__mwindow_mutex;

0 commit comments

Comments
 (0)