cmake: new LibGit2 module

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-07-10 07:38:20 +03:00
parent f90c94dae7
commit 0f7f80b2cd
2 changed files with 38 additions and 0 deletions

View file

@ -47,6 +47,7 @@ set(cmakeFiles
FindLibUSB.cmake
FindLibVNCServer.cmake
FindLightDM.cmake
FindLibGit2.cmake
FindMPFR.cmake
FindMtp.cmake
FindPCIUTILS.cmake

View file

@ -0,0 +1,37 @@
# Try to find libgit2 library, once done this will define:
#
# LIBGIT2_FOUND - system has libgit2
# LIBGIT2_INCLUDE_DIR - the libgit2 include directory
# LIBGIT2_LIBRARIES - the libraries needed to use libgit2
#
# Copyright (c) 2023 Ivailo Monev <xakepa10@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_LIBGIT2 QUIET libgit2)
set(LIBGIT2_INCLUDE_DIR ${PC_LIBGIT2_INCLUDE_DIRS})
set(LIBGIT2_LIBRARIES ${PC_LIBGIT2_LIBRARIES})
set(LIBGIT2_VERSION ${PC_LIBGIT2_VERSION})
if(NOT LIBGIT2_INCLUDE_DIR OR NOT LIBGIT2_LIBRARIES)
find_path(LIBGIT2_INCLUDE_DIR
NAMES git2.h
HINTS $ENV{LIBGIT2DIR}/include
)
find_library(LIBGIT2_LIBRARIES
NAMES git2
HINTS $ENV{LIBGIT2DIR}/lib
)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibGit2
VERSION_VAR LIBGIT2_VERSION
REQUIRED_VARS LIBGIT2_LIBRARIES LIBGIT2_INCLUDE_DIR
)
mark_as_advanced(LIBGIT2_INCLUDE_DIR LIBGIT2_LIBRARIES)