Skip to content

Commit 9980be0

Browse files
committed
cmake: Add USE_HTTPS as a CMake option
It defaults to ON, e.g. "pick whatever default is appropriate for the platform". It accepts one of SecureTransport, OpenSSL, WinHTTP, or OFF. It errors if the backend library couldn't be found.
1 parent 10b25db commit 9980be0

File tree

3 files changed

+57
-30
lines changed

3 files changed

+57
-30
lines changed

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
4545
OPTION( USE_SHA1DC "Use SHA-1 with collision detection" OFF )
4646
OPTION( USE_ICONV "Link with and use iconv library" OFF )
4747
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 )
4849
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
4950
OPTION( VALGRIND "Configure build for valgrind" OFF )
5051
OPTION( CURL "Use curl for HTTP if available" ON)
@@ -91,10 +92,6 @@ IF(MSVC)
9192
OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
9293
ENDIF()
9394

94-
IF (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
95-
OPTION( USE_OPENSSL "Link with and use openssl library" ON )
96-
ENDIF()
97-
9895
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
9996
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
10097
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"

src/CMakeLists.txt

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ IF(THREADSAFE)
9797
ENDIF()
9898
ADD_FEATURE_INFO(threadsafe THREADSAFE "threadsafe support")
9999

100-
IF (SECURITY_FOUND)
101-
IF (SECURITY_HAS_SSLCREATECONTEXT)
102-
LIST(APPEND LIBGIT2_PC_LIBS ${SECURITY_LDFLAGS})
103-
ELSE()
104-
MESSAGE("-- Security framework is too old, falling back to OpenSSL")
105-
SET(USE_OPENSSL "ON")
106-
ENDIF()
107-
ENDIF()
108-
109100
IF (COREFOUNDATION_FOUND)
110101
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LIBRARIES})
111102
LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS})
@@ -121,7 +112,6 @@ ENDIF()
121112

122113
IF (WIN32 AND WINHTTP)
123114
SET(GIT_WINHTTP 1)
124-
SET(GIT_HTTPS 1)
125115

126116
# Since MinGW does not come with headers or an import library for winhttp,
127117
# we have to include a private header and generate our own import library
@@ -142,7 +132,7 @@ ELSE ()
142132
PKG_CHECK_MODULES(CURL libcurl)
143133
ENDIF ()
144134

145-
IF (NOT AMIGA AND USE_OPENSSL)
135+
IF (NOT AMIGA AND (USE_HTTPS STREQUAL "OpenSSL" OR USE_HTTPS STREQUAL "ON"))
146136
FIND_PACKAGE(OpenSSL)
147137
ENDIF ()
148138

@@ -156,6 +146,60 @@ ELSE ()
156146
ADD_FEATURE_INFO(cURL GIT_CURL "cURL for HTTP proxy support")
157147
ENDIF()
158148

149+
IF (USE_HTTPS)
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 SECURITY_FOUND)
172+
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found")
173+
ENDIF()
174+
IF (NOT SECURITY_HAS_SSLCREATECONTEXT)
175+
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported")
176+
ENDIF()
177+
178+
SET(GIT_SECURE_TRANSPORT 1)
179+
LIST(APPEND LIBGIT2_INCLUDES ${SECURITY_INCLUDE_DIR})
180+
LIST(APPEND LIBGIT2_LIBS ${SECURITY_LIBRARIES})
181+
LIST(APPEND LIBGIT2_PC_LIBS ${SECURITY_LDFLAGS})
182+
ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL")
183+
IF (NOT OPENSSL_FOUND)
184+
MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
185+
ENDIF()
186+
187+
SET(GIT_OPENSSL 1)
188+
LIST(APPEND LIBGIT2_INCLUDES ${OPENSSL_INCLUDE_DIR})
189+
LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
190+
LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
191+
ELSEIF (HTTPS_BACKEND STREQUAL "WinHTTP")
192+
# WinHTTP setup was handled in the WinHTTP-specific block above
193+
ELSE()
194+
MESSAGE(FATAL_ERROR "Asked for backend ${HTTPS_BACKEND} but it wasn't found")
195+
ENDIF()
196+
197+
ADD_FEATURE_INFO(HTTPS ON "using ${HTTPS_BACKEND}")
198+
SET(GIT_HTTPS 1)
199+
ELSE()
200+
ADD_FEATURE_INFO(HTTPS OFF "no support")
201+
ENDIF()
202+
159203
# Specify sha1 implementation
160204
IF (USE_SHA1DC)
161205
ADD_FEATURE_INFO(SHA ON "using SHA1DC")
@@ -270,20 +314,6 @@ IF (ICONV_FOUND)
270314
ENDIF()
271315
ADD_FEATURE_INFO(iconv GIT_USE_ICONV "iconv encoding conversion support")
272316

273-
IF (SECURITY_FOUND)
274-
SET(GIT_SECURE_TRANSPORT 1)
275-
SET(GIT_HTTPS 1)
276-
LIST(APPEND LIBGIT2_INCLUDES ${SECURITY_INCLUDE_DIR})
277-
ENDIF ()
278-
279-
IF (OPENSSL_FOUND)
280-
SET(GIT_OPENSSL 1)
281-
SET(GIT_HTTPS 1)
282-
LIST(APPEND LIBGIT2_INCLUDES ${OPENSSL_INCLUDE_DIR})
283-
LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
284-
ENDIF()
285-
286-
287317

288318
IF (THREADSAFE)
289319
IF (NOT WIN32)

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ IF (MSVC_IDE)
5252
SET_SOURCE_FILES_PROPERTIES("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
5353
ENDIF ()
5454

55-
IF (GIT_HTTPS)
55+
IF (USE_HTTPS)
5656
ADD_TEST(libgit2_clar "${libgit2_BINARY_DIR}/libgit2_clar" -ionline -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style)
5757
ELSE ()
5858
ADD_TEST(libgit2_clar "${libgit2_BINARY_DIR}/libgit2_clar" -v -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style)

0 commit comments

Comments
 (0)