Skip to content

Commit e3467dd

Browse files
authored
Merge pull request libgit2#6924 from libgit2/ethomson/cmake_deps
Improve dependency selection in CMake
2 parents 533ec83 + 95f47a3 commit e3467dd

File tree

11 files changed

+83
-57
lines changed

11 files changed

+83
-57
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
name: noble
4343
env:
4444
CC: clang
45-
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec
45+
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=exec -DUSE_HTTP_PARSER=http-parser
4646
CMAKE_GENERATOR: Ninja
4747
- name: "Linux (Xenial, GCC, OpenSSL, OpenSSH)"
4848
id: xenial-gcc-openssl

CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ option(USE_THREADS "Use threads for parallel processing when possibl
3030
option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON)
3131

3232
# Backend selection
33-
option(USE_SSH "Enable SSH support. Can be set to a specific backend" OFF)
34-
option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
35-
option(USE_SHA1 "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS" ON)
36-
option(USE_SHA256 "Enable SHA256. Can be set to HTTPS/Builtin" ON)
37-
option(USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF)
38-
set(USE_HTTP_PARSER "" CACHE STRING "Specifies the HTTP Parser implementation; either system or builtin.")
33+
set(USE_SSH "" CACHE STRING "Enables SSH support and optionally selects provider. One of ON, OFF, or a specific provider: libssh2 or exec. (Defaults to OFF.)")
34+
set(USE_HTTPS "" CACHE STRING "Enable HTTPS support and optionally selects the provider. One of ON, OFF, or a specific provider: OpenSSL, OpenSSL-FIPS, OpenSSL-Dynamic, mbedTLS, SecureTransport, Schannel, or WinHTTP. (Defaults to ON.)")
35+
set(USE_SHA1 "" CACHE STRING "Selects SHA1 provider. One of CollisionDetection, HTTPS, or a specific provider. (Defaults to CollisionDetection.)")
36+
set(USE_SHA256 "" CACHE STRING "Selects SHA256 provider. One of Builtin, HTTPS, or a specific provider. (Defaults to HTTPS.)")
37+
option(USE_GSSAPI "Enable SPNEGO authentication using GSSAPI" OFF)
38+
set(USE_HTTP_PARSER "" CACHE STRING "Selects HTTP Parser support: http-parser, llhttp, or builtin. (Defaults to builtin.)")
3939
# set(USE_XDIFF "" CACHE STRING "Specifies the xdiff implementation; either system or builtin.")
40-
set(REGEX_BACKEND "" CACHE STRING "Regular expression implementation. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
40+
set(REGEX_BACKEND "" CACHE STRING "Selects regex provider. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
4141
option(USE_BUNDLED_ZLIB "Use the bundled version of zlib. Can be set to one of Bundled(ON)/Chromium. The Chromium option requires a x86_64 processor with SSE4.2 and CLMUL" OFF)
4242

4343
# Debugging options
@@ -64,7 +64,7 @@ option(ENABLE_WERROR "Enable compilation with -Werror"
6464

6565
if(UNIX)
6666
# NTLM client requires crypto libraries from the system HTTPS stack
67-
if(NOT USE_HTTPS)
67+
if(USE_HTTPS STREQUAL "OFF")
6868
option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF)
6969
else()
7070
option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON)

README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,29 +265,39 @@ Build options:
265265

266266
Dependency options:
267267

268-
* `USE_SSH=type`: enables SSH support; `type` can be set to `libssh2`
269-
or `exec` (which will execute an external OpenSSH command)
270-
* `USE_HTTPS=type`: enables HTTPS support; `type` can be set to
271-
`OpenSSL`, `mbedTLS`, `SecureTransport`, `Schannel`, or `WinHTTP`;
272-
the default is `SecureTransport` on macOS, `WinHTTP` on Windows, and
273-
whichever of `OpenSSL` or `mbedTLS` is detected on other platforms.
268+
* `USE_SSH=type`: enables SSH support and optionally selects the provider;
269+
`type` can be set to `libssh2` or `exec` (which will execute an external
270+
OpenSSH command). `ON` implies `libssh2`; defaults to `OFF`.
271+
* `USE_HTTPS=type`: enables HTTPS support and optionally selects the
272+
provider; `type` can be set to `OpenSSL`, `OpenSSL-Dynamic` (to not
273+
link against OpenSSL, but load it dynamically), `SecureTransport`,
274+
`Schannel` or `WinHTTP`; the default is `SecureTransport` on macOS,
275+
`WinHTTP` on Windows, and whichever of `OpenSSL` or `mbedTLS` is
276+
detected on other platforms. Defaults to `ON`.
274277
* `USE_SHA1=type`: selects the SHA1 mechanism to use; `type` can be set
275-
to `CollisionDetection` (default), or `HTTPS` to use the HTTPS
276-
driver specified above as the hashing provider.
278+
to `CollisionDetection`, `HTTPS` to use the system or HTTPS provider,
279+
or one of `OpenSSL`, `OpenSSL-Dynamic`, `OpenSSL-FIPS` (to use FIPS
280+
compliant routines in OpenSSL), `CommonCrypto`, or `Schannel`.
281+
Defaults to `CollisionDetection`. This option is retained for
282+
backward compatibility and should not be changed.
277283
* `USE_SHA256=type`: selects the SHA256 mechanism to use; `type` can be
278-
set to `HTTPS` (default) to use the HTTPS driver specified above as
279-
the hashing provider, or `Builtin`.
284+
set to `HTTPS` to use the system or HTTPS driver, `builtin`, or one of
285+
`OpenSSL`, `OpenSSL-Dynamic`, `OpenSSL-FIPS` (to use FIPS compliant
286+
routines in OpenSSL), `CommonCrypto`, or `Schannel`. Defaults to `HTTPS`.
280287
* `USE_GSSAPI=<on/off>`: enables GSSAPI for SPNEGO authentication on
281-
Unix
288+
Unix. Defaults to `OFF`.
282289
* `USE_HTTP_PARSER=type`: selects the HTTP Parser; either `http-parser`
283290
for an external
284291
[`http-parser`](https://github.com/nodejs/http-parser) dependency,
285292
`llhttp` for an external [`llhttp`](https://github.com/nodejs/llhttp)
286-
dependency, or `builtin`
293+
dependency, or `builtin`. Defaults to `builtin`.
287294
* `REGEX_BACKEND=type`: selects the regular expression backend to use;
288-
one of `regcomp_l`, `pcre2`, `pcre`, `regcomp`, or `builtin`.
289-
* `USE_BUNDLED_ZLIB=type`: selects the zlib dependency to use; one of
290-
`bundled` or `Chromium`.
295+
one of `regcomp_l`, `pcre2`, `pcre`, `regcomp`, or `builtin`. The
296+
default is to use `regcomp_l` where available, PCRE if found, otherwise,
297+
to use the builtin.
298+
* `USE_BUNDLED_ZLIB=type`: selects the bundled zlib; either `ON` or `OFF`.
299+
Defaults to using the system zlib if available, falling back to the
300+
bundled zlib.
291301

292302
Locating Dependencies
293303
---------------------

ci/docker/noble

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ FROM ${BASE} AS apt
44
RUN apt-get update && \
55
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
66
bzip2 \
7-
clang \
7+
clang \
8+
clang-18 \
89
cmake \
910
curl \
1011
gcc \
1112
git \
1213
krb5-user \
13-
libclang-rt-17-dev \
14+
libclang-rt-18-dev \
1415
libcurl4-gnutls-dev \
1516
libgcrypt20-dev \
17+
libhttp-parser-dev \
1618
libkrb5-dev \
1719
libpcre3-dev \
1820
libssl-dev \
1921
libz-dev \
20-
llvm-17 \
22+
llvm-18 \
2123
make \
2224
ninja-build \
2325
openjdk-8-jre-headless \
@@ -40,10 +42,10 @@ RUN cd /tmp && \
4042
scripts/config.pl set MBEDTLS_MD4_C 1 && \
4143
mkdir build build-msan && \
4244
cd build && \
43-
CC=clang-17 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
45+
CC=clang-18 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
4446
ninja install && \
4547
cd ../build-msan && \
46-
CC=clang-17 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=MemSanDbg -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \
48+
CC=clang-18 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=MemSanDbg -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \
4749
ninja install && \
4850
cd .. && \
4951
rm -rf mbedtls-mbedtls-2.28.6
@@ -54,24 +56,24 @@ RUN cd /tmp && \
5456
cd libssh2-1.11.0 && \
5557
mkdir build build-msan && \
5658
cd build && \
57-
CC=clang-17 CFLAGS="-fPIC" cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
59+
CC=clang-18 CFLAGS="-fPIC" cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
5860
ninja install && \
5961
cd ../build-msan && \
60-
CC=clang-17 CFLAGS="-fPIC -fsanitize=memory -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer" LDFLAGS="-fsanitize=memory" cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCRYPTO_BACKEND=mbedTLS -DCMAKE_PREFIX_PATH=/usr/local/msan -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \
62+
CC=clang-18 CFLAGS="-fPIC -fsanitize=memory -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer" LDFLAGS="-fsanitize=memory" cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCRYPTO_BACKEND=mbedTLS -DCMAKE_PREFIX_PATH=/usr/local/msan -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \
6163
ninja install && \
6264
cd .. && \
6365
rm -rf libssh2-1.11.0
6466

6567
FROM libssh2 AS valgrind
6668
RUN cd /tmp && \
67-
curl --insecure --location --silent --show-error https://sourceware.org/pub/valgrind/valgrind-3.22.0.tar.bz2 | \
69+
curl --insecure --location --silent --show-error https://sourceware.org/pub/valgrind/valgrind-3.23.0.tar.bz2 | \
6870
tar -xj && \
69-
cd valgrind-3.22.0 && \
70-
CC=clang-17 ./configure && \
71+
cd valgrind-3.23.0 && \
72+
CC=clang-18 ./configure && \
7173
make MAKEFLAGS="-j -l$(grep -c ^processor /proc/cpuinfo)" && \
7274
make install && \
7375
cd .. && \
74-
rm -rf valgrind-3.22.0
76+
rm -rf valgrind-3.23.0
7577

7678
FROM valgrind AS adduser
7779
ARG UID=""

ci/docker/xenial

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RUN apt-get update && \
77
clang \
88
cmake \
99
curl \
10-
gettext \
10+
gettext \
1111
gcc \
1212
krb5-user \
1313
libcurl4-gnutls-dev \
14-
libexpat1-dev \
14+
libexpat1-dev \
1515
libgcrypt20-dev \
16-
libintl-perl \
16+
libintl-perl \
1717
libkrb5-dev \
1818
libpcre3-dev \
1919
libssl-dev \

cmake/SelectHTTPParser.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Optional external dependency: http-parser
2-
if(USE_HTTP_PARSER STREQUAL "http-parser")
3-
find_package(HTTPParser)
2+
if(USE_HTTP_PARSER STREQUAL "http-parser" OR USE_HTTP_PARSER STREQUAL "system")
3+
find_package(HTTP_Parser)
44

55
if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
66
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
@@ -23,10 +23,12 @@ elseif(USE_HTTP_PARSER STREQUAL "llhttp")
2323
else()
2424
message(FATAL_ERROR "llhttp support was requested but not found")
2525
endif()
26-
else()
26+
elseif(USE_HTTP_PARSER STREQUAL "" OR USE_HTTP_PARSER STREQUAL "builtin")
2727
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/llhttp" "${PROJECT_BINARY_DIR}/deps/llhttp")
2828
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/llhttp")
2929
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:llhttp>")
3030
set(GIT_HTTPPARSER_BUILTIN 1)
3131
add_feature_info(http-parser ON "using bundled parser")
32+
else()
33+
message(FATAL_ERROR "unknown http-parser: ${USE_HTTP_PARSER}")
3234
endif()

cmake/SelectHTTPSBackend.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "iOS")
88
find_package(CoreFoundation)
99
endif()
1010

11+
if(USE_HTTPS STREQUAL "")
12+
set(USE_HTTPS ON)
13+
endif()
14+
15+
sanitizebool(USE_HTTPS)
16+
1117
if(USE_HTTPS)
1218
# Auto-select TLS backend
13-
sanitizebool(USE_HTTPS)
1419
if(USE_HTTPS STREQUAL ON)
1520
if(SECURITY_FOUND)
1621
if(SECURITY_HAS_SSLCREATECONTEXT)
@@ -136,12 +141,12 @@ if(USE_HTTPS)
136141
set(GIT_OPENSSL_DYNAMIC 1)
137142
list(APPEND LIBGIT2_SYSTEM_LIBS dl)
138143
else()
139-
message(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
144+
message(FATAL_ERROR "unknown HTTPS backend: ${USE_HTTPS}")
140145
endif()
141146

142147
set(GIT_HTTPS 1)
143148
add_feature_info(HTTPS GIT_HTTPS "using ${USE_HTTPS}")
144149
else()
145150
set(GIT_HTTPS 0)
146-
add_feature_info(HTTPS NO "")
151+
add_feature_info(HTTPS NO "HTTPS support is disabled")
147152
endif()

cmake/SelectHashes.cmake

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
include(SanitizeBool)
44

5-
# USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
65
sanitizebool(USE_SHA1)
76
sanitizebool(USE_SHA256)
87

98
# sha1
109

11-
if(USE_SHA1 STREQUAL ON)
10+
if(USE_SHA1 STREQUAL "" OR USE_SHA1 STREQUAL ON)
1211
SET(USE_SHA1 "CollisionDetection")
1312
elseif(USE_SHA1 STREQUAL "HTTPS")
1413
if(USE_HTTPS STREQUAL "SecureTransport")
@@ -20,7 +19,7 @@ elseif(USE_SHA1 STREQUAL "HTTPS")
2019
elseif(USE_HTTPS)
2120
set(USE_SHA1 ${USE_HTTPS})
2221
else()
23-
set(USE_SHA1 "CollisionDetection")
22+
message(FATAL_ERROR "asked for HTTPS SHA1 backend but HTTPS is not enabled")
2423
endif()
2524
endif()
2625

@@ -41,15 +40,21 @@ elseif(USE_SHA1 STREQUAL "mbedTLS")
4140
elseif(USE_SHA1 STREQUAL "Win32")
4241
set(GIT_SHA1_WIN32 1)
4342
else()
44-
message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
43+
message(FATAL_ERROR "asked for unknown SHA1 backend: ${USE_SHA1}")
4544
endif()
4645

4746
# sha256
4847

49-
if(USE_SHA256 STREQUAL ON AND USE_HTTPS)
50-
SET(USE_SHA256 "HTTPS")
51-
elseif(USE_SHA256 STREQUAL ON)
52-
SET(USE_SHA256 "Builtin")
48+
if(USE_SHA256 STREQUAL "" OR USE_SHA256 STREQUAL ON)
49+
if(USE_HTTPS)
50+
SET(USE_SHA256 "HTTPS")
51+
else()
52+
SET(USE_SHA256 "builtin")
53+
endif()
54+
endif()
55+
56+
if(USE_SHA256 STREQUAL "Builtin")
57+
set(USE_SHA256 "builtin")
5358
endif()
5459

5560
if(USE_SHA256 STREQUAL "HTTPS")
@@ -64,7 +69,7 @@ if(USE_SHA256 STREQUAL "HTTPS")
6469
endif()
6570
endif()
6671

67-
if(USE_SHA256 STREQUAL "Builtin")
72+
if(USE_SHA256 STREQUAL "builtin")
6873
set(GIT_SHA256_BUILTIN 1)
6974
elseif(USE_SHA256 STREQUAL "OpenSSL")
7075
set(GIT_SHA256_OPENSSL 1)
@@ -81,7 +86,7 @@ elseif(USE_SHA256 STREQUAL "mbedTLS")
8186
elseif(USE_SHA256 STREQUAL "Win32")
8287
set(GIT_SHA256_WIN32 1)
8388
else()
84-
message(FATAL_ERROR "Asked for unknown SHA256 backend: ${USE_SHA256}")
89+
message(FATAL_ERROR "asked for unknown SHA256 backend: ${USE_SHA256}")
8590
endif()
8691

8792
# add library requirements

cmake/SelectSSH.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ elseif(USE_SSH STREQUAL ON OR USE_SSH STREQUAL "libssh2")
3939
set(GIT_SSH 1)
4040
set(GIT_SSH_LIBSSH2 1)
4141
add_feature_info(SSH ON "using libssh2")
42-
else()
42+
elseif(USE_SSH STREQUAL OFF OR USE_SSH STREQUAL "")
4343
add_feature_info(SSH OFF "SSH transport support")
44+
else()
45+
message(FATAL_ERROR "unknown SSH option: ${USE_HTTP_PARSER}")
4446
endif()

0 commit comments

Comments
 (0)