# - Try to find the 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
#  LIBGIT2_DEFINITIONS - Compiler switches required for using libgit2


# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
#FIND_PACKAGE(PkgConfig)
#PKG_SEARCH_MODULE(PC_LIBGIT2 libgit2)

SET(LIBGIT2_DEFINITIONS ${PC_LIBGIT2_CFLAGS_OTHER})

FIND_PATH(LIBGIT2_INCLUDE_DIR NAMES git2.h
   HINTS
   ${PC_LIBGIT2_INCLUDEDIR}
   ${PC_LIBGIT2_INCLUDE_DIRS}
)

FIND_LIBRARY(LIBGIT2_LIBRARIES NAMES libgit2.a
   HINTS
   ${PC_LIBGIT2_LIBDIR}
   ${PC_LIBGIT2_LIBRARY_DIRS}
)

find_package(CoreFoundation REQUIRED)
find_package(Security REQUIRED)
find_package(libssh2 REQUIRED)
find_package(CURL REQUIRED)
find_package(libcrypto REQUIRED)

list(APPEND LIBGIT2_LIBRARIES ${COREFOUNDATION_LIBRARIES})
list(APPEND LIBGIT2_LIBRARIES ${SECURITY_LIBRARIES})
list(APPEND LIBGIT2_LIBRARIES ${LIBSSH2_LIBRARIES})
list(APPEND LIBGIT2_LIBRARIES ${LIBCURL_LIBRARIES})
list(APPEND LIBGIT2_LIBRARIES ${LIBCRYPTO_LIBRARIES})
list(APPEND LIBGIT2_LIBRARIES libz.a)
list(APPEND LIBGIT2_LIBRARIES libiconv.a)


INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(libgit2 DEFAULT_MSG LIBGIT2_LIBRARIES LIBGIT2_INCLUDE_DIR)

MARK_AS_ADVANCED(LIBGIT2_INCLUDE_DIR LIBGIT2_LIBRARIES)
