-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 version 1.7.2, support conan v2 #18458
Changes from 24 commits
fd20266
40ed77d
28c2bf1
22a6482
ecc36e4
c2cd815
ae21891
b1eaf57
a0a0ee5
e99f103
974ef8c
8ca3d60
701d719
22a6255
e34284d
f0658aa
fed112b
37a3dc7
45b0b17
7aa9087
70afd59
f181d53
15b732d
6ccaf17
51bbd22
592eb96
c75ed03
d3e80d1
09f2eb5
33f0fcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime | ||
from conans import ConanFile, tools, CMake | ||
from conans.errors import ConanInvalidConfiguration | ||
import functools | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc | ||
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.apple import is_apple_os | ||
import os | ||
|
||
required_conan_version = ">=1.45.0" | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class LibGit2Conan(ConanFile): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
@@ -38,43 +41,42 @@ class LibGit2Conan(ConanFile): | |
"with_sha1": "collisiondetection", | ||
} | ||
|
||
exports_sources = "CMakeLists.txt" | ||
generators = "cmake", "cmake_find_package" | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
def export_sources(self): | ||
export_conandata_patches(self) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
if not tools.is_apple_os(self.settings.os): | ||
if not is_apple_os(self): | ||
del self.options.with_iconv | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
del self.options.fPIC | ||
del self.settings.compiler.cppstd | ||
del self.settings.compiler.libcxx | ||
self.options.rm_safe("fPIC") | ||
self.settings.rm_safe("compiler.libcxx") | ||
self.settings.rm_safe("compiler.cppstd") | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
@property | ||
def _need_openssl(self): | ||
return "openssl" in (self.options.with_https, self.options.with_sha1) | ||
|
||
def requirements(self): | ||
self.requires("zlib/1.2.12") | ||
self.requires("zlib/[>=1.2.12 <2]") | ||
self.requires("http_parser/2.9.4") | ||
if self.options.with_libssh2: | ||
self.requires("libssh2/1.10.0") | ||
self.requires("libssh2/1.11.0") | ||
if self.settings.os != "Windows": | ||
self.requires("libcurl/7.83.1") | ||
self.requires("libcurl/[>=7.83 <9]") | ||
if self._need_openssl: | ||
self.requires("openssl/1.1.1o") | ||
self.requires("openssl/[>=1.1 <4]") | ||
|
||
def validate(self): | ||
if self.options.with_https == "security": | ||
if not tools.is_apple_os(self.settings.os): | ||
if not is_apple_os(self): | ||
raise ConanInvalidConfiguration("security is only valid for Apple products") | ||
elif self.options.with_https == "winhttp": | ||
if self.settings.os != "Windows": | ||
|
@@ -85,8 +87,7 @@ def validate(self): | |
raise ConanInvalidConfiguration("win32 is only valid on Windows") | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version], | ||
destination=self._source_subfolder, strip_root=True) | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
_cmake_https = { | ||
"openssl": "OpenSSL", | ||
|
@@ -103,49 +104,32 @@ def source(self): | |
"win32": "Win32", | ||
} | ||
|
||
@functools.lru_cache(1) | ||
def _configure_cmake(self): | ||
cmake = CMake(self) | ||
cmake.definitions["THREADSAFE"] = self.options.threadsafe | ||
cmake.definitions["USE_SSH"] = self.options.with_libssh2 | ||
|
||
cmake.definitions["USE_ICONV"] = self.options.get_safe("with_iconv", False) | ||
|
||
cmake.definitions["USE_HTTPS"] = self._cmake_https[str(self.options.with_https)] | ||
cmake.definitions["SHA1_BACKEND"] = self._cmake_sha1[str(self.options.with_sha1)] | ||
|
||
cmake.definitions["BUILD_CLAR"] = False | ||
cmake.definitions["BUILD_EXAMPLES"] = False | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["THREADSAFE"] = self.options.threadsafe | ||
tc.variables["USE_SSH"] = self.options.with_libssh2 | ||
tc.variables["USE_ICONV"] = self.options.get_safe("with_iconv", False) | ||
tc.variables["USE_HTTPS"] = self._cmake_https[str(self.options.with_https)] | ||
tc.variables["SHA1_BACKEND"] = self._cmake_sha1[str(self.options.with_sha1)] | ||
tc.variables["BUILD_CLAR"] = False | ||
tc.variables["BUILD_EXAMPLES"] = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to set |
||
if is_msvc(self): | ||
cmake.definitions["STATIC_CRT"] = is_msvc_static_runtime(self) | ||
|
||
cmake.configure() | ||
return cmake | ||
|
||
def _patch_sources(self): | ||
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"), | ||
"FIND_PKGLIBRARIES(LIBSSH2 libssh2)", | ||
"FIND_PACKAGE(Libssh2 REQUIRED)\n" | ||
"\tSET(LIBSSH2_FOUND ON)\n" | ||
"\tSET(LIBSSH2_INCLUDE_DIRS ${Libssh2_INCLUDE_DIRS})\n" | ||
"\tSET(LIBSSH2_LIBRARIES ${Libssh2_LIBRARIES})\n" | ||
"\tSET(LIBSSH2_LIBRARY_DIRS ${Libssh2_LIB_DIRS})") | ||
|
||
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"), | ||
"FIND_PKGLIBRARIES(CURL libcurl)", | ||
"FIND_PACKAGE(CURL REQUIRED)\n") | ||
tc.variables["STATIC_CRT"] = is_msvc_static_runtime(self) | ||
tc.generate() | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
|
||
def build(self): | ||
self._patch_sources() | ||
cmake = self._configure_cmake() | ||
apply_conandata_patches(self) | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
self.copy("COPYING", src=self._source_subfolder, dst="licenses") | ||
cmake = self._configure_cmake() | ||
copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) | ||
cmake = CMake(self) | ||
cmake.install() | ||
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
|
||
def package_info(self): | ||
self.cpp_info.set_property("pkg_config_name", "libgit2") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 83898c5..bc7934e 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -11,8 +11,8 @@ | ||
# Install: | ||
# > cmake --build . --target install | ||
|
||
-PROJECT(libgit2 C) | ||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) | ||
+PROJECT(libgit2 C) | ||
CMAKE_POLICY(SET CMP0015 NEW) | ||
IF (POLICY CMP0051) | ||
CMAKE_POLICY(SET CMP0051 NEW) | ||
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt | ||
index 2080933..8b310fa 100644 | ||
--- a/src/CMakeLists.txt | ||
+++ b/src/CMakeLists.txt | ||
@@ -126,7 +126,7 @@ IF (WIN32 AND WINHTTP) | ||
LIST(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") | ||
ELSE () | ||
IF (CURL) | ||
- FIND_PKGLIBRARIES(CURL libcurl) | ||
+ FIND_PACKAGE(CURL REQUIRED) | ||
ENDIF () | ||
IF (CURL_FOUND) | ||
SET(GIT_CURL 1) | ||
@@ -287,7 +287,11 @@ ENDIF() | ||
|
||
# Optional external dependency: libssh2 | ||
IF (USE_SSH) | ||
- FIND_PKGLIBRARIES(LIBSSH2 libssh2) | ||
+ FIND_PACKAGE(Libssh2 REQUIRED) | ||
+ SET(LIBSSH2_FOUND ON) | ||
+ SET(LIBSSH2_INCLUDE_DIRS ${Libssh2_INCLUDE_DIRS}) | ||
+ SET(LIBSSH2_LIBRARIES ${Libssh2_LIBRARIES}) | ||
+ SET(LIBSSH2_LIBRARY_DIRS ${Libssh2_LIB_DIRS}) | ||
ENDIF() | ||
IF (LIBSSH2_FOUND) | ||
SET(GIT_SSH 1) | ||
@@ -295,10 +299,7 @@ IF (LIBSSH2_FOUND) | ||
LIST(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES}) | ||
LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS}) | ||
|
||
- CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS) | ||
- IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS) | ||
- SET(GIT_SSH_MEMORY_CREDENTIALS 1) | ||
- ENDIF() | ||
+ SET(GIT_SSH_MEMORY_CREDENTIALS 1) | ||
ELSE() | ||
MESSAGE(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.") | ||
ENDIF() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
project(test_package LANGUAGES C) | ||
|
||
find_package(libgit2 REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} libgit2::libgit2) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE libgit2::libgit2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
from conans import ConanFile, CMake, tools | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "cmake", "cmake_find_package_multi" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the
0.27
recipe can be dropped altogether.