add_rules("mode.debug", "mode.release")

add_defines("TD_IMPL_OPENGL_LOADER_GLEW")
add_requires("libsdl2", "zlib", "glew")

set_languages("c++17")

target("TowerDefenseData")
    set_kind("static")

    add_includedirs("include")
    add_files("src/td/**.cpp")

    add_packages("zlib")
    
    add_links("pthread")
    add_cxflags("-pthread")

    if is_os("windows") then
        add_links("ws2_32") -- link network stuff
    end

    if is_mode("debug") then
        if is_os("linux") then
            add_links("dw")
        end
        if is_os("windows") then
            add_links("dbghelp", "psapi", "kernel32", "msvcr90")
        end
        add_cxflags("-pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=1 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wno-unused")
    end





target("TowerDefense")
    add_deps("TowerDefenseData")

    set_kind("static")
    add_files("src/server/**.cpp")
    add_includedirs("include")





target("TowerDefenseServer")
    add_deps("TowerDefense")

    set_kind("binary")
    add_files("src/ServerMain.cpp")
    add_includedirs("include")





target("TowerDefenseClient")
    add_deps("TowerDefense")
    
    set_kind("binary")
    add_files("src/ClientMain.cpp", "src/client/**.cpp")
    add_includedirs("include")

    add_packages("libsdl2", "glew", "opengl")

    -- run windows program with wine on linux
    if is_host("linux") and is_os("windows") then
        on_run(function(target)
            os.cd("test")
            os.execv("wine", {target:targetfile()})
        end)
    end
