phoboslab / wipeout-rewrite

2.61k stars 203 forks source link

Use Xmake to build on Windows #52

Open star-hengxing opened 10 months ago

star-hengxing commented 10 months ago

I make a simple xmake.lua file to build on windows with mingw.

set_project("wipeout-rewrite")
set_languages("c11")

set_allowedplats("linux", "macosx", "mingw", "wasm")

if is_host("windows") then
    set_config("plat", "mingw")
end

option("platform")
    set_default("sdl")
    set_showmenu(true)
    set_description("Graphics platform to handle input/output")
    set_values("sdl", "sokol")
option_end()

option("opengl")
    set_default(false)
    set_showmenu(true)
    set_description("Graphics rendering backend")
option_end()

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

if is_config("platform", "sdl") then
    add_requires("libsdl")
elseif is_config("platform", "sokol") then
    if is_plat("linux") then
        add_requires("libx11", "libxi", "libxcursor")
    end
end

if has_config("opengl") then
    add_requires("glew")
end

target("wipeout")
    set_kind("binary")
    add_files("src/wipeout/*.c",
              "src/utils.c",
              "src/types.c",
              "src/system.c",
              "src/mem.c",
              "src/input.c")

    if is_plat("windows", "mingw") then
        add_defines("_USE_MATH_DEFINES")
    elseif is_plat("linux") then
        add_syslinks("pthread")
    elseif is_plat("macosx") then
        add_frameworks("Foundation")
        if is_config("platform", "sokol") then
            add_frameworks("Cocoa", "QuartzCore", "AudioToolbox")
        end
    end

    if has_config("opengl") then
        add_defines("RENDERER_GL")
        add_files("src/render_gl.c")
        add_packages("glew")
    else
        add_defines("RENDERER_SOFTWARE")
        add_files("src/render_software.c")
    end

    if is_config("platform", "sdl") then
        add_files("src/platform_sdl.c")
        add_packages("libsdl")
    elseif is_config("platform", "sokol") then
        add_files("src/platform_sokol.c")
        add_defines("RENDERER_GL")
        if is_plat("linux") then
            add_packages("libx11", "libxi", "libxcursor")
        elseif is_plat("mingw") then
            add_syslinks("gdi32", "ole32")
        end
    end

Try

xmake f -c -y --mingw=path/to/mingw
xmake

I don't have other systems (linux/macos) to test it on, so hopefully someone can improve it.