Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CppSharp Generator code for generating Spout.cs #1

Closed
microdee opened this issue Jul 27, 2020 · 2 comments
Closed

CppSharp Generator code for generating Spout.cs #1

microdee opened this issue Jul 27, 2020 · 2 comments

Comments

@microdee
Copy link

Hi! I noticed CppSharp was used to generate Interop/Spout.cs. Is it possible to include the code generator project as well in this or a different repo?

@ilharp
Copy link
Contributor

ilharp commented Jul 28, 2020

Here's the code.

I will not add the code below into this repo or create a new repo to store this code. One reason is that it's simple and anyone can write such generator code following the Generating Bindings Tutorial provided by CppSharp. Another reason is that the code CppSharp generated will not work properly. There's still a lot of things that need to be fixed in the generated code. So I think using the Spout.NET NuGet Package may be the better solution than generating the code yourself.

But I will pin this issue for latecomers. Feel free to comment below if you have more questions.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;

namespace CXPlayground
{
    public class CppSharpLibrary : ILibrary
    {
        public void Preprocess(Driver driver, ASTContext ctx)
        {
        }

        public void Postprocess(Driver driver, ASTContext ctx)
        {
        }

        public const string SpoutSourcePath = @"D:\SpoutSDK\";

        public void Setup(Driver driver)
        {
            var options = driver.Options;
            options.GeneratorKind = GeneratorKind.CSharp;
            options.OutputDir = $"{SpoutSourcePath}output";
            options.Compilation.Platform = TargetPlatform.Windows;
            options.Compilation.VsVersion = VisualStudioVersion.Latest;
            options.GenerateFinalizers = true;
            options.GenerateSingleCSharpFile = true;
            var module = options.AddModule("Spout.Interop");
            module.IncludeDirs.Add($"{SpoutSourcePath}include");
            foreach (string file in Directory.GetFiles($"{SpoutSourcePath}include"))
                if (file.EndsWith(".h"))
                    module.Headers.Add(file);
            module.LibraryDirs.Add($"{SpoutSourcePath}lib");
            module.Libraries.Add("Spout.dll");
        }

        public void SetupPasses(Driver driver)
        {
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ConsoleDriver.Run(new CppSharpLibrary());
        }
    }
}

@ilharp ilharp closed this as completed Jul 28, 2020
@ilharp ilharp pinned this issue Jul 28, 2020
@microdee
Copy link
Author

Sure thing I'd use the nuget package when needed, I was just curious to see how did that go. Thanks for the info, great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants