import os from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.env import VirtualBuildEnv from conan.tools.files import copy, get, chdir, rm from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain, PkgConfigDeps from conan.tools.layout import basic_layout required_conan_version = ">=2.0.0" class YaraConan(ConanFile): name = "yara" package_type = "library" license = "BSD-3-Clause" url = "https://github.com/VirusTotal/yara" homepage = "https://virustotal.github.io/yara/" description = "The pattern matching swiss knife" topics = ("security", "malware", "signatures", "yara") settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], "fPIC": [True, False], "with_crypto": [True, False], "with_proc_scan": [True, False], } default_options = { "shared": False, "fPIC": True, "with_crypto": True, "with_proc_scan": False, "openssl/*:shared": False, } def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): if self.options.shared: self.options.rm_safe("fPIC") def validate(self): if self.settings.os == "Windows": raise ConanInvalidConfiguration( "This local recipe currently targets Linux/macOS-style Autotools builds only." ) def requirements(self): if self.options.with_crypto: self.requires("openssl/3.6.2") def build_requirements(self): self.tool_requires("autoconf/2.71") self.tool_requires("automake/1.16.5") self.tool_requires("libtool/2.4.7") self.tool_requires("pkgconf/2.5.1") def layout(self): basic_layout(self, src_folder="src") def source(self): get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def generate(self): tc = AutotoolsToolchain(self) tc.configure_args.extend(self._configure_args()) tc.generate() AutotoolsDeps(self).generate() PkgConfigDeps(self).generate() VirtualBuildEnv(self).generate() def build(self): autotools = Autotools(self) with chdir(self, self.source_folder): autotools.autoreconf() autotools.configure() autotools.make() def package(self): autotools = Autotools(self) with chdir(self, self.source_folder): autotools.install() copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) rm(self, "*.la", os.path.join(self.package_folder, "lib")) def package_info(self): self.cpp_info.set_property("pkg_config_name", "yara") self.cpp_info.libs = ["yara"] if self.settings.os == "Linux": self.cpp_info.system_libs.append("pthread") def _configure_args(self): args = [ "--disable-cuckoo", "--disable-dex", "--disable-magic", "--disable-macho", ] if not self.options.with_proc_scan: args.append("--disable-proc-scan") if not self.options.with_crypto: args.append("--without-crypto") return args