Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10fdd8e

Browse files
committed
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 0752ed7 commit 10fdd8e

File tree

1 file changed

+56
-39
lines changed

1 file changed

+56
-39
lines changed

CMakeLists.txt

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
4040
OPTION( USE_SHA1DC "Use SHA-1 with collision detection" OFF )
4141
OPTION( USE_ICONV "Link with and use iconv library" OFF )
4242
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
43+
OPTION( USE_HTTPS "Enable HTTPS support" ON )
4344
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
4445
OPTION( VALGRIND "Configure build for valgrind" OFF )
4546
OPTION( CURL "Use curl for HTTP if available" ON)
@@ -89,10 +90,6 @@ IF(MSVC)
8990
OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
9091
ENDIF()
9192

92-
IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
93-
OPTION( USE_OPENSSL "Link with and use openssl library" ON )
94-
ENDIF()
95-
9693
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
9794
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
9895
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
@@ -208,21 +205,6 @@ STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "$
208205
# Find required dependencies
209206
INCLUDE_DIRECTORIES(src include)
210207

211-
IF (SECURITY_FOUND)
212-
# OS X 10.7 and older do not have some functions we use, fall back to OpenSSL there
213-
CHECK_LIBRARY_EXISTS("${SECURITY_DIRS}" SSLCreateContext "Security/SecureTransport.h" HAVE_NEWER_SECURITY)
214-
IF (HAVE_NEWER_SECURITY)
215-
MESSAGE("-- Found Security ${SECURITY_DIRS}")
216-
LIST(APPEND LIBGIT2_PC_LIBS "-framework Security")
217-
ELSE()
218-
MESSAGE("-- Security framework is too old, falling back to OpenSSL")
219-
SET(SECURITY_FOUND "NO")
220-
SET(SECURITY_DIRS "")
221-
SET(SECURITY_DIR "")
222-
SET(USE_OPENSSL "ON")
223-
ENDIF()
224-
ENDIF()
225-
226208
IF (COREFOUNDATION_FOUND)
227209
MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}")
228210
LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation")
@@ -280,7 +262,7 @@ ELSE ()
280262
PKG_CHECK_MODULES(CURL libcurl)
281263
ENDIF ()
282264

283-
IF (NOT AMIGA AND USE_OPENSSL)
265+
IF (NOT AMIGA AND (USE_HTTPS STREQUAL "OpenSSL" OR USE_HTTPS STREQUAL "ON"))
284266
FIND_PACKAGE(OpenSSL)
285267
ENDIF ()
286268

@@ -293,6 +275,58 @@ ELSE ()
293275
ENDIF()
294276
ENDIF()
295277

278+
IF (USE_HTTPS STREQUAL "ON")
279+
IF (SECURITY_FOUND)
280+
# OS X 10.7 and older do not have some functions we use, fall back to OpenSSL there
281+
CHECK_LIBRARY_EXISTS("${SECURITY_DIRS}" SSLCreateContext "Security/SecureTransport.h" HAVE_NEWER_SECURITY)
282+
IF (HAVE_NEWER_SECURITY)
283+
MESSAGE("-- Found Security ${SECURITY_DIRS}")
284+
LIST(APPEND LIBGIT2_PC_LIBS "-framework Security")
285+
SET(HTTPS_BACKEND "SecureTransport")
286+
ELSE()
287+
MESSAGE("-- Security framework is too old, falling back to OpenSSL")
288+
SET(SECURITY_FOUND "NO")
289+
SET(SECURITY_DIRS "")
290+
SET(SECURITY_DIR "")
291+
SET(HTTPS_BACKEND "OpenSSL")
292+
ENDIF()
293+
ELSEIF(WINHTTP)
294+
SET(HTTPS_BACKEND "WinHTTP")
295+
ELSE()
296+
SET(HTTPS_BACKEND "OpenSSL")
297+
ENDIF()
298+
ELSE()
299+
SET(HTTPS_BACKEND ${USE_HTTPS})
300+
ENDIF()
301+
302+
MESSAGE(STATUS "Using HTTPS backend ${HTTPS_BACKEND}")
303+
304+
IF (HTTPS_BACKEND STREQUAL "SecureTransport")
305+
IF (NOT SECURITY_FOUND)
306+
MESSAGE(FATAL_ERROR "Asked for SecureTransport HTTPS backend, but it wasn't found")
307+
ENDIF()
308+
309+
ADD_DEFINITIONS(-DGIT_SECURE_TRANSPORT)
310+
INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR})
311+
ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL")
312+
IF (NOT OPENSSL_FOUND)
313+
MESSAGE(FATAL_ERROR "Asked for OpenSSL HTTPS backend, but it wasn't found")
314+
ENDIF()
315+
316+
ADD_DEFINITIONS(-DGIT_OPENSSL)
317+
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
318+
SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
319+
ELSEIF(HTTPS_BACKEND STREQUAL "WinHTTP")
320+
ENDIF()
321+
322+
IF (USE_HTTPS AND NOT HTTPS_BACKEND)
323+
MESSAGE(FATAL_ERROR "Asked for backend " ${HTTPS_BACKEND} " but it wasn't found")
324+
ENDIF()
325+
326+
IF (HTTPS_BACKEND)
327+
ADD_DEFINITIONS(-DGIT_HTTPS)
328+
ENDIF()
329+
296330
# Specify sha1 implementation
297331
IF (USE_SHA1DC)
298332
ADD_DEFINITIONS(-DGIT_SHA1_COLLISIONDETECT)
@@ -303,9 +337,9 @@ IF (USE_SHA1DC)
303337
ELSEIF (WIN32 AND NOT MINGW)
304338
ADD_DEFINITIONS(-DGIT_SHA1_WIN32)
305339
FILE(GLOB SRC_SHA1 src/hash/hash_win32.c)
306-
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
340+
ELSEIF (TLS_BACKEND MATCHES "SecureTransport")
307341
ADD_DEFINITIONS(-DGIT_SHA1_COMMON_CRYPTO)
308-
ELSEIF (OPENSSL_FOUND)
342+
ELSEIF (TLS_BACKEND MATCHES "OpenSSL")
309343
ADD_DEFINITIONS(-DGIT_SHA1_OPENSSL)
310344
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
311345
LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
@@ -543,23 +577,6 @@ ELSE()
543577
# that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE
544578
ENDIF()
545579

546-
IF (SECURITY_FOUND)
547-
ADD_DEFINITIONS(-DGIT_SECURE_TRANSPORT)
548-
INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR})
549-
ENDIF ()
550-
551-
IF (OPENSSL_FOUND)
552-
ADD_DEFINITIONS(-DGIT_OPENSSL)
553-
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
554-
SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
555-
ENDIF()
556-
557-
IF (WINHTTP OR SECURITY_FOUND OR OPENSSL_FOUND)
558-
ADD_DEFINITIONS(-DGIT_HTTPS)
559-
SET(HAS_HTTPS_SUPPORT)
560-
ENDIF()
561-
562-
563580
IF (THREADSAFE)
564581
IF (NOT WIN32)
565582
FIND_PACKAGE(Threads REQUIRED)

0 commit comments

Comments
 (0)