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

required_conan_version = ">=1.60.0 <2.0 || >=2.0.5"


class adaRecipe(ConanFile):
    name = "ada"
    package_type = "library"
    user = "aurora"

    # Optional metadata
    homepage = "https://ada-url.com"
    author = "Daniil Markevich <d.markevich@omp.ru>"
    url = "https://gitverse.ru/auroraos/mirror_ada"
    license = "Apache License 2.0"
    description = "Ada is a fast and spec-compliant URL parser written in C++."
    topics = ("ada", "url", "parser")

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

    def layout(self):
        cmake_layout(self)

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

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        tc.variables["BUILD_TESTING"] = False
        tc.variables["ADA_TOOLS"] = False
        tc.generate()

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

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

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