diff --git a/recipes/libgit2/0.27.x/CMakeLists.txt b/recipes/libgit2/0.27.x/CMakeLists.txt index 97030501e5bd7..c502da172e7b8 100644 --- a/recipes/libgit2/0.27.x/CMakeLists.txt +++ b/recipes/libgit2/0.27.x/CMakeLists.txt @@ -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) diff --git a/recipes/libgit2/0.27.x/conandata.yml b/recipes/libgit2/0.27.x/conandata.yml index d18a94e064929..53e71ffa5177c 100644 --- a/recipes/libgit2/0.27.x/conandata.yml +++ b/recipes/libgit2/0.27.x/conandata.yml @@ -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" diff --git a/recipes/libgit2/0.27.x/conanfile.py b/recipes/libgit2/0.27.x/conanfile.py index 17d887ee33c11..609435df3fb3d 100644 --- a/recipes/libgit2/0.27.x/conanfile.py +++ b/recipes/libgit2/0.27.x/conanfile.py @@ -1,18 +1,24 @@ +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], @@ -20,7 +26,7 @@ class LibGit2Conan(ConanFile): "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, @@ -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") @@ -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", @@ -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"), @@ -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") diff --git a/recipes/libgit2/0.27.x/test_package/CMakeLists.txt b/recipes/libgit2/0.27.x/test_package/CMakeLists.txt index 196188113685c..912bdc647f324 100644 --- a/recipes/libgit2/0.27.x/test_package/CMakeLists.txt +++ b/recipes/libgit2/0.27.x/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libgit2/0.27.x/test_package/conanfile.py b/recipes/libgit2/0.27.x/test_package/conanfile.py index bd7165a553cf4..38f4483872d47 100644 --- a/recipes/libgit2/0.27.x/test_package/conanfile.py +++ b/recipes/libgit2/0.27.x/test_package/conanfile.py @@ -3,8 +3,8 @@ 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) @@ -12,6 +12,6 @@ def build(self): 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) diff --git a/recipes/libgit2/0.27.x/test_package/test_package.c b/recipes/libgit2/0.27.x/test_package/test_package.c new file mode 100644 index 0000000000000..1ea125101cdc8 --- /dev/null +++ b/recipes/libgit2/0.27.x/test_package/test_package.c @@ -0,0 +1,34 @@ +#include + +#include + +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; +} diff --git a/recipes/libgit2/0.27.x/test_package/test_package.cpp b/recipes/libgit2/0.27.x/test_package/test_package.cpp deleted file mode 100644 index ab4034d609280..0000000000000 --- a/recipes/libgit2/0.27.x/test_package/test_package.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "git2.h" - -#include -#include - -int main() -{ - git_libgit2_init(); - int versionMajor, versionMinor, versionRev; - git_libgit2_version(&versionMajor, &versionMinor, &versionRev); - - std::cout << "libgit2 v" << versionMajor << "." << versionMinor << "." << versionRev << std::endl; - - std::cout << "Compile Features:" << std::endl; - - int features = git_libgit2_features(); - - if (features & GIT_FEATURE_THREADS) - std::cout << " - Thread safe" << std::endl; - else - std::cout << " - Single thread only" << std::endl; - - if (features & GIT_FEATURE_HTTPS) - std::cout << " - TLS (openssl, winhttp or security)" << std::endl; - else - std::cout << " - No TLS" << std::endl; - - if (features & GIT_FEATURE_SSH) - std::cout << " - SSH (libssh2)" << std::endl; - else - std::cout << " - No SSH support" << std::endl; - - git_libgit2_shutdown(); - return EXIT_SUCCESS; -} diff --git a/recipes/libgit2/0.28.x/CMakeLists.txt b/recipes/libgit2/0.28.x/CMakeLists.txt index 97030501e5bd7..c502da172e7b8 100644 --- a/recipes/libgit2/0.28.x/CMakeLists.txt +++ b/recipes/libgit2/0.28.x/CMakeLists.txt @@ -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) diff --git a/recipes/libgit2/0.28.x/conanfile.py b/recipes/libgit2/0.28.x/conanfile.py index db3987cd12dab..a9237470e171a 100644 --- a/recipes/libgit2/0.28.x/conanfile.py +++ b/recipes/libgit2/0.28.x/conanfile.py @@ -1,18 +1,24 @@ +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], @@ -32,14 +38,15 @@ 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): @@ -51,17 +58,6 @@ def configure(self): del self.settings.compiler.cppstd del self.settings.compiler.libcxx - if self.options.with_https == "security": - if not tools.is_apple_os(self.settings.os): - raise ConanInvalidConfiguration("security is only valid for Apple products") - elif self.options.with_https == "winhttp": - if self.settings.os != "Windows": - raise ConanInvalidConfiguration("winhttp is only valid on Windows") - - if self.options.with_sha1 == "win32": - 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) @@ -71,21 +67,32 @@ def _need_mbedtls(self): return "mbedtls" in (self.options.with_https, self.options.with_sha1) def requirements(self): - self.requires("zlib/1.2.11") + self.requires("zlib/1.2.12") self.requires("http_parser/2.9.4") if self.options.with_libssh2: - self.requires("libssh2/1.9.0") + self.requires("libssh2/1.10.0") if self._need_openssl: - self.requires("openssl/1.1.1j") + self.requires("openssl/1.1.1n") if self._need_mbedtls: - self.requires("mbedtls/2.24.0") + self.requires("mbedtls/2.25.0") if tools.is_apple_os(self.settings.os) and self.options.with_iconv: self.requires("libiconv/1.16") + 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") + elif self.options.with_https == "winhttp": + if self.settings.os != "Windows": + raise ConanInvalidConfiguration("winhttp is only valid on Windows") + + if self.options.with_sha1 == "win32": + if self.settings.os != "Windows": + raise ConanInvalidConfiguration("win32 is only valid on Windows") + 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", @@ -104,29 +111,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 + cmake = CMake(self) + cmake.definitions["THREADSAFE"] = self.options.threadsafe + 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"] = False + 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"), @@ -139,20 +142,19 @@ def _patch_sources(self): def build(self): self._patch_sources() - cmake = self._configure_cmake() 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") diff --git a/recipes/libgit2/0.28.x/test_package/CMakeLists.txt b/recipes/libgit2/0.28.x/test_package/CMakeLists.txt index 196188113685c..912bdc647f324 100644 --- a/recipes/libgit2/0.28.x/test_package/CMakeLists.txt +++ b/recipes/libgit2/0.28.x/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libgit2/0.28.x/test_package/conanfile.py b/recipes/libgit2/0.28.x/test_package/conanfile.py index bd7165a553cf4..38f4483872d47 100644 --- a/recipes/libgit2/0.28.x/test_package/conanfile.py +++ b/recipes/libgit2/0.28.x/test_package/conanfile.py @@ -3,8 +3,8 @@ 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) @@ -12,6 +12,6 @@ def build(self): 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) diff --git a/recipes/libgit2/0.28.x/test_package/test_package.c b/recipes/libgit2/0.28.x/test_package/test_package.c new file mode 100644 index 0000000000000..96e8eda89c73b --- /dev/null +++ b/recipes/libgit2/0.28.x/test_package/test_package.c @@ -0,0 +1,34 @@ +#include + +#include + +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, mbedtls, 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; +} diff --git a/recipes/libgit2/0.28.x/test_package/test_package.cpp b/recipes/libgit2/0.28.x/test_package/test_package.cpp deleted file mode 100644 index 8e7504a8338a1..0000000000000 --- a/recipes/libgit2/0.28.x/test_package/test_package.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "git2.h" - -#include -#include - -int main() -{ - git_libgit2_init(); - int versionMajor, versionMinor, versionRev; - git_libgit2_version(&versionMajor, &versionMinor, &versionRev); - - std::cout << "libgit2 v" << versionMajor << "." << versionMinor << "." << versionRev << std::endl; - - std::cout << "Compile Features:" << std::endl; - - int features = git_libgit2_features(); - - if (features & GIT_FEATURE_THREADS) - std::cout << " - Thread safe" << std::endl; - else - std::cout << " - Single thread only" << std::endl; - - if (features & GIT_FEATURE_HTTPS) - std::cout << " - TLS (openssl, mbedtls, winhttp or security)" << std::endl; - else - std::cout << " - No TLS" << std::endl; - - if (features & GIT_FEATURE_SSH) - std::cout << " - SSH (libssh2)" << std::endl; - else - std::cout << " - No SSH support" << std::endl; - - git_libgit2_shutdown(); - return EXIT_SUCCESS; -} diff --git a/recipes/libgit2/all/CMakeLists.txt b/recipes/libgit2/all/CMakeLists.txt index 97030501e5bd7..c502da172e7b8 100644 --- a/recipes/libgit2/all/CMakeLists.txt +++ b/recipes/libgit2/all/CMakeLists.txt @@ -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) diff --git a/recipes/libgit2/all/conanfile.py b/recipes/libgit2/all/conanfile.py index 7b3fe8aa3499b..62167f61fce67 100644 --- a/recipes/libgit2/all/conanfile.py +++ b/recipes/libgit2/all/conanfile.py @@ -1,19 +1,24 @@ +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.33.0" +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",) + license = "GPL-2.0-linking-exception" - settings = "os", "compiler", "build_type", "arch" + settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], @@ -37,9 +42,8 @@ class LibGit2Conan(ConanFile): "with_regex": "builtin", } - exports_sources = "CMakeLists.txt", + exports_sources = "CMakeLists.txt" generators = "cmake", "cmake_find_package" - _cmake = None @property def _source_subfolder(self): @@ -65,12 +69,12 @@ def configure(self): del self.settings.compiler.libcxx def requirements(self): - self.requires("zlib/1.2.11") + self.requires("zlib/1.2.12") self.requires("http_parser/2.9.4") if self.options.with_libssh2: - self.requires("libssh2/1.9.0") + self.requires("libssh2/1.10.0") if self._need_openssl: - self.requires("openssl/1.1.1k") + self.requires("openssl/1.1.1n") if self._need_mbedtls: self.requires("mbedtls/2.25.0") if self.options.get_safe("with_iconv"): @@ -78,7 +82,7 @@ def requirements(self): if self.options.with_regex == "pcre": self.requires("pcre/8.45") elif self.options.with_regex == "pcre2": - self.requires("pcre2/10.37") + self.requires("pcre2/10.40") @property def _need_openssl(self): @@ -128,30 +132,28 @@ 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 + cmake = CMake(self) + cmake.definitions["THREADSAFE"] = self.options.threadsafe + cmake.definitions["USE_SSH"] = self.options.with_libssh2 - self._cmake.definitions["USE_ICONV"] = self.options.get_safe("with_iconv", False) + 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["USE_SHA1"] = self._cmake_sha1[str(self.options.with_sha1)] + cmake.definitions["USE_HTTPS"] = self._cmake_https[str(self.options.with_https)] + cmake.definitions["USE_SHA1"] = self._cmake_sha1[str(self.options.with_sha1)] - self._cmake.definitions["BUILD_CLAR"] = False - self._cmake.definitions["BUILD_EXAMPLES"] = False - self._cmake.definitions["USE_HTTP_PARSER"] = "system" + cmake.definitions["BUILD_CLAR"] = False + cmake.definitions["BUILD_EXAMPLES"] = False + cmake.definitions["USE_HTTP_PARSER"] = "system" - self._cmake.definitions["REGEX_BACKEND"] = self.options.with_regex + cmake.definitions["REGEX_BACKEND"] = self.options.with_regex - 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"), @@ -178,13 +180,13 @@ 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.names["pkg_config"] = "libgit2" + 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"]) diff --git a/recipes/libgit2/all/test_package/CMakeLists.txt b/recipes/libgit2/all/test_package/CMakeLists.txt index 196188113685c..912bdc647f324 100644 --- a/recipes/libgit2/all/test_package/CMakeLists.txt +++ b/recipes/libgit2/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libgit2/all/test_package/conanfile.py b/recipes/libgit2/all/test_package/conanfile.py index bd7165a553cf4..38f4483872d47 100644 --- a/recipes/libgit2/all/test_package/conanfile.py +++ b/recipes/libgit2/all/test_package/conanfile.py @@ -3,8 +3,8 @@ 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) @@ -12,6 +12,6 @@ def build(self): 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) diff --git a/recipes/libgit2/all/test_package/test_package.c b/recipes/libgit2/all/test_package/test_package.c new file mode 100644 index 0000000000000..96e8eda89c73b --- /dev/null +++ b/recipes/libgit2/all/test_package/test_package.c @@ -0,0 +1,34 @@ +#include + +#include + +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, mbedtls, 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; +} diff --git a/recipes/libgit2/all/test_package/test_package.cpp b/recipes/libgit2/all/test_package/test_package.cpp deleted file mode 100644 index 8e7504a8338a1..0000000000000 --- a/recipes/libgit2/all/test_package/test_package.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "git2.h" - -#include -#include - -int main() -{ - git_libgit2_init(); - int versionMajor, versionMinor, versionRev; - git_libgit2_version(&versionMajor, &versionMinor, &versionRev); - - std::cout << "libgit2 v" << versionMajor << "." << versionMinor << "." << versionRev << std::endl; - - std::cout << "Compile Features:" << std::endl; - - int features = git_libgit2_features(); - - if (features & GIT_FEATURE_THREADS) - std::cout << " - Thread safe" << std::endl; - else - std::cout << " - Single thread only" << std::endl; - - if (features & GIT_FEATURE_HTTPS) - std::cout << " - TLS (openssl, mbedtls, winhttp or security)" << std::endl; - else - std::cout << " - No TLS" << std::endl; - - if (features & GIT_FEATURE_SSH) - std::cout << " - SSH (libssh2)" << std::endl; - else - std::cout << " - No SSH support" << std::endl; - - git_libgit2_shutdown(); - return EXIT_SUCCESS; -}