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: bump dependencies + modernize #10489

Merged
merged 3 commits into from
Apr 26, 2022
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
6 changes: 3 additions & 3 deletions recipes/libgit2/0.27.x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper C)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

add_subdirectory(source_subfolder)
6 changes: 3 additions & 3 deletions recipes/libgit2/0.27.x/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sources:
"0.27.9":
url: "https://github.com/libgit2/libgit2/archive/v0.27.9.tar.gz"
sha256: "adf17310b590e6e7618f070c742b5ee028aeeed2c60099bc4190c386b5060de1"
"0.27.10":
url: "https://github.com/libgit2/libgit2/archive/v0.27.10.tar.gz"
sha256: "f6fd26378ff71bd7a4b17b576c82c774a2e9c2d6b74b24718a8fb29551e1c4a5"
"0.27.9":
url: "https://github.com/libgit2/libgit2/archive/v0.27.9.tar.gz"
sha256: "adf17310b590e6e7618f070c742b5ee028aeeed2c60099bc4190c386b5060de1"
97 changes: 51 additions & 46 deletions recipes/libgit2/0.27.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conans import ConanFile, tools, CMake
from conans.errors import ConanInvalidConfiguration
import functools
import os

required_conan_version = ">=1.45.0"


class LibGit2Conan(ConanFile):
name = "libgit2"
description = "libgit2 is a portable, pure C implementation of the Git core methods provided as a re-entrant linkable library with a solid API"
topics = ("conan", "libgit2", "git", "scm", )
description = (
"libgit2 is a portable, pure C implementation of the Git core methods "
"provided as a re-entrant linkable library with a solid API"
)
topics = ("libgit2", "git", "scm")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://libgit2.org/"
license = ("GPL-2.0-linking-exception",)
exports_sources = "CMakeLists.txt",
generators = "cmake", "cmake_find_package",
settings = "os", "compiler", "build_type", "arch"
license = "GPL-2.0-linking-exception"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"threadsafe": [True, False],
"with_iconv": [True, False],
"with_libssh2": [True, False],
"with_https": [False, "openssl", "winhttp", "security"],
"with_sha1": ["collisiondetection", "commoncrypto", "openssl", "generic", "win32"],
"with_sha1": ["collisiondetection", "commoncrypto", "openssl", "generic", "win32"],
}
default_options = {
"shared": False,
Expand All @@ -32,23 +38,41 @@ class LibGit2Conan(ConanFile):
"with_sha1": "collisiondetection",
}

_cmake = None
exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"

@property
def _source_subfolder(self):
return "source_subfolder"

def config_options(self):
if self.settings.os == "Windows" or self.options.shared:
if self.settings.os == "Windows":
del self.options.fPIC

if not tools.is_apple_os(self.settings.os):
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

@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("http_parser/2.9.4")
if self.options.with_libssh2:
self.requires("libssh2/1.10.0")
if self.settings.os != "Windows":
self.requires("libcurl/7.80.0")
if self._need_openssl:
self.requires("openssl/1.1.1n")

def validate(self):
if self.options.with_https == "security":
if not tools.is_apple_os(self.settings.os):
raise ConanInvalidConfiguration("security is only valid for Apple products")
Expand All @@ -60,24 +84,9 @@ def configure(self):
if self.settings.os != "Windows":
raise ConanInvalidConfiguration("win32 is only valid on Windows")

@property
def _need_openssl(self):
return "openssl" in (self.options.with_https, self.options.with_sha1)

def requirements(self):
self.requires("zlib/1.2.11")
self.requires("http_parser/2.9.4")
if self.options.with_libssh2:
self.requires("libssh2/1.9.0")
if self.settings.os != "Windows":
self.requires("libcurl/7.75.0")
if self._need_openssl:
self.requires("openssl/1.1.1j")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "{}-{}".format(self.name, self.version)
os.rename(extracted_dir, self._source_subfolder)
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

_cmake_https = {
"openssl": "OpenSSL",
Expand All @@ -94,30 +103,25 @@ def source(self):
"win32": "Win32",
}

@functools.lru_cache(1)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["THREADSAFE"] = self.options.threadsafe
self._cmake.definitions["USE_SSH"] = self.options.with_libssh2

if tools.is_apple_os(self.settings.os):
self._cmake.definitions["USE_ICONV"] = self.options.with_iconv
else:
self._cmake.definitions["USE_ICONV"] = True
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)

self._cmake.definitions["USE_HTTPS"] = self._cmake_https[str(self.options.with_https)]
self._cmake.definitions["SHA1_BACKEND"] = self._cmake_sha1[str(self.options.with_sha1)]
cmake.definitions["USE_HTTPS"] = self._cmake_https[str(self.options.with_https)]
cmake.definitions["SHA1_BACKEND"] = self._cmake_sha1[str(self.options.with_sha1)]

self._cmake.definitions["BUILD_CLAR"] = False
self._cmake.definitions["BUILD_EXAMPLES"] = False
cmake.definitions["BUILD_CLAR"] = False
cmake.definitions["BUILD_EXAMPLES"] = False

if self.settings.compiler == "Visual Studio":
self._cmake.definitions["STATIC_CRT"] = "MT" in str(self.settings.compiler.runtime)
if is_msvc(self):
cmake.definitions["STATIC_CRT"] = is_msvc_static_runtime(self)

self._cmake.configure()
return self._cmake
cmake.configure()
return cmake

def _patch_sources(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
Expand All @@ -138,14 +142,15 @@ def build(self):
cmake.build()

def package(self):
self.copy("COPYING", src=os.path.join(self.source_folder, self._source_subfolder), dst="licenses")
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "libgit2")
self.cpp_info.libs = ["git2"]
if self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["winhttp", "rpcrt4", "crypt32"])
if self.settings.os == "Linux" and self.options.threadsafe:
if self.settings.os in ["Linux", "FreeBSD"] and self.options.threadsafe:
self.cpp_info.system_libs.append("pthread")
10 changes: 6 additions & 4 deletions recipes/libgit2/0.27.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(TARGETS)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
find_package(libgit2 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} libgit2::libgit2)
6 changes: 3 additions & 3 deletions recipes/libgit2/0.27.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
34 changes: 34 additions & 0 deletions recipes/libgit2/0.27.x/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <git2.h>

#include <stdio.h>

int main()
{
git_libgit2_init();
int versionMajor, versionMinor, versionRev;
git_libgit2_version(&versionMajor, &versionMinor, &versionRev);

printf("libgit2 v%i.%i.%i\n", versionMajor, versionMinor, versionRev);

printf("Compile Features:\n");

int features = git_libgit2_features();

if (features & GIT_FEATURE_THREADS)
printf(" - Thread safe\n");
else
printf(" - Single thread only\n");

if (features & GIT_FEATURE_HTTPS)
printf(" - TLS (openssl, winhttp or security)\n");
else
printf(" - No TLS\n");

if (features & GIT_FEATURE_SSH)
printf(" - SSH (libssh2)\n");
else
printf(" - No SSH support\n");

git_libgit2_shutdown();
return 0;
}
35 changes: 0 additions & 35 deletions recipes/libgit2/0.27.x/test_package/test_package.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions recipes/libgit2/0.28.x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper C)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

add_subdirectory(source_subfolder)
Loading