from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get
import os

required_conan_version = ">=1.53.0"


class FarmhashConan(ConanFile):
    name = "farmhash"
    user = "aurora"
    description = "A family of hash functions"
    topics = ("hash", "google", "family")
    license = "MIT"
    homepage = "https://github.com/google/farmhash"
    url = "https://gitverse.ru/auroraos/mirror_conan-center-index"

    package_type = "library"
    settings = "os", "arch", "compiler", "build_type"
    options = {
        "shared": [True, False],
        "no_builtin_expect": [True, False],
    }
    default_options = {
        "shared": False,
        "no_builtin_expect": False,
    }

    exports_sources = "CMakeLists.txt"

    def layout(self):
        cmake_layout(self, src_folder="src")

    def source(self):
        get(self, **self.conan_data["sources"][self.version], strip_root=True)

    def generate(self):
        tc = CMakeToolchain(self)
        tc.variables["FARMHASH_SRC_DIR"] = self.source_folder.replace("\\", "/")
        tc.variables["FARMHASH_NO_BUILTIN_EXPECT"] = self.options.no_builtin_expect
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
        cmake.build()

    def package(self):
        copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["farmhash"]
