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

Skip to content

Commit 594e27d

Browse files
committed
Add USE_TLS 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 a27f593 commit 594e27d

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

CMakeLists.txt

Lines changed: 57 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_TLS "Enable TLS 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")
@@ -279,7 +261,7 @@ ELSE ()
279261
PKG_CHECK_MODULES(CURL libcurl)
280262
ENDIF ()
281263

282-
IF (NOT AMIGA AND USE_OPENSSL)
264+
IF (NOT AMIGA AND (USE_TLS STREQUAL "OpenSSL" OR USE_TLS STREQUAL "ON"))
283265
FIND_PACKAGE(OpenSSL)
284266
ENDIF ()
285267

@@ -292,16 +274,68 @@ ELSE ()
292274
ENDIF()
293275
ENDIF()
294276

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

547-
IF (SECURITY_FOUND)
548-
ADD_DEFINITIONS(-DGIT_SECURE_TRANSPORT)
549-
INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR})
550-
ENDIF ()
551-
552-
IF (OPENSSL_FOUND)
553-
ADD_DEFINITIONS(-DGIT_OPENSSL)
554-
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
555-
SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
556-
ENDIF()
557-
558-
IF (WINHTTP OR SECURITY_FOUND OR OPENSSL_FOUND)
559-
ADD_DEFINITIONS(-DGIT_TLS)
560-
SET(HAS_TLS_SUPPORT)
561-
ENDIF()
562-
563581

564582
IF (THREADSAFE)
565583
IF (NOT WIN32)
@@ -711,7 +729,7 @@ IF (BUILD_CLAR)
711729
ENDIF ()
712730

713731
ENABLE_TESTING()
714-
IF (HAS_TLS_SUPPORT)
732+
IF (USE_TLS)
715733
ADD_TEST(libgit2_clar libgit2_clar -ionline)
716734
ELSE ()
717735
ADD_TEST(libgit2_clar libgit2_clar -v)

0 commit comments

Comments
 (0)