Unverified Commit e1299171 by Patrick Steinhardt Committed by GitHub

Merge pull request #5440 from pks-t/pks/cmake-streamlining

CMake: backend selection streamlining
parents b8eec0b2 541de515
# Select the backend to use
# We try to find any packages our backends might use
INCLUDE(SanitizeBool) INCLUDE(SanitizeBool)
# We try to find any packages our backends might use
FIND_PACKAGE(GSSAPI) FIND_PACKAGE(GSSAPI)
IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
INCLUDE(FindGSSFramework) INCLUDE(FindGSSFramework)
ENDIF() ENDIF()
# Auto-select GSS backend IF(USE_GSSAPI)
SanitizeBool(USE_GSSAPI) # Auto-select GSS backend
IF (USE_GSSAPI STREQUAL ON) SanitizeBool(USE_GSSAPI)
IF (USE_GSSAPI STREQUAL ON)
IF (GSSFRAMEWORK_FOUND) IF (GSSFRAMEWORK_FOUND)
SET(GSS_BACKEND "GSS.framework") SET(USE_GSSAPI "GSS.framework")
ELSEIF(GSSAPI_FOUND) ELSEIF(GSSAPI_FOUND)
SET(GSS_BACKEND "gssapi") SET(USE_GSSAPI "gssapi")
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Unable to autodetect a usable GSS backend." MESSAGE(FATAL_ERROR "Unable to autodetect a usable GSS backend."
"Please pass the backend name explicitly (-DUSE_GSS=backend)") "Please pass the backend name explicitly (-DUSE_GSS=backend)")
ENDIF() ENDIF()
ELSEIF(USE_GSSAPI) ENDIF()
# Backend was explicitly set
SET(GSS_BACKEND ${USE_GSSAPI})
ELSE()
SET(GSS_BACKEND NO)
ENDIF()
IF(GSS_BACKEND)
# Check that we can find what's required for the selected backend # Check that we can find what's required for the selected backend
IF (GSS_BACKEND STREQUAL "GSS.framework") IF (USE_GSSAPI STREQUAL "GSS.framework")
IF (NOT GSSFRAMEWORK_FOUND) IF (NOT GSSFRAMEWORK_FOUND)
MESSAGE(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found") MESSAGE(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found")
ENDIF() ENDIF()
...@@ -37,8 +29,8 @@ IF(GSS_BACKEND) ...@@ -37,8 +29,8 @@ IF(GSS_BACKEND)
LIST(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES}) LIST(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES})
SET(GIT_GSSFRAMEWORK 1) SET(GIT_GSSFRAMEWORK 1)
ADD_FEATURE_INFO(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${GSS_BACKEND})") ADD_FEATURE_INFO(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})")
ELSEIF (GSS_BACKEND STREQUAL "gssapi") ELSEIF (USE_GSSAPI STREQUAL "gssapi")
IF (NOT GSSAPI_FOUND) IF (NOT GSSAPI_FOUND)
MESSAGE(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found") MESSAGE(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found")
ENDIF() ENDIF()
...@@ -46,9 +38,9 @@ IF(GSS_BACKEND) ...@@ -46,9 +38,9 @@ IF(GSS_BACKEND)
LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES}) LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES})
SET(GIT_GSSAPI 1) SET(GIT_GSSAPI 1)
ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${GSS_BACKEND})") ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})")
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Asked for backend ${GSS_BACKEND} but it wasn't found") MESSAGE(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found")
ENDIF() ENDIF()
ELSE() ELSE()
SET(GIT_GSSAPI 0) SET(GIT_GSSAPI 0)
......
# Select the backend to use
INCLUDE(SanitizeBool) INCLUDE(SanitizeBool)
# We try to find any packages our backends might use # We try to find any packages our backends might use
...@@ -10,36 +8,31 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") ...@@ -10,36 +8,31 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
FIND_PACKAGE(CoreFoundation) FIND_PACKAGE(CoreFoundation)
ENDIF() ENDIF()
# Auto-select TLS backend IF(USE_HTTPS)
SanitizeBool(USE_HTTPS) # Auto-select TLS backend
IF (USE_HTTPS STREQUAL ON) SanitizeBool(USE_HTTPS)
IF (USE_HTTPS STREQUAL ON)
IF (SECURITY_FOUND) IF (SECURITY_FOUND)
IF (SECURITY_HAS_SSLCREATECONTEXT) IF (SECURITY_HAS_SSLCREATECONTEXT)
SET(HTTPS_BACKEND "SecureTransport") SET(USE_HTTPS "SecureTransport")
ELSE() ELSE()
MESSAGE(STATUS "Security framework is too old, falling back to OpenSSL") MESSAGE(STATUS "Security framework is too old, falling back to OpenSSL")
SET(HTTPS_BACKEND "OpenSSL") SET(USE_HTTPS "OpenSSL")
ENDIF() ENDIF()
ELSEIF (WINHTTP) ELSEIF (WINHTTP)
SET(HTTPS_BACKEND "WinHTTP") SET(USE_HTTPS "WinHTTP")
ELSEIF(OPENSSL_FOUND) ELSEIF(OPENSSL_FOUND)
SET(HTTPS_BACKEND "OpenSSL") SET(USE_HTTPS "OpenSSL")
ELSEIF(MBEDTLS_FOUND) ELSEIF(MBEDTLS_FOUND)
SET(HTTPS_BACKEND "mbedTLS") SET(USE_HTTPS "mbedTLS")
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Unable to autodetect a usable HTTPS backend." MESSAGE(FATAL_ERROR "Unable to autodetect a usable HTTPS backend."
"Please pass the backend name explicitly (-DUSE_HTTPS=backend)") "Please pass the backend name explicitly (-DUSE_HTTPS=backend)")
ENDIF() ENDIF()
ELSEIF(USE_HTTPS) ENDIF()
# HTTPS backend was explicitly set
SET(HTTPS_BACKEND ${USE_HTTPS})
ELSE()
SET(HTTPS_BACKEND NO)
ENDIF()
IF(HTTPS_BACKEND)
# Check that we can find what's required for the selected backend # Check that we can find what's required for the selected backend
IF (HTTPS_BACKEND STREQUAL "SecureTransport") IF (USE_HTTPS STREQUAL "SecureTransport")
IF (NOT COREFOUNDATION_FOUND) IF (NOT COREFOUNDATION_FOUND)
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found") MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found")
ENDIF() ENDIF()
...@@ -54,7 +47,7 @@ IF(HTTPS_BACKEND) ...@@ -54,7 +47,7 @@ IF(HTTPS_BACKEND)
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR}) LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR})
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL") ELSEIF (USE_HTTPS STREQUAL "OpenSSL")
IF (NOT OPENSSL_FOUND) IF (NOT OPENSSL_FOUND)
MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found") MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
ENDIF() ENDIF()
...@@ -64,7 +57,7 @@ IF(HTTPS_BACKEND) ...@@ -64,7 +57,7 @@ IF(HTTPS_BACKEND)
LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES}) LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
ELSEIF(HTTPS_BACKEND STREQUAL "mbedTLS") ELSEIF(USE_HTTPS STREQUAL "mbedTLS")
IF (NOT MBEDTLS_FOUND) IF (NOT MBEDTLS_FOUND)
MESSAGE(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found") MESSAGE(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found")
ENDIF() ENDIF()
...@@ -113,14 +106,14 @@ IF(HTTPS_BACKEND) ...@@ -113,14 +106,14 @@ IF(HTTPS_BACKEND)
# https://github.com/ARMmbed/mbedtls/issues/228 # https://github.com/ARMmbed/mbedtls/issues/228
# For now, pass its link flags as our own # For now, pass its link flags as our own
LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
ELSEIF (HTTPS_BACKEND STREQUAL "WinHTTP") ELSEIF (USE_HTTPS STREQUAL "WinHTTP")
# WinHTTP setup was handled in the WinHTTP-specific block above # WinHTTP setup was handled in the WinHTTP-specific block above
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Asked for backend ${HTTPS_BACKEND} but it wasn't found") MESSAGE(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
ENDIF() ENDIF()
SET(GIT_HTTPS 1) SET(GIT_HTTPS 1)
ADD_FEATURE_INFO(HTTPS GIT_HTTPS "using ${HTTPS_BACKEND}") ADD_FEATURE_INFO(HTTPS GIT_HTTPS "using ${USE_HTTPS}")
ELSE() ELSE()
SET(GIT_HTTPS 0) SET(GIT_HTTPS 0)
ADD_FEATURE_INFO(HTTPS NO "") ADD_FEATURE_INFO(HTTPS NO "")
......
...@@ -5,37 +5,28 @@ INCLUDE(SanitizeBool) ...@@ -5,37 +5,28 @@ INCLUDE(SanitizeBool)
# USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF # USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
SanitizeBool(USE_SHA1) SanitizeBool(USE_SHA1)
IF(USE_SHA1 STREQUAL ON OR USE_SHA1 STREQUAL "CollisionDetection") IF(USE_SHA1 STREQUAL ON)
SET(SHA1_BACKEND "CollisionDetection") SET(USE_SHA1 "CollisionDetection")
ELSEIF(USE_SHA1 STREQUAL "HTTPS") ELSEIF(USE_SHA1 STREQUAL "HTTPS")
message(STATUS "Checking HTTPS backend… ${HTTPS_BACKEND}") IF(USE_HTTPS STREQUAL "SecureTransport")
IF(HTTPS_BACKEND STREQUAL "SecureTransport") SET(USE_SHA1 "CommonCrypto")
SET(SHA1_BACKEND "CommonCrypto") ELSEIF(USE_HTTPS STREQUAL "WinHTTP")
ELSEIF(HTTPS_BACKEND STREQUAL "WinHTTP") SET(USE_SHA1 "Win32")
SET(SHA1_BACKEND "Win32") ELSEIF(USE_HTTPS)
ELSEIF(HTTPS_BACKEND) SET(USE_SHA1 ${USE_HTTPS})
SET(SHA1_BACKEND ${HTTPS_BACKEND})
ELSE() ELSE()
SET(USE_SHA1 "CollisionDetection")
ENDIF() ENDIF()
IF(NOT HTTPS_BACKEND)
SET(SHA1_BACKEND "CollisionDetection")
ENDIF()
message(STATUS "Using SHA1 backend ${SHA1_BACKEND}")
ELSEIF(USE_SHA1 STREQUAL "Generic")
SET(SHA1_BACKEND "Generic")
# ELSEIF(NOT USE_SHA1)
ELSE()
MESSAGE(FATAL_ERROR "Invalid value for USE_SHA1: ${USE_SHA1}")
ENDIF() ENDIF()
IF(SHA1_BACKEND STREQUAL "CollisionDetection") IF(USE_SHA1 STREQUAL "CollisionDetection")
SET(GIT_SHA1_COLLISIONDETECT 1) SET(GIT_SHA1_COLLISIONDETECT 1)
ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1) ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\") ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\") ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*) FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL") ELSEIF(USE_SHA1 STREQUAL "OpenSSL")
# OPENSSL_FOUND should already be set, we're checking HTTPS_BACKEND # OPENSSL_FOUND should already be set, we're checking USE_HTTPS
SET(GIT_SHA1_OPENSSL 1) SET(GIT_SHA1_OPENSSL 1)
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
...@@ -44,10 +35,10 @@ ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL") ...@@ -44,10 +35,10 @@ ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL")
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
ENDIF() ENDIF()
FILE(GLOB SRC_SHA1 hash/sha1/openssl.*) FILE(GLOB SRC_SHA1 hash/sha1/openssl.*)
ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto") ELSEIF(USE_SHA1 STREQUAL "CommonCrypto")
SET(GIT_SHA1_COMMON_CRYPTO 1) SET(GIT_SHA1_COMMON_CRYPTO 1)
FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*) FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*)
ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS") ELSEIF(USE_SHA1 STREQUAL "mbedTLS")
SET(GIT_SHA1_MBEDTLS 1) SET(GIT_SHA1_MBEDTLS 1)
FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*) FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
...@@ -56,14 +47,13 @@ ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS") ...@@ -56,14 +47,13 @@ ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS")
# https://github.com/ARMmbed/mbedtls/issues/228 # https://github.com/ARMmbed/mbedtls/issues/228
# For now, pass its link flags as our own # For now, pass its link flags as our own
LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
ELSEIF(SHA1_BACKEND STREQUAL "Win32") ELSEIF(USE_SHA1 STREQUAL "Win32")
SET(GIT_SHA1_WIN32 1) SET(GIT_SHA1_WIN32 1)
FILE(GLOB SRC_SHA1 hash/sha1/win32.*) FILE(GLOB SRC_SHA1 hash/sha1/win32.*)
ELSEIF(SHA1_BACKEND STREQUAL "Generic") ELSEIF(USE_SHA1 STREQUAL "Generic")
FILE(GLOB SRC_SHA1 hash/sha1/generic.*) FILE(GLOB SRC_SHA1 hash/sha1/generic.*)
# ELSEIF(NOT USE_SHA1)
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${SHA1_BACKEND}") MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
ENDIF() ENDIF()
ADD_FEATURE_INFO(SHA ON "using ${SHA1_BACKEND}") ADD_FEATURE_INFO(SHA ON "using ${USE_SHA1}")
...@@ -4,20 +4,20 @@ ADD_DEFINITIONS(-DNTLM_STATIC=1) ...@@ -4,20 +4,20 @@ ADD_DEFINITIONS(-DNTLM_STATIC=1)
DISABLE_WARNINGS(implicit-fallthrough) DISABLE_WARNINGS(implicit-fallthrough)
IF (HTTPS_BACKEND STREQUAL "SecureTransport") IF(USE_HTTPS STREQUAL "SecureTransport")
ADD_DEFINITIONS(-DCRYPT_COMMONCRYPTO) ADD_DEFINITIONS(-DCRYPT_COMMONCRYPTO)
SET(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c") SET(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c")
# CC_MD4 has been deprecated in macOS 10.15. # CC_MD4 has been deprecated in macOS 10.15.
SET_SOURCE_FILES_PROPERTIES("crypt_commoncrypto.c" COMPILE_FLAGS "-Wno-deprecated") SET_SOURCE_FILES_PROPERTIES("crypt_commoncrypto.c" COMPILE_FLAGS "-Wno-deprecated")
ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL") ELSEIF(USE_HTTPS STREQUAL "OpenSSL")
ADD_DEFINITIONS(-DCRYPT_OPENSSL) ADD_DEFINITIONS(-DCRYPT_OPENSSL)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c") SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c")
ELSEIF (HTTPS_BACKEND STREQUAL "mbedTLS") ELSEIF(USE_HTTPS STREQUAL "mbedTLS")
ADD_DEFINITIONS(-DCRYPT_MBEDTLS) ADD_DEFINITIONS(-DCRYPT_MBEDTLS)
SET(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c") SET(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c")
ELSE () ELSE()
MESSAGE(FATAL_ERROR "Unable to use libgit2's HTTPS backend (${HTTPS_BACKEND}) for NTLM crypto") MESSAGE(FATAL_ERROR "Unable to use libgit2's HTTPS backend (${USE_HTTPS}) for NTLM crypto")
ENDIF() ENDIF()
ADD_LIBRARY(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_CRYPTO}) ADD_LIBRARY(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_CRYPTO})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment