Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit 07f6d3b

Browse files
committed
CMake: Use system libgit2 if found
This makes it possible to use the GitHub source release as it doesn't contain the submodule. Also avoids unnecessary build of libgit2.
1 parent a7a6eab commit 07f6d3b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
55
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
66

77
# Add libgit2
8-
ADD_SUBDIRECTORY(ext/libgit2 ${CMAKE_BINARY_DIR}/lib)
8+
find_package(PkgConfig)
9+
if(PkgConfig_FOUND)
10+
PKG_CHECK_MODULES(LIBGIT2 libgit2>=0.99)
11+
endif()
12+
if(NOT LIBGIT2_FOUND)
13+
ADD_SUBDIRECTORY(ext/libgit2 ${CMAKE_BINARY_DIR}/lib)
14+
set(LIBGIT2_INCLUDEDIR ext/libgit2/include)
15+
endif()
916

1017
INCLUDE(CMakePackageConfigHelpers)
1118

@@ -20,7 +27,7 @@ SET(CPPGIT2_VERSION_STRING "${CPPGIT2_VERSION_MAJOR}.${CPPGIT2_VERSION_MINOR}.${
2027

2128
# Build object library
2229
ADD_LIBRARY(CPPGIT2_OBJECT_LIBRARY OBJECT ${CPPGIT2_SOURCES})
23-
INCLUDE_DIRECTORIES("include" "ext/libgit2/include" "test")
30+
INCLUDE_DIRECTORIES("include" "${LIBGIT2_INCLUDEDIR}" "test")
2431
SET_PROPERTY(TARGET CPPGIT2_OBJECT_LIBRARY PROPERTY CXX_STANDARD 11)
2532

2633
# Shared libraries need PIC
@@ -42,7 +49,8 @@ TARGET_LINK_LIBRARIES(CPPGIT2_STATIC git2)
4249

4350
# Copy include directories to build/include
4451
FILE(COPY "include" DESTINATION "${CMAKE_BINARY_DIR}/.")
45-
FILE(COPY "ext/libgit2/include" DESTINATION "${CMAKE_BINARY_DIR}/.")
52+
FILE(COPY "${LIBGIT2_INCLUDEDIR}/git2" DESTINATION "${CMAKE_BINARY_DIR}/include")
53+
FILE(COPY "${LIBGIT2_INCLUDEDIR}/git2.h" DESTINATION "${CMAKE_BINARY_DIR}/include")
4654

4755
# Build samples
4856
FILE(GLOB SAMPLES "samples/*.cpp")

0 commit comments

Comments
 (0)