#!/usr/bin/env python

IMGUI_GODOT_INCLUDE = "../../../addons/imgui-godot/include"
IMGUI_TAG = "v1.91.6-docking"

import os
import subprocess

if not os.path.exists("godot-cpp"):
    subprocess.call(
        "git clone -b 4.5 https://github.com/godotengine/godot-cpp", shell=True
    )

if not os.path.exists("imgui"):
    subprocess.call("git clone -b docking https://github.com/ocornut/imgui", shell=True)
    subprocess.call(f"git -C imgui checkout {IMGUI_TAG}", shell=True)

if not os.path.exists("implot"):
    subprocess.call("git clone https://github.com/epezent/implot", shell=True)

if not os.path.exists("imgui_markdown"):
    subprocess.call(
        "git clone https://github.com/enkisoftware/imgui_markdown", shell=True
    )

env = SConscript("godot-cpp/SConstruct")
env = env.Clone()

env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")

# Dear ImGui
sources += Glob(f"imgui/*.cpp")
env.Append(CPPDEFINES=['IMGUI_USER_CONFIG="\\"imconfig-godot.h\\""'])
env.Append(CPPPATH=["imgui", IMGUI_GODOT_INCLUDE])

# ImPlot
sources += Glob(f"implot/*.cpp")
env.Append(CPPPATH=["implot"])

# imgui_markdown
env.Append(CPPPATH=["imgui_markdown"])

if env["platform"] == "macos":
    library = env.SharedLibrary(
        "project/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(
            env["platform"], env["target"], env["platform"], env["target"]
        ),
        source=sources,
    )
else:
    library = env.SharedLibrary(
        "project/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
        source=sources,
    )

Default(library)
