Commit | Line | Data |
---|---|---|
9ea9e97b MC |
1 | From de3c48d72ec7064e7f0522877fe759c729df0c50 Mon Sep 17 00:00:00 2001 |
2 | From: Maxim Cournoyer <maxim.cournoyer@gmail.com> | |
3 | Date: Wed, 25 Mar 2020 11:32:18 -0400 | |
4 | Subject: [PATCH] Allow using a system provided libgit2 library | |
5 | ||
6 | Setting the USE_SYSTEM_LIBGIT2 Make or CMake variable (through the | |
7 | BUILD_OPTIONS variable) to any value enables using the system library. | |
8 | The default behavior of using a bundled copy of libgit2 is unchanged. | |
9 | --- | |
10 | CMakeLists.txt | 9 +++++++-- | |
11 | Makefile | 11 +++++++++++ | |
12 | src/CMakeLists.txt | 9 +++++++-- | |
13 | 3 files changed, 25 insertions(+), 4 deletions(-) | |
14 | ||
15 | diff --git a/CMakeLists.txt b/CMakeLists.txt | |
16 | index a393d7c..75d6ca6 100644 | |
17 | --- a/CMakeLists.txt | |
18 | +++ b/CMakeLists.txt | |
19 | @@ -7,9 +7,14 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "shared" FORCE) | |
20 | set(BUILD_CLAR OFF CACHE BOOL "clar" FORCE) | |
21 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DEGIT_DEBUG") | |
22 | ||
23 | -add_subdirectory(libgit2) | |
24 | +if(USE_SYSTEM_LIBGIT2) | |
25 | + find_package(PkgConfig REQUIRED) | |
26 | + pkg_check_modules(git2 REQUIRED IMPORTED_TARGET libgit2) | |
27 | +else() | |
28 | + add_subdirectory(libgit2) | |
29 | + find_library(git2 libgit2.a) | |
30 | +endif() | |
31 | ||
32 | -find_library(git2 libgit2.a) | |
33 | add_subdirectory(src) | |
34 | ||
35 | enable_testing() | |
36 | diff --git a/Makefile b/Makefile | |
37 | index 8199532..6a6a4e1 100644 | |
38 | --- a/Makefile | |
39 | +++ b/Makefile | |
40 | @@ -13,6 +13,13 @@ ifeq ($(UNAME),MSYS) | |
41 | BUILD_OPTIONS+= -G "MSYS Makefiles" | |
42 | endif | |
43 | ||
44 | +# If the variable USE_SYSTEM_LIBGIT2 is set to *any* value, use the | |
45 | +# system provided libgit2 library. | |
46 | +USE_SYSTEM_LIBGIT2? := \ | |
47 | + $(if $(or $(USE_SYSTEM_LIBGIT2),\ | |
48 | + $(findstring USE_SYSTEM_LIBGIT2,$(BUILD_OPTIONS))),\ | |
49 | + true) | |
50 | + | |
51 | ifeq "$(TRAVIS)" "true" | |
52 | ## Makefile for Travis ################################################### | |
53 | # | |
54 | @@ -87,7 +94,11 @@ submodule-update: | |
55 | @git submodule update | |
56 | ||
57 | libgit2: | |
58 | +ifeq ($(USE_SYSTEM_LIBGIT2?),) | |
59 | @git submodule update --init | |
60 | +else | |
61 | + @echo "Using the system provided libgit2 library" | |
62 | +endif | |
63 | ||
64 | CLEAN = $(ELCS) $(PKG)-autoloads.el build | |
65 | ||
66 | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt | |
67 | index cfb5777..0dbad8a 100644 | |
68 | --- a/src/CMakeLists.txt | |
69 | +++ b/src/CMakeLists.txt | |
70 | @@ -13,8 +13,13 @@ if(WIN32) | |
71 | set_target_properties(egit2 PROPERTIES PREFIX lib) | |
72 | endif(WIN32) | |
73 | ||
74 | -target_link_libraries(egit2 git2) | |
75 | -target_include_directories(egit2 SYSTEM PRIVATE "${libgit2_SOURCE_DIR}/include") | |
76 | +if(USE_SYSTEM_LIBGIT2) | |
77 | + target_link_libraries(egit2 PRIVATE PkgConfig::git2) | |
78 | +else() | |
79 | + target_link_libraries(egit2 git2) | |
80 | + target_include_directories( | |
81 | + egit2 SYSTEM PRIVATE "${libgit2_SOURCE_DIR}/include") | |
82 | +endif() | |
83 | ||
84 | if(CMAKE_COMPILER_IS_GNUCC) | |
85 | target_compile_options(egit2 PRIVATE -Wall -Wextra) | |
86 | -- | |
87 | 2.26.2 | |
88 |