Implement Wayland protocols module and file generation

This commit is contained in:
2025-01-02 22:33:05 +02:00
parent 37979e452a
commit ef0c2a2785
4 changed files with 131 additions and 0 deletions

View File

@@ -101,6 +101,8 @@ public class Platform : EngineModule
options.SourcePaths.Add(Path.Combine(FolderPath, "SDL")); options.SourcePaths.Add(Path.Combine(FolderPath, "SDL"));
break; break;
} }
if (options.Platform.Target == TargetPlatform.Linux)
options.PublicDependencies.Add("Wayland");
} }
if (options.Target.IsEditor) if (options.Target.IsEditor)
{ {

29
Source/ThirdParty/Wayland/LICENSE.txt vendored Normal file
View File

@@ -0,0 +1,29 @@
Copyright © 2008-2012 Kristian Høgsberg
Copyright © 2010-2012 Intel Corporation
Copyright © 2011 Benjamin Franzke
Copyright © 2012 Collabora, Ltd.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
---
The above is the version of the MIT "Expat" License used by X.org:
http://cgit.freedesktop.org/xorg/xserver/tree/COPYING

View File

@@ -0,0 +1,37 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.IO;
using Flax.Build;
using Flax.Build.NativeCpp;
/// <summary>
/// https://gitlab.freedesktop.org/wayland/wayland-protocolsk
/// </summary>
public class Wayland : ThirdPartyModule
{
/// <inheritdoc />
public override void Init()
{
base.Init();
LicenseType = LicenseTypes.MIT;
LicenseFilePath = "LICENSE.txt";
// Merge third-party modules into engine binary
BinaryModuleName = "FlaxEngine";
}
/// <inheritdoc />
public override void Setup(BuildOptions options)
{
base.Setup(options);
if (options.Platform.Target != TargetPlatform.Linux)
throw new InvalidPlatformException(options.Platform.Target);
// Include generated protocol files for dependency
options.PublicIncludePaths.Add(Path.Combine(FolderPath, "include"));
options.SourceFiles.AddRange(Directory.GetFiles(FolderPath, "*.cpp", SearchOption.TopDirectoryOnly));
}
}

View File

@@ -0,0 +1,63 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.IO;
using Flax.Build;
namespace Flax.Deps.Dependencies
{
/// <summary>
/// Wayland protocols.
/// </summary>
/// <seealso cref="Flax.Deps.Dependency" />
class Wayland : Dependency
{
/// <inheritdoc />
public override TargetPlatform[] Platforms
{
get
{
switch (BuildPlatform)
{
case TargetPlatform.Linux:
return new[]
{
TargetPlatform.Linux,
};
default: return new TargetPlatform[0];
}
}
}
/// <inheritdoc />
public override void Build(BuildOptions options)
{
var dstPath = Path.Combine(options.ThirdPartyFolder, "Wayland");
var protocolsPath = Path.Combine(dstPath, "protocols");
var includePath = Path.Combine(dstPath, "include");
foreach (var platform in options.Platforms)
{
BuildStarted(platform);
switch (platform)
{
case TargetPlatform.Linux:
if (!Directory.Exists(Path.Combine(includePath, "wayland")))
Directory.CreateDirectory(Path.Combine(includePath, "wayland"));
string[] protocolFiles = Directory.GetFiles(protocolsPath, "*.xml", SearchOption.TopDirectoryOnly);
foreach (var protocolPath in protocolFiles)
{
var headerFile = Path.ChangeExtension(Path.GetFileName(protocolPath), "h");
var glueFile = Path.ChangeExtension(Path.GetFileName(protocolPath), "cpp");
Utilities.Run("wayland-scanner", $"client-header {protocolPath} include/wayland/{headerFile}", null, dstPath, Utilities.RunOptions.DefaultTool);
Utilities.Run("wayland-scanner", $"private-code {protocolPath} {glueFile}", null, dstPath, Utilities.RunOptions.DefaultTool);
}
break;
}
}
Utilities.FileCopy("/usr/share/licenses/wayland/COPYING", Path.Combine(dstPath, "LICENSE.txt"));
}
}
}