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 srtpConan(ConanFile):
    name = "libsrtp"
    package_type = "library"
    user = "aurora"
    
    # Optional metadata
    license = "BSD-3-Clause"
    author = "Angelica Volkova <angelica.volkova@fruct.org>"
    url = "https://gitverse.ru/auroraos/mirror_libsrtp"
    description = "Library for SRTP (Secure Realtime Transport Protocol)."
    topics = ("rtp", "srtp", "libsrtp")

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

    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.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_target_name", "srtp::srtp")
        self.cpp_info.set_property("cmake_file_name", "srtp")
        self.cpp_info.set_property("pkg_config_name", "libsrtp2")
        self.cpp_info.libs = ["srtp2"]
