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


class MfwMapRecipe(ConanFile):
    name = "mfw-map"
    package_type = "library"
    user = "aurora"

    # Optional metadata
    license = "The 3-Clause BSD License"
    author = "Vladislav Larionov <vladislav.larionov@fruct.org>"
    url = "https://hub.mos.ru/auroraos/libraries/mfw-map"
    description = "The MfwMap plugin allows users to display maps based on data, " \
    "either online or offline. User can draw a variety of objects on the map, " \
    "interact with them, and style them according to their preferences."
    topics = ("map", "mfw")

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

    def requirements(self):
        self.requires("maplibre-native/5.2.0@aurora", transitive_headers=True)
        self.requires("boost/1.85.0@aurora", transitive_headers=True)

    def source(self):
        git = Git(self)
        git.clone(url="https://gitlab.com/omprussia/libraries/mfw-map.git", target=".")
        branch = self.conan_data["sources"][self.version]["branch"]
        git.checkout(commit=branch)

    def layout(self):
        cmake_layout(self)

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        tc.cache_variables['MFW_INSTALL_PATH'] = os.path.join(self.package_folder, "qmlplugins", "MfwMap")
        tc.generate()

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

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

    def package_info(self):
        self.cpp_info.libs = ["MfwMap"]
        self.cpp_info.includedirs = []
        self.cpp_info.libdirs = ["qmlplugins/MfwMap"]




