import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir


class crc32cConan(ConanFile):
    name = "crc32c"
    package_type = "library"
    user = "aurora"
    
    # Optional metadata
    license = "CRC32C implementation with support for CPU-specific acceleration instructions"
    author = "Angelica Volkova <angelica.volkova@fruct.org>"
    url = "https://gitverse.ru/auroraos/mirror_crc32c"
    description = ""
    topics = ("", "", "")

    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True]}

    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["BUILD_TESTING"] = "OFF"
        tc.variables["CRC32C_BUILD_TESTS"] = "OFF"
        tc.variables["CRC32C_BUILD_BENCHMARKS"] = "OFF"
        tc.variables["CRC32C_USE_GLOG"] = "OFF"
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
        cmake = CMake(self)
        cmake.install()
        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

    def package_info(self):
        self.cpp_info.set_property("cmake_file_name", "Crc32c")
        self.cpp_info.set_property("cmake_target_name", "Crc32c::crc32c")
        self.cpp_info.set_property("pkg_config_name", "crc32c")
        self.cpp_info.libs = ["crc32c"]
