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

required_conan_version = ">=1.33.0"

class Bigfoot(ConanFile):
    name = "bigfoot"
    homepage = "https://git.romainboullard.com/BigfootDev/Bigfoot"
    description = "Bigfoot is a 3D game engine written in C++"
    topics = ("game engine", "3d")
    license = "MIT"
    version = "0.1.0"

    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {
        "shared": [True, False],
        "fPIC": [True, False],
        "asan": [True, False],
        "coverage": [True, False],
        "build_tests": [True, False],
        "build_benchmarks": [True, False],
        "tracy": [True, False],
        "vulkan": [True, False]
        }
    default_options = {
        "shared": False,
        "fPIC": True,
        "asan": False,
        "coverage": False,
        "build_tests": False,
        "build_benchmarks": False,
        "tracy": False,
        "vulkan": True,
        }
    
    generators = "CMakeDeps"

    def layout(self):
        cmake_layout(self)

    def configure(self):
        if self.settings.os == "Windows":
            del self.options.fPIC

        if(self.options.asan):
            self.options["mimalloc"].asan = True

        self.options['stduuid'].with_cxx20_span = True
        self.options['flatbuffers'].header_only = True

        if(self.options.tracy):
            self.options["tracy"].on_demand = True

        if(self.options.vulkan):
            self.options["spirv-cross"].exceptions = False
            
    def build_requirements(self):
        self.tool_requires("bin2cpp/1.0.0@bigfootdev/main")

    def requirements(self):
        self.requires("eastl/3.27.01@bigfootdev/main", transitive_headers=True)
        self.requires("unordered_dense/4.8.1@bigfootdev/main", transitive_headers=True)
        self.requires("mimalloc/3.3.2@bigfootdev/main", transitive_headers=True)
        self.requires("stduuid/1.2.3@bigfootdev/main", transitive_headers=True)
        self.requires("sqlite3/3.53.3@bigfootdev/main", transitive_headers=True)
        self.requires("rapidhash/3.0@bigfootdev/main", transitive_headers=True)
        self.requires("effolkronium-random/1.5.0", transitive_headers=True)
        self.requires("flatbuffers/25.12.19-2026-02-06-03fffb2-bigfoot@bigfootdev/main", transitive_headers=True)

        if(self.settings.build_type == "RelWithDebInfo" or self.settings.build_type == "Debug"):
            self.requires("quill/12.0.0", transitive_headers=True)

        if(self.options.tracy):
            self.requires("tracy/0.13.1", transitive_headers=True)

        self.requires("glm/1.0.3@bigfootdev/main", transitive_headers=True)
        self.requires("lodepng/cci.20260210@bigfootdev/main", transitive_headers=True)
        self.requires("imgui/1.92.8-docking@bigfootdev/main", transitive_headers=True)

        if(self.options.vulkan):
            self.requires("vulkan-headers/1.4.341.0@bigfootdev/main", override=True)
            self.requires("vulkan-memory-allocator/3.3.0@bigfootdev/main")

        if(self.options.build_tests):
            self.test_requires("gtest/1.17.0")
            self.test_requires("pixelmatch-cpp17/1.0.3@bigfootdev/main")

        if(self.options.build_benchmarks):
            self.requires("benchmark/1.9.5")

    def generate(self):
        tc = CMakeToolchain(self)
        
        tc.variables["ASAN"] = self.options.asan
        tc.variables["COVERAGE"] = self.options.coverage
        tc.variables["BUILD_TESTS"] = self.options.build_tests
        tc.variables["BUILD_BENCHMARKS"] = self.options.build_benchmarks
        tc.variables["TRACY"] = self.options.tracy
        tc.variables["VULKAN"] = self.options.vulkan

        tc.generate()

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