Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libgit2] Add Exported CMake Targets #21670

Merged
merged 5 commits into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
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
53 changes: 53 additions & 0 deletions ports/libgit2/fix-configcmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fdb3673..da1f972 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -125,7 +125,6 @@ include(SelectHashes)
target_sources(git2internal PRIVATE ${SRC_SHA1})

# Specify regular expression implementation
-FIND_PACKAGE(PCRE)

IF(REGEX_BACKEND STREQUAL "")
CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
@@ -159,8 +158,8 @@ ELSEIF(REGEX_BACKEND STREQUAL "pcre")
ADD_FEATURE_INFO(regex ON "using system PCRE")
SET(GIT_REGEX_PCRE 1)

- LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS})
- LIST(APPEND LIBGIT2_LIBS ${PCRE_LIBRARIES})
+ FIND_PACKAGE(unofficial-pcre CONFIG REQUIRED)
+ LIST(APPEND LIBGIT2_LIBS unofficial::pcre::pcre)
LIST(APPEND LIBGIT2_PC_REQUIRES "libpcre")
ELSEIF(REGEX_BACKEND STREQUAL "regcomp")
ADD_FEATURE_INFO(regex ON "using system regcomp")
@@ -424,10 +423,28 @@ IF (MSVC_IDE)
ENDIF ()

# Install
-INSTALL(TARGETS git2
+INSTALL(TARGETS git2 EXPORT unofficial-git2Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
+
+install(EXPORT unofficial-git2Targets
+ NAMESPACE unofficial::git2::
+ DESTINATION share/unofficial-git2
+)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/unofficial-git2-config.cmake.in"
+[[include(CMakeFindDependencyMacro)
+IF(@USE_BUNDLED_ZLIB@ STREQUAL "OFF")
+ find_dependency(ZLIB)
+ENDIF()
+IF(@REGEX_BACKEND@ STREQUAL "pcre")
+ find_dependency(unofficial-pcre CONFIG)
+ENDIF()
+include("${CMAKE_CURRENT_LIST_DIR}/unofficial-git2Targets.cmake")
+]])
+configure_file("${CMAKE_CURRENT_BINARY_DIR}/unofficial-git2-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/unofficial-git2-config.cmake" @ONLY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unofficial-git2-config.cmake DESTINATION share/unofficial-git2)
+
INSTALL(DIRECTORY ${libgit2_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
INSTALL(FILES ${libgit2_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
8 changes: 5 additions & 3 deletions ports/libgit2/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# libgit2 uses winapi functions not available in WindowsStore
vcpkg_fail_port_install(ON_TARGET "uwp")

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO libgit2/libgit2
REF v1.3.0
SHA512 842a648a67ff23ba9e6bf14b706ba9081164866e14000ebf3858442b7046925f05e1dbf00a7d740dc4bf32280e260730e23a9492e817094aa90736ae335ee76e
HEAD_REF master
PATCHES
fix-configcmake.patch
)

file(REMOVE_RECURSE "${SOURCE_PATH}/cmake/FindPCRE.cmake")

string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" STATIC_CRT)

set(REGEX_BACKEND OFF)
Expand Down Expand Up @@ -75,6 +76,7 @@ vcpkg_cmake_configure(
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-git2 CONFIG_PATH share/unofficial-git2)
vcpkg_fixup_pkgconfig()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
Expand Down
6 changes: 5 additions & 1 deletion ports/libgit2/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libgit2",
"version-semver": "1.3.0",
"port-version": 1,
"port-version": 2,
"description": "Git linkable library",
"homepage": "https://github.com/libgit2/libgit2",
"supports": "!uwp",
Expand All @@ -11,6 +11,10 @@
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
"zlib"
],
"default-features": [
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3478,7 +3478,7 @@
},
"libgit2": {
"baseline": "1.3.0",
"port-version": 1
"port-version": 2
},
"libgnutls": {
"baseline": "3.6.15",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libgit2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "37f2b6e92b60481a4db74de9da17385706d7d2e9",
"version-semver": "1.3.0",
"port-version": 2
},
{
"git-tree": "608c02285dbac754d7b2a34e67f081879cdee38f",
"version-semver": "1.3.0",
Expand Down