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

CMake: Use system libgit2 if found #3

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Add libgit2
ADD_SUBDIRECTORY(ext/libgit2 ${CMAKE_BINARY_DIR}/lib)
find_package(PkgConfig)
if(PkgConfig_FOUND)
PKG_CHECK_MODULES(LIBGIT2 libgit2>=0.99)
endif()
if(NOT LIBGIT2_FOUND)
ADD_SUBDIRECTORY(ext/libgit2 ${CMAKE_BINARY_DIR}/lib)
set(LIBGIT2_INCLUDEDIR ext/libgit2/include)
endif()

INCLUDE(CMakePackageConfigHelpers)

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

# Build object library
ADD_LIBRARY(CPPGIT2_OBJECT_LIBRARY OBJECT ${CPPGIT2_SOURCES})
INCLUDE_DIRECTORIES("include" "ext/libgit2/include" "test")
INCLUDE_DIRECTORIES("include" "${LIBGIT2_INCLUDEDIR}" "test")
SET_PROPERTY(TARGET CPPGIT2_OBJECT_LIBRARY PROPERTY CXX_STANDARD 11)

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

# Copy include directories to build/include
FILE(COPY "include" DESTINATION "${CMAKE_BINARY_DIR}/.")
FILE(COPY "ext/libgit2/include" DESTINATION "${CMAKE_BINARY_DIR}/.")
FILE(COPY "${LIBGIT2_INCLUDEDIR}/git2" DESTINATION "${CMAKE_BINARY_DIR}/include")
FILE(COPY "${LIBGIT2_INCLUDEDIR}/git2.h" DESTINATION "${CMAKE_BINARY_DIR}/include")

# Build samples
FILE(GLOB SAMPLES "samples/*.cpp")
Expand Down