|
| 1 | +from conans import ConanFile, AutoToolsBuildEnvironment, tools |
| 2 | +from conans.errors import ConanInvalidConfiguration |
| 3 | +from contextlib import contextmanager |
| 4 | +import os |
| 5 | + |
| 6 | +required_conan_version = ">=1.33.0" |
| 7 | + |
| 8 | + |
| 9 | +class CityhashConan(ConanFile): |
| 10 | + name = "cityhash" |
| 11 | + description = "CityHash, a family of hash functions for strings." |
| 12 | + license = "MIT" |
| 13 | + topics = ("conan", "cityhash", "hash") |
| 14 | + homepage = "https://github.com/google/cityhash" |
| 15 | + url = "https://github.com/conan-io/conan-center-index" |
| 16 | + |
| 17 | + settings = "os", "arch", "compiler", "build_type" |
| 18 | + options = { |
| 19 | + "shared": [True, False], |
| 20 | + "fPIC": [True, False], |
| 21 | + } |
| 22 | + default_options = { |
| 23 | + "shared": False, |
| 24 | + "fPIC": True, |
| 25 | + } |
| 26 | + |
| 27 | + _autotools = None |
| 28 | + |
| 29 | + @property |
| 30 | + def _source_subfolder(self): |
| 31 | + return "source_subfolder" |
| 32 | + |
| 33 | + def config_options(self): |
| 34 | + if self.settings.os == "Windows": |
| 35 | + del self.options.fPIC |
| 36 | + |
| 37 | + def configure(self): |
| 38 | + if self.options.shared: |
| 39 | + del self.options.fPIC |
| 40 | + |
| 41 | + def validate(self): |
| 42 | + if self.settings.compiler == "Visual Studio" and self.options.shared: |
| 43 | + raise ConanInvalidConfiguration("cityhash does not support shared builds with Visual Studio") |
| 44 | + |
| 45 | + def build_requirements(self): |
| 46 | + self.build_requires("libtool/2.4.6") |
| 47 | + if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH"): |
| 48 | + self.build_requires("msys2/cci.latest") |
| 49 | + |
| 50 | + def source(self): |
| 51 | + tools.get(**self.conan_data["sources"][self.version], |
| 52 | + destination=self._source_subfolder, strip_root=True) |
| 53 | + |
| 54 | + @contextmanager |
| 55 | + def _build_context(self): |
| 56 | + if self.settings.compiler == "Visual Studio": |
| 57 | + with tools.vcvars(self.settings): |
| 58 | + env = { |
| 59 | + "CC": "cl -nologo", |
| 60 | + "CXX": "cl -nologo", |
| 61 | + "LD": "link -nologo", |
| 62 | + "AR": "{} lib".format(tools.unix_path(self.deps_user_info["automake"].ar_lib)), |
| 63 | + } |
| 64 | + with tools.environment_append(env): |
| 65 | + yield |
| 66 | + else: |
| 67 | + yield |
| 68 | + |
| 69 | + def _configure_autotools(self): |
| 70 | + if self._autotools: |
| 71 | + return self._autotools |
| 72 | + self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) |
| 73 | + self._autotools.libs = [] |
| 74 | + yes_no = lambda v: "yes" if v else "no" |
| 75 | + args = [ |
| 76 | + "--enable-static={}".format(yes_no(not self.options.shared)), |
| 77 | + "--enable-shared={}".format(yes_no(self.options.shared)), |
| 78 | + ] |
| 79 | + if self.settings.compiler == "Visual Studio": |
| 80 | + self._autotools.cxx_flags.append("-EHsc") |
| 81 | + self._autotools.flags.append("-FS") |
| 82 | + self._autotools.configure(configure_dir=self._source_subfolder, args=args) |
| 83 | + return self._autotools |
| 84 | + |
| 85 | + def build(self): |
| 86 | + with tools.chdir(self._source_subfolder): |
| 87 | + self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows) |
| 88 | + with self._build_context(): |
| 89 | + autotools = self._configure_autotools() |
| 90 | + autotools.make() |
| 91 | + |
| 92 | + def package(self): |
| 93 | + self.copy("COPYING", dst="licenses", src=self._source_subfolder) |
| 94 | + with self._build_context(): |
| 95 | + autotools = self._configure_autotools() |
| 96 | + autotools.install() |
| 97 | + tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") |
| 98 | + tools.rmdir(os.path.join(self.package_folder, "share")) |
| 99 | + |
| 100 | + def package_info(self): |
| 101 | + self.cpp_info.libs = ["cityhash"] |
0 commit comments