Warning, /frameworks/extra-cmake-modules/find-modules/FindLibGit2.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org>
0002 # SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003 # SPDX-FileCopyrightText: 2014 Christoph Cullmann <cullmann@kde.org>
0004 # SPDX-FileCopyrightText: 2023 Louis Moureaux <m_louis30@yahoo.com>
0005 #
0006 # SPDX-License-Identifier: BSD-3-Clause
0007
0008 #[=======================================================================[.rst:
0009 FindLibGit2
0010 -----------
0011
0012 Try to find libgit2 on a Unix system.
0013
0014 This will define the following variables:
0015
0016 ``LIBGIT2_FOUND``
0017 True if (the requested version of) libgit2 is available
0018 ``LIBGIT2_VERSION``
0019 The version of libgit2
0020 ``LIBGIT2_LIBRARIES``
0021 This can be passed to target_link_libraries() instead of the ``LibGit2::LibGit2``
0022 target
0023 ``LIBGIT2_INCLUDE_DIRS``
0024 This should be passed to target_include_directories() if the target is not
0025 used for linking
0026 ``LIBGIT2_DEFINITIONS``
0027 This should be passed to target_compile_options() if the target is not
0028 used for linking
0029
0030 If ``LIBGIT2_FOUND`` is TRUE, it will also define the following imported target:
0031
0032 ``LibGit2::LibGit2``
0033 The libgit2 library
0034
0035 In general we recommend using the imported target, as it is easier to use.
0036 Bear in mind, however, that if the target is in the link interface of an
0037 exported library, it must be made available by the package config file.
0038
0039 Since 1.3.0.
0040 #]=======================================================================]
0041
0042 include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake)
0043
0044 ecm_find_package_version_check(LibGit2)
0045
0046 # Use pkg-config to get the directories and then use these values
0047 # in the FIND_PATH() and FIND_LIBRARY() calls
0048 find_package(PkgConfig QUIET)
0049 pkg_check_modules(PKG_GIT2 QUIET libgit2)
0050
0051 set(LIBGIT2_DEFINITIONS ${PKG_GIT2_CFLAGS_OTHER})
0052
0053 find_path(LIBGIT2_INCLUDE_DIR
0054 NAMES
0055 git2.h
0056 HINTS
0057 ${PKG_GIT2_INCLUDE_DIRS}
0058 )
0059 find_library(LIBGIT2_LIBRARY
0060 NAMES
0061 git2
0062 HINTS
0063 ${PKG_GIT2_LIBRARY_DIRS}
0064 )
0065
0066 # get version from header, should work on windows, too
0067 if(LIBGIT2_INCLUDE_DIR)
0068 file(STRINGS "${LIBGIT2_INCLUDE_DIR}/git2/version.h" LIBGIT2_H REGEX "^#define LIBGIT2_VERSION +\"[^\"]*\"$")
0069
0070 string(REGEX REPLACE "^.*LIBGIT2_VERSION +\"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${LIBGIT2_H}")
0071 string(REGEX REPLACE "^.*LIBGIT2_VERSION +\"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${LIBGIT2_H}")
0072 string(REGEX REPLACE "^.*LIBGIT2_VERSION +\"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_PATCH "${LIBGIT2_H}")
0073 set(LIBGIT2_VERSION "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_PATCH}")
0074
0075 set(LIBGIT2_MAJOR_VERSION "${LIBGIT2_VERSION_MAJOR}")
0076 set(LIBGIT2_MINOR_VERSION "${LIBGIT2_VERSION_MINOR}")
0077 set(LIBGIT2_PATCH_VERSION "${LIBGIT2_VERSION_PATCH}")
0078
0079 unset(LIBGIT2_H)
0080 endif()
0081
0082 include(FindPackageHandleStandardArgs)
0083 find_package_handle_standard_args(LibGit2
0084 FOUND_VAR
0085 LIBGIT2_FOUND
0086 REQUIRED_VARS
0087 LIBGIT2_LIBRARY
0088 LIBGIT2_INCLUDE_DIR
0089 VERSION_VAR
0090 LIBGIT2_VERSION
0091 )
0092
0093 if(LIBGIT2_FOUND AND NOT TARGET LibGit2::LibGit2)
0094 add_library(LibGit2::LibGit2 UNKNOWN IMPORTED)
0095 set_target_properties(LibGit2::LibGit2 PROPERTIES
0096 IMPORTED_LOCATION "${LIBGIT2_LIBRARY}"
0097 INTERFACE_COMPILE_OPTIONS "${LIBGIT2_DEFINITIONS}"
0098 INTERFACE_INCLUDE_DIRECTORIES "${LIBGIT2_INCLUDE_DIR}"
0099 )
0100 endif()
0101
0102 mark_as_advanced(LIBGIT2_LIBRARY LIBGIT2_INCLUDE_DIR)
0103
0104 set(LIBGIT2_LIBRARIES ${LIBGIT2_LIBRARY})
0105 set(LIBGIT2_INCLUDE_DIRS ${LIBGIT2_INCLUDE_DIR})
0106
0107 include(FeatureSummary)
0108 set_package_properties(LibGit2 PROPERTIES
0109 URL "https://libgit2.github.com/"
0110 DESCRIPTION "A plain C library to interface with the git version control system."
0111 )