cmake: allow explicitly choosing SHA1 backend Right now, if SHA1DC is disabled, the SHA1 backend is mostly chosen based on which system libgit2 is being compiled on and which libraries have been found. To give developers and distributions more choice, enable them to request specific backends by passing in a `-DSHA1_BACKEND=<BACKEND>` option instead. This completely replaces the previous auto-selection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32f8ac0..48a4d91 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,7 +42,7 @@ OPTION( PROFILE "Generate profiling information" OFF )
OPTION( ENABLE_TRACE "Enables tracing support" OFF )
OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
-OPTION( USE_SHA1DC "Use SHA-1 with collision detection" ON )
+SET(SHA1_BACKEND "CollisionDetection" CACHE STRING "Backend to use for SHA1. One of Generic, OpenSSL, Win32, CommonCrypto, CollisionDetection. ")
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
OPTION( USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON )
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2c82d1f..76bd6ce 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -127,10 +127,6 @@ ELSE ()
PKG_CHECK_MODULES(CURL libcurl)
ENDIF ()
- IF (NOT AMIGA AND (USE_HTTPS STREQUAL "OpenSSL" OR USE_HTTPS STREQUAL "ON"))
- FIND_PACKAGE(OpenSSL QUIET)
- ENDIF ()
-
IF (CURL_FOUND)
SET(GIT_CURL 1)
LIST(APPEND LIBGIT2_INCLUDES ${CURL_INCLUDE_DIRS})
@@ -183,6 +179,8 @@ IF (USE_HTTPS)
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LIBRARIES} ${SECURITY_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL")
+ FIND_PACKAGE(OpenSSL)
+
IF (NOT OPENSSL_FOUND)
MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
ENDIF()
@@ -204,34 +202,42 @@ ELSE()
ENDIF()
# Specify sha1 implementation
-IF (USE_SHA1DC)
- ADD_FEATURE_INFO(SHA ON "using SHA1DC")
+IF(SHA1_BACKEND STREQUAL "OpenSSL")
+ IF(NOT OPENSSL_FOUND)
+ FIND_PACKAGE(OpenSSL)
+ IF(NOT OPENSSL_FOUND)
+ MESSAGE(FATAL_ERROR "Requested OpenSSL SHA1 backend, but OpenSSL could not be found")
+ ENDIF()
+ ENDIF()
+
+ ADD_FEATURE_INFO(SHA ON "using OpenSSL")
+ SET(GIT_SHA1_OPENSSL 1)
+ IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
+ ELSE()
+ SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
+ ENDIF()
+ELSEIF(SHA1_BACKEND STREQUAL "CollisionDetection")
+ ADD_FEATURE_INFO(SHA ON "using CollisionDetection")
SET(GIT_SHA1_COLLISIONDETECT 1)
ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
FILE(GLOB SRC_SHA1 hash/hash_collisiondetect.c hash/sha1dc/*)
-ELSEIF (WIN32 AND NOT MINGW)
- ADD_FEATURE_INFO(SHA ON "using SHA1_WIN32")
+ELSEIF(SHA1_BACKEND STREQUAL "Generic")
+ ADD_FEATURE_INFO(SHA ON "using Generic")
+ FILE(GLOB SRC_SHA1 hash/hash_generic.c)
+ELSEIF(SHA1_BACKEND STREQUAL "Win32")
+ ADD_FEATURE_INFO(SHA ON "using Win32")
SET(GIT_SHA1_WIN32 1)
FILE(GLOB SRC_SHA1 hash/hash_win32.c)
-ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto")
ADD_FEATURE_INFO(SHA ON "using CommonCrypto")
SET(GIT_SHA1_COMMON_CRYPTO 1)
-ELSEIF (OPENSSL_FOUND)
- ADD_FEATURE_INFO(SHA ON "using OpenSSL")
- SET(GIT_SHA1_OPENSSL 1)
- IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
- LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
- ELSE()
- SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
- ENDIF ()
ELSE()
- ADD_FEATURE_INFO(SHA ON "using generic")
- FILE(GLOB SRC_SHA1 hash/hash_generic.c)
+ MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend ${SHA1_BACKEND}")
ENDIF()
-
# Include POSIX regex when it is required
IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/regex" "${libgit2_BINARY_DIR}/deps/regex")