from conan.tools.scm import Git
from conan import ConanFile, tools
from conan.tools.cmake import CMakeToolchain, CMake
from conan.tools.layout import basic_layout
from conan.tools.files import patch, copy
import os

class bluezQtConan(ConanFile):
    name = "bluez-qt"
    package_type = "library"
    user = "aurora"

    # Optional metadata
    license = "LGPL v3"
    author = "Evgeniy Samohin <e.samohin@omp.ru>"
    url = "https://gitverse.ru/auroraos/mirror_bluez-qt"
    description = "Qt wrapper for Bluez 5 DBus API."

    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True]}
    exports = '*.patch'

    def source(self):
        git = Git(self)
        git.clone(url="https://github.com/KDE/bluez-qt.git", target=".")
        branch = self.conan_data["sources"][self.version]["commit"]
        git.checkout(commit=branch)
        backport_to_qt = os.path.join(self.recipe_folder, "patches", "01-backport-to-qt-5.6.3.patch")
        patch(self, patch_file=backport_to_qt)
    
    def layout(self):
        basic_layout(self)

    def generate(self):
        cmake = CMakeToolchain(self)
        cmake.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure(variables={"CMAKE_BUILD_TYPE": "Release",
                                   "BUILD_TESTING": "OFF"})
        cmake.build()

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

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