From a00d4f9349817f25898a1a89ab5cd201cc5f1836 Mon Sep 17 00:00:00 2001 From: Speykious Date: Sun, 30 Jan 2022 19:45:55 +0100 Subject: [PATCH] Create basic CppSharp generator --- ...NativeFileDialogs.CppSharpGenerator.csproj | 14 +++++++ .../NativeFileDialogsLibrary.cs | 39 +++++++++++++++++++ .../Program.cs | 8 ++++ NativeFileDialogs.NET.sln | 36 ++++++++++------- 4 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 NativeFileDialogs.CppSharpGenerator/NativeFileDialogs.CppSharpGenerator.csproj create mode 100644 NativeFileDialogs.CppSharpGenerator/NativeFileDialogsLibrary.cs create mode 100644 NativeFileDialogs.CppSharpGenerator/Program.cs diff --git a/NativeFileDialogs.CppSharpGenerator/NativeFileDialogs.CppSharpGenerator.csproj b/NativeFileDialogs.CppSharpGenerator/NativeFileDialogs.CppSharpGenerator.csproj new file mode 100644 index 0000000..749bc02 --- /dev/null +++ b/NativeFileDialogs.CppSharpGenerator/NativeFileDialogs.CppSharpGenerator.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + disable + enable + + + + + + + diff --git a/NativeFileDialogs.CppSharpGenerator/NativeFileDialogsLibrary.cs b/NativeFileDialogs.CppSharpGenerator/NativeFileDialogsLibrary.cs new file mode 100644 index 0000000..ea5317d --- /dev/null +++ b/NativeFileDialogs.CppSharpGenerator/NativeFileDialogsLibrary.cs @@ -0,0 +1,39 @@ +// Copyright (c) Speykious +// This file is part of NativeFileDialogs.NET. +// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details. + +using CppSharp; +using CppSharp.AST; +using CppSharp.Generators; +using CppSharp.Passes; + +namespace NativeFileDialogs.CppSharpGenerator; + +public class NativeFileDialogsLibrary : ILibrary +{ + private const string lib_name = "NativeFileDialogs"; + + public void Setup(Driver driver) + { + DriverOptions options = driver.Options; + options.GeneratorKind = GeneratorKind.CSharp; + options.OutputDir = $"../{lib_name}.AutoGen"; + var module = options.AddModule("nfd"); + module.IncludeDirs.Add(@"../nativefiledialog-extended/src/include"); + module.Headers.Add("nfd.h"); + module.OutputNamespace = $"{lib_name}.AutoGen"; + } + + public void SetupPasses(Driver driver) + { + driver.Context.TranslationUnitPasses.RenameDeclsUpperCase(RenameTargets.Any); + } + + public void Preprocess(Driver driver, ASTContext ctx) + { + } + + public void Postprocess(Driver driver, ASTContext ctx) + { + } +} diff --git a/NativeFileDialogs.CppSharpGenerator/Program.cs b/NativeFileDialogs.CppSharpGenerator/Program.cs new file mode 100644 index 0000000..8a39144 --- /dev/null +++ b/NativeFileDialogs.CppSharpGenerator/Program.cs @@ -0,0 +1,8 @@ +// Copyright (c) Speykious +// This file is part of NativeFileDialogs.NET. +// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details. + +using CppSharp; +using NativeFileDialogs.CppSharpGenerator; + +ConsoleDriver.Run(new NativeFileDialogsLibrary()); diff --git a/NativeFileDialogs.NET.sln b/NativeFileDialogs.NET.sln index b936964..7b34736 100644 --- a/NativeFileDialogs.NET.sln +++ b/NativeFileDialogs.NET.sln @@ -1,14 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30114.105 -MinimumVisualStudioVersion = 10.0.40219.1 -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeFileDialogs.CppSharpGenerator", "NativeFileDialogs.CppSharpGenerator\NativeFileDialogs.CppSharpGenerator.csproj", "{25BA3FA4-354F-4F27-85AB-7130BB65C957}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {25BA3FA4-354F-4F27-85AB-7130BB65C957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25BA3FA4-354F-4F27-85AB-7130BB65C957}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25BA3FA4-354F-4F27-85AB-7130BB65C957}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25BA3FA4-354F-4F27-85AB-7130BB65C957}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal