Skip to content

Commit

Permalink
Switch to premake for project generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomspilman committed Aug 26, 2024
1 parent 5d2cd20 commit 5c1dfa0
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 82 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ jobs:
with:
dotnet-version: '8.0.x'

- name: Setup Xmake
uses: xmake-io/github-action-setup-xmake@v1
- name: Add msbuild to PATH
if: runner.os == 'Windows'
uses: microsoft/[email protected]

- name: Setup Premake5
uses: abel0b/[email protected]
with:
xmake-version: latest
version: "5.0.0-beta2"

- name: Setup Java
uses: actions/setup-java@v4
Expand Down
13 changes: 0 additions & 13 deletions build/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,4 @@ out IEnumerable<string> processOutput

return processOutput.Any(match => match.StartsWith($"{workload} "));
}

public int XMake(string workingDir, params string[] args)
{
return this.StartProcess(
"xmake",
new ProcessSettings()
{
WorkingDirectory = workingDir,
Arguments = string.Join(" ", args),
RedirectStandardOutput = false,
}
);
}
}
26 changes: 16 additions & 10 deletions build/BuildFrameworksTasks/BuildDesktopVKTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ public sealed class BuildDesktopVKTask : FrostingTask<BuildContext>

public override void Run(BuildContext context)
{
int exit = context.XMake(@"src\monogame\", "f -m debug -v -y");
if (exit < 0)
throw new Exception($"Setting debug config failed! {exit}");
// TODO: This should be moved to its own seperate
// build process so that it doesn't run on all MG builds.
{
var buildDir = "src/monogame/external/sdl2/sdl/build";
context.CreateDirectory(buildDir);
context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "-A x64 -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ../" });
context.StartProcess("msbuild", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "SDL2.sln /p:Configuration=Release /p:Platform=x64" });
}

exit = context.XMake(@"src\monogame\", "-r");
// Generate the native projects.
var exit = context.StartProcess("premake5", new ProcessSettings { WorkingDirectory = "src/monogame", Arguments = "clean" });
if (exit < 0)
throw new Exception($"Rebuild debug failed! {exit}");

exit = context.XMake(@"src\monogame\", "f -m release -v -y");
throw new Exception($"Setting Premake clean failed! {exit}");
exit = context.StartProcess("premake5", new ProcessSettings { WorkingDirectory = "src/monogame", Arguments = "--os=windows --verbose vs2022" });
if (exit < 0)
throw new Exception($"Setting release config failed! {exit}");
throw new Exception($"Setting Premake generation failed! {exit}");

exit = context.XMake(@"src\monogame\", "-r");
// Build it.
exit = context.StartProcess("msbuild", new ProcessSettings { WorkingDirectory = "src/monogame", Arguments = "monogame.sln /p:Configuration=Release /p:Platform=x64" });
if (exit < 0)
throw new Exception($"Rebuild release failed! {exit}");
throw new Exception($"Setting build failed! {exit}");
}
}
8 changes: 0 additions & 8 deletions src/monogame/build_windows.bat

This file was deleted.

2 changes: 1 addition & 1 deletion src/monogame/make_windows_solution.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
xmake project -m "Release,Debug" -k vsxmake
premake5 vs2022


109 changes: 109 additions & 0 deletions src/monogame/premake5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
-- MonoGame - Copyright (C) MonoGame Foundation, Inc
-- This file is subject to the terms and conditions defined in
-- file 'LICENSE.txt', which is part of this source code package.

function common(project_name)

platform_target_path = "../../Artifacts/monogame.native/%{cfg.system}/" .. project_name .. "/%{cfg.buildcfg}"

kind "SharedLib"
language "C++"
architecture "x64"
defines { "DLL_EXPORT" }
targetdir( platform_target_path )
targetname "monogame.native"

files
{
"include/**.h",
"common/**.h",
"common/**.cpp",
}
includedirs
{
"include",
}

end

-- SDL is supported on all desktop platforms.
function sdl2()

defines { "MG_SDL2" }

files
{
"sdl/**.h",
"sdl/**.cpp",
}

includedirs
{
"external/sdl2/sdl/include",
}

filter { "system:windows" }
links
{
"external/sdl2/sdl/build/Release/SDL2-static.lib",
"winmm",
"imm32",
"user32",
"gdi32",
"advapi32",
"setupapi",
"ole32",
"oleaut32",
"version",
"shell32"
}

end

-- Vulkan is supported for all desktop platforms.
function vulkan()

defines { "MG_VULKAN" }

files
{
"vulkan/**.h",
"vulkan/**.cpp",
}

filter "system:windows"
files { "vulkan/**.rc", }

includedirs
{
"external/vulkan-headers/include",
"external/volk",
"external/vma/include",
}

end

function configs()

filter "configurations:Debug"
defines { "DEBUG" }
symbols "On"

filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"

end

workspace "monogame"
configurations { "Debug", "Release" }

project "desktopvk"
common("desktopvk")
sdl2()
vulkan()
configs()


project "windowsdx"
common("windowsdx")
4 changes: 2 additions & 2 deletions src/monogame/vulkan/MGG_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include <vulkan/vulkan.h>

#define VOLK_IMPLEMENTATION
#include <Volk/volk.h>
#include <volk.h>

#define VMA_IMPLEMENTATION
#define VMA_STATIC_VULKAN_FUNCTIONS 1
#include <vma/vk_mem_alloc.h>
#include <vk_mem_alloc.h>

#if defined(MG_SDL2)
#include <SDL_vulkan.h>
Expand Down
45 changes: 0 additions & 45 deletions src/monogame/xmake.lua

This file was deleted.

0 comments on commit 5c1dfa0

Please sign in to comment.