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


class GeocoderNlpTkrzwRecipe(ConanFile):
    name = "geocoder-nlp-tkrzw"
    user = "aurora"
    package_type = "library"

    # Optional metadata
    license = "MIT"
    author = "Vladislav Larionov <vladislav.larionov@fruct.org>"
    url = "https://hub.mos.ru/auroraos/libraries/geocoder-nlp-tkrzw"
    description = "Geocoder library based on libpostal normalization of libosmscout generated database"
    topics = ("geocoder")

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

    exports = "CMakeLists.txt"

    def requirements(self):
        self.requires("marisa/0.2.6@aurora", transitive_headers=True)
        self.requires("tkrzw/1.72.0@aurora", transitive_headers=True)
        self.requires("postal/1.1@aurora")
        self.requires("boost/1.85.0@aurora", transitive_headers=True)

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

    def layout(self):
        cmake_layout(self)

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        tc.generate()

    def build(self):
        copy(self, "CMakeLists.txt", src=os.path.join(self.recipe_folder), dst=self.source_folder)
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["geocoder-nlp-tkrzw"]

