local native = require('tundra.native')

-----------------------------------------------------------------------------------------------------------------------

local mac_opts = {
    "-Wall",
    "-Wno-switch-enum",
    "-I.", "-DPRODBG_MAC",
    -- "-Weverything", "-Werror",
    "-Wno-unknown-warning-option",
    "-Wno-c11-extensions",
    "-Wno-variadic-macros",
    "-Wno-c++98-compat-pedantic",
    "-Wno-old-style-cast",
    "-Wno-documentation",
    "-Wno-reserved-id-macro",
    "-Wno-missing-prototypes",
    "-Wno-deprecated-declarations",
    "-Wno-cast-qual",
    "-Wno-gnu-anonymous-struct",
    "-Wno-nested-anon-types",
    "-Wno-padded",
    "-Wno-c99-extensions",
    "-Wno-missing-field-initializers",
    "-Wno-weak-vtables",
    "-Wno-format-nonliteral",
    "-Wno-non-virtual-dtor",
    "-Wno-undefined-reinterpret-cast", -- generated by Qt Moc
    { "-O0", "-g"; Config = "*-*-debug" },
    { "-O3", "-g"; Config = "*-*-release" },
}

local macosx = {
    Env = {
		--QT5 = "", --, native.getenv("QT5"),
        RUST_CARGO_OPTS = {
            { "test"; Config = "*-*-*-test" },
        },

        CCOPTS =  {
            mac_opts,
        },

        CXXOPTS = {
            mac_opts,
            "-std=c++11",
        },

        SHLIBOPTS = { "-lstdc++" },
        PROGCOM = { "-lstdc++" },
    },

    Frameworks = {
        { "Cocoa" },
        { "Metal" },
        { "QuartzCore" },
        { "OpenGL" }
    },
}

-----------------------------------------------------------------------------------------------------------------------

local gcc_opts = {
    "-I.",
    "-Wno-array-bounds", "-Wno-attributes", "-Wno-unused-value",
    "-DOBJECT_DIR=\\\"$(OBJECTDIR)\\\"",
    "-Wall", "-DPRODBG_UNIX",
    "-fPIC",
    { "-O0", "-g"; Config = "*-*-debug" },
    { "-O3", "-g"; Config = "*-*-release" },
}

local gcc_env = {
    Env = {
		QT5_INC = native.getenv("QT5_INC"),
		QT5_BIN = native.getenv("QT5_BIN"),
		QT5_LIB = native.getenv("QT5_LIB"),
        RUST_CARGO_OPTS = {
            { "test"; Config = "*-*-*-test" },
        },

        CCOPTS = {
            gcc_opts,
        },

        CXXOPTS = {
            gcc_opts,
            "-std=c++11",
            "-I$(QT5_INC)",
            -- temp
            "-Isrc/prodbg",
            "-Isrc/native/external/flatbuffers/include",
        },

        SHLIBOPTS = { "-lstdc++" },
        PROGCOM = { "-lstdc++" },
    },

    ReplaceEnv = {
        QTMOC = "$(QT5_BIN)/moc",
        QTUIC = "$(QT5_BIN)/uic",
        QTRCC = "$(QT5_BIN)/rcc",
    },
}

-----------------------------------------------------------------------------------------------------------------------

local win64_opts = {
    "/DPRODBG_WIN",
    "/EHsc", "/FS", "/MT", "/W3", "/I.", "/DUNICODE", "/D_UNICODE", "/DWIN32", "/D_CRT_SECURE_NO_WARNINGS", "/wd4005", "/wd4200", "/wd4152", "/wd4996", "/wd4389", "/wd4201", "/wd4152", "/wd4996", "/wd4389",
    "\"/DOBJECT_DIR=$(OBJECTDIR:#)\"",
    { "/Od"; Config = "*-*-debug" },
    { "/O2"; Config = "*-*-release" },
}

local win64 = {
    Env = {
		QT5_INC = native.getenv("QT5_INC"),
		QT5_BIN = native.getenv("QT5_BIN"),
		QT5_LIB = native.getenv("QT5_LIB"),
        RUST_CARGO_OPTS = {
            { "test"; Config = "*-*-*-test" },
        },

        GENERATE_PDB = "1",
        CCOPTS = {
            win64_opts,
        },

        CXXOPTS = {
            win64_opts,
            "/I$(QT5_INC)",
            "/Isrc\\prodbg",
        },

        OBJCCOM = "meh",
    },

    ReplaceEnv = {
        QTMOC = "$(QT5_BIN)\\moc",
        QTUIC = "$(QT5_BIN)\\uic",
        QTRCC = "$(QT5_BIN)\\rcc",
    },
}

-----------------------------------------------------------------------------------------------------------------------

Build {
    Passes = {
        BuildTools = { Name="Build Tools", BuildOrder = 1 },
        GenerateSources = { Name="Generate Sources", BuildOrder = 2 },
    },

    Units = {
        "units.libs.lua",
        "units.misc.lua",
        "units.plugins.lua",
        "units.prodbg.lua",
    },

    Configs = {
        Config { Name = "macosx-clang", DefaultOnHost = "macosx", Inherit = macosx, Tools = { "clang-osx", "rust", "qt" } },
        Config { Name = "win64-msvc", DefaultOnHost = { "windows" }, Inherit = win64, Tools = { "msvc-vs2019", "rust", "qt" } },
        Config { Name = "linux-gcc", DefaultOnHost = { "linux" }, Inherit = gcc_env, Tools = { "gcc", "rust", "qt" } },
    },

    IdeGenerationHints = {
        Msvc = {
            -- Remap config names to MSVC platform names (affects things like header scanning & debugging)
            PlatformMappings = {
                ['win64-msvc'] = 'x64',
            },
            -- Remap variant names to MSVC friendly names
            VariantMappings = {
                ['release']    = 'Release',
                ['debug']      = 'Debug',
            },
        },

        MsvcSolutions = {
            ['ProDBG.sln'] = { } -- will get everything
        },

    },

    Variants = { "debug", "release" },
    SubVariants = { "default", "test" },
}

-- vim: ts=4:sw=4:sts=4

