| 1 |
include(SanitizeBool) |
| 2 |
|
| 3 |
# We try to find any packages our backends might use |
| 4 |
find_package(OpenSSL) |
| 5 |
find_package(mbedTLS) |
| 6 |
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "iOS") |
| 7 |
find_package(Security) |
| 8 |
find_package(CoreFoundation) |
| 9 |
endif() |
| 10 |
|
| 11 |
if(USE_HTTPS STREQUAL "") |
| 12 |
set(USE_HTTPS ON) |
| 13 |
endif() |
| 14 |
|
| 15 |
sanitizebool(USE_HTTPS) |
| 16 |
|
| 17 |
if(USE_HTTPS) |
| 18 |
# Auto-select TLS backend |
| 19 |
if(USE_HTTPS STREQUAL ON) |
| 20 |
if(SECURITY_FOUND) |
| 21 |
if(SECURITY_HAS_SSLCREATECONTEXT) |
| 22 |
set(USE_HTTPS "SecureTransport") |
| 23 |
else() |
| 24 |
message(STATUS "Security framework is too old, falling back to OpenSSL") |
| 25 |
set(USE_HTTPS "OpenSSL") |
| 26 |
endif() |
| 27 |
elseif(WIN32) |
| 28 |
set(USE_HTTPS "WinHTTP") |
| 29 |
elseif(OPENSSL_FOUND) |
| 30 |
set(USE_HTTPS "OpenSSL") |
| 31 |
elseif(MBEDTLS_FOUND) |
| 32 |
set(USE_HTTPS "mbedTLS") |
| 33 |
else() |
| 34 |
message(FATAL_ERROR "Unable to autodetect a usable HTTPS backend." |
| 35 |
"Please pass the backend name explicitly (-DUSE_HTTPS=backend)") |
| 36 |
endif() |
| 37 |
endif() |
| 38 |
|
| 39 |
# Check that we can find what's required for the selected backend |
| 40 |
if(USE_HTTPS STREQUAL "SecureTransport") |
| 41 |
if(NOT COREFOUNDATION_FOUND) |
| 42 |
message(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found") |
| 43 |
endif() |
| 44 |
if(NOT SECURITY_FOUND) |
| 45 |
message(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found") |
| 46 |
endif() |
| 47 |
if(NOT SECURITY_HAS_SSLCREATECONTEXT) |
| 48 |
message(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported") |
| 49 |
endif() |
| 50 |
|
| 51 |
set(GIT_SECURE_TRANSPORT 1) |
| 52 |
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR}) |
| 53 |
list(APPEND LIBGIT2_SYSTEM_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) |
| 54 |
list(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) |
| 55 |
elseif(USE_HTTPS STREQUAL "OpenSSL") |
| 56 |
if(NOT OPENSSL_FOUND) |
| 57 |
message(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found") |
| 58 |
endif() |
| 59 |
|
| 60 |
set(GIT_OPENSSL 1) |
| 61 |
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR}) |
| 62 |
list(APPEND LIBGIT2_SYSTEM_LIBS ${OPENSSL_LIBRARIES}) |
| 63 |
# Static OpenSSL (lib crypto.a) requires libdl, include it explicitly |
| 64 |
if(LINK_WITH_STATIC_LIBRARIES STREQUAL ON) |
| 65 |
list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_DL_LIBS}) |
| 66 |
endif() |
| 67 |
list(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) |
| 68 |
list(APPEND LIBGIT2_PC_REQUIRES "openssl") |
| 69 |
elseif(USE_HTTPS STREQUAL "mbedTLS") |
| 70 |
if(NOT MBEDTLS_FOUND) |
| 71 |
message(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found") |
| 72 |
endif() |
| 73 |
|
| 74 |
if(NOT CERT_LOCATION) |
| 75 |
message(STATUS "Auto-detecting default certificates location") |
| 76 |
if(EXISTS "/usr/local/opt/openssl/bin/openssl") |
| 77 |
# Check for an Homebrew installation |
| 78 |
set(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl") |
| 79 |
else() |
| 80 |
set(OPENSSL_CMD "openssl") |
| 81 |
endif() |
| 82 |
execute_process(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 83 |
if(OPENSSL_DIR) |
| 84 |
string(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR}) |
| 85 |
|
| 86 |
set(OPENSSL_CA_LOCATIONS |
| 87 |
"ca-bundle.pem" # OpenSUSE Leap 42.1 |
| 88 |
"cert.pem" # Ubuntu 14.04, FreeBSD |
| 89 |
"certs/ca-certificates.crt" # Ubuntu 16.04 |
| 90 |
"certs/ca.pem" # Debian 7 |
| 91 |
) |
| 92 |
foreach(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS) |
| 93 |
set(LOC "${OPENSSL_DIR}${SUFFIX}") |
| 94 |
if(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}") |
| 95 |
set(CERT_LOCATION ${LOC}) |
| 96 |
endif() |
| 97 |
endforeach() |
| 98 |
else() |
| 99 |
message(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION") |
| 100 |
endif() |
| 101 |
endif() |
| 102 |
|
| 103 |
if(CERT_LOCATION) |
| 104 |
if(NOT EXISTS ${CERT_LOCATION}) |
| 105 |
message(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist") |
| 106 |
endif() |
| 107 |
add_feature_info(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}") |
| 108 |
add_definitions(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}") |
| 109 |
endif() |
| 110 |
|
| 111 |
set(GIT_MBEDTLS 1) |
| 112 |
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) |
| 113 |
list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES}) |
| 114 |
# mbedTLS has no pkgconfig file, hence we can't require it |
| 115 |
# https://github.com/ARMmbed/mbedtls/issues/228 |
| 116 |
# For now, pass its link flags as our own |
| 117 |
list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) |
| 118 |
elseif(USE_HTTPS STREQUAL "Schannel") |
| 119 |
set(GIT_SCHANNEL 1) |
| 120 |
|
| 121 |
list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32") |
| 122 |
list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") |
| 123 |
elseif(USE_HTTPS STREQUAL "WinHTTP") |
| 124 |
set(GIT_WINHTTP 1) |
| 125 |
|
| 126 |
# Since MinGW does not come with headers or an import library for winhttp, |
| 127 |
# we have to include a private header and generate our own import library |
| 128 |
if(MINGW) |
| 129 |
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/winhttp" "${PROJECT_BINARY_DIR}/deps/winhttp") |
| 130 |
list(APPEND LIBGIT2_SYSTEM_LIBS winhttp) |
| 131 |
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/winhttp") |
| 132 |
else() |
| 133 |
list(APPEND LIBGIT2_SYSTEM_LIBS "winhttp") |
| 134 |
list(APPEND LIBGIT2_PC_LIBS "-lwinhttp") |
| 135 |
endif() |
| 136 |
|
| 137 |
list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32") |
| 138 |
list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") |
| 139 |
elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic") |
| 140 |
set(GIT_OPENSSL 1) |
| 141 |
set(GIT_OPENSSL_DYNAMIC 1) |
| 142 |
list(APPEND LIBGIT2_SYSTEM_LIBS dl) |
| 143 |
else() |
| 144 |
message(FATAL_ERROR "unknown HTTPS backend: ${USE_HTTPS}") |
| 145 |
endif() |
| 146 |
|
| 147 |
set(GIT_HTTPS 1) |
| 148 |
add_feature_info(HTTPS GIT_HTTPS "using ${USE_HTTPS}") |
| 149 |
else() |
| 150 |
set(GIT_HTTPS 0) |
| 151 |
add_feature_info(HTTPS NO "HTTPS support is disabled") |
| 152 |
endif() |