diff --git a/recipes/libgcrypt/all/conanfile.py b/recipes/libgcrypt/all/conanfile.py index e758bd35a6027d..dd7bea9124e530 100644 --- a/recipes/libgcrypt/all/conanfile.py +++ b/recipes/libgcrypt/all/conanfile.py @@ -1,15 +1,21 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import cross_building +from conan.tools.env import VirtualRunEnv +from conan.tools.files import copy, get, rm, rmdir +from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain +from conan.tools.layout import basic_layout import os -from conans import ConanFile, AutoToolsBuildEnvironment, tools -from conans.errors import ConanInvalidConfiguration -required_conan_version = ">=1.33.0" +required_conan_version = ">=1.50.0" + class LibgcryptConan(ConanFile): name = "libgcrypt" url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.gnupg.org/download/index.html#libgcrypt" description = "Libgcrypt is a general purpose cryptographic library originally based on code from GnuPG" - topics = ("libgcrypt", "gcrypt", "gnupg", "gpg", "crypto", "cryptography") + topics = ("gcrypt", "gnupg", "gpg", "crypto", "cryptography") license = "LGPL-2.1-or-later" settings = "os", "arch", "compiler", "build_type" options = { @@ -21,63 +27,58 @@ class LibgcryptConan(ConanFile): "fPIC": True, } - _autotools = None - - @property - def _source_subfolder(self): - return "source_subfolder" - def configure(self): - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd if self.options.shared: del self.options.fPIC + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") + + def layout(self): + basic_layout(self, src_folder="src") + + def requirements(self): + self.requires("libcap/2.65") + self.requires("libgpg-error/1.36") def validate(self): - if self.settings.os != "Linux": + if self.info.settings.os != "Linux": raise ConanInvalidConfiguration("This recipe only support Linux. You can contribute Windows and/or Macos support.") 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], + destination=self.source_folder, strip_root=True) - def requirements(self): - self.requires("libgpg-error/1.36") - self.requires("libcap/2.50") + def generate(self): + if not cross_building(self): + env = VirtualRunEnv(self) + env.generate(scope="build") - def _configure(self): - if self._autotools: - return self._autotools - args = ["--disable-doc"] - args.append("--with-libgpg-error-prefix={}".format(self.deps_cpp_info["libgpg-error"].rootpath)) - if self.options.get_safe("fPIC", True): - args.append("--with-pic") - if self.options.shared: - args.extend(["--disable-static", "--enable-shared"]) - else: - args.extend(["--disable-shared", "--enable-static"]) + tc = AutotoolsToolchain(self) + tc.configure_args.extend([ + "--disable-doc", + f"--with-libgpg-error-prefix={self.dependencies['libgpg-error'].package_folder}", + ]) + tc.generate() - self._autotools = AutoToolsBuildEnvironment(self) - self._autotools.configure(args=args, configure_dir=self._source_subfolder) - return self._autotools + deps = AutotoolsDeps(self) + deps.generate() def build(self): - env_build = self._configure() - env_build.make() + autotools = Autotools(self) + autotools.configure() + autotools.make() def package(self): - env_build = self._configure() - env_build.install() - self.copy(pattern="COPYING*", dst="licenses", src=self._source_subfolder) - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*la") - tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) - tools.rmdir(os.path.join(self.package_folder, "share")) + copy(self, "COPYING*", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + autotools = Autotools(self) + autotools.install() + rm(self, "*la", os.path.join(self.package_folder, "lib")) + rmdir(self, os.path.join(self.package_folder, "share")) def package_info(self): self.cpp_info.libs = ["gcrypt"] - bin_path = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH env var with : {}".format(bin_path)) - self.env_info.PATH.append(bin_path) - self.cpp_info.names["pkg_config"] = "gcrypt" if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs = ["pthread"] + + # TODO: to remove in conan v2 + self.env_info.PATH.append(os.path.join(self.package_folder, "bin")) diff --git a/recipes/libgcrypt/all/test_package/CMakeLists.txt b/recipes/libgcrypt/all/test_package/CMakeLists.txt index db0b2fa444a2f1..1a3fbb3bbed04c 100644 --- a/recipes/libgcrypt/all/test_package/CMakeLists.txt +++ b/recipes/libgcrypt/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(test_package C) +project(test_package LANGUAGES C) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -find_library(CAP_LIBRARY NAMES libcap.a libcap.so) +find_package(libgcrypt REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +target_link_libraries(${PROJECT_NAME} PRIVATE libgcrypt::libgcrypt) diff --git a/recipes/libgcrypt/all/test_package/conanfile.py b/recipes/libgcrypt/all/test_package/conanfile.py index fc4fe1905b49a5..0a6bc68712d901 100644 --- a/recipes/libgcrypt/all/test_package/conanfile.py +++ b/recipes/libgcrypt/all/test_package/conanfile.py @@ -1,10 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os -from conans import ConanFile, CMake, tools class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): 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.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/libgcrypt/all/test_v1_package/CMakeLists.txt b/recipes/libgcrypt/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..0d20897301b68b --- /dev/null +++ b/recipes/libgcrypt/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package) diff --git a/recipes/libgcrypt/all/test_v1_package/conanfile.py b/recipes/libgcrypt/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..38f4483872d47f --- /dev/null +++ b/recipes/libgcrypt/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + 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): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)