mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.13k stars 516 forks source link

Generate only added headers #1755

Open deadlocklogic opened 1 year ago

deadlocklogic commented 1 year ago

Consider:

module.Headers.Add("Test1.h");
module.Headers.Add("Test2.h");

Now if Test2.h includes Test3.h then we will have 3 TranslationUnit for generation. Is there a way to restrict the generation to Test1.h/Test2.h only? (I know that Test3.h is necessary for symbol resolution but I don't want it to be generated as output).

tritao commented 1 year ago

IIRC by default it should only work as you want, it only generates translation units added by the user.

Are you using the default driver for generation or you write your own?

EDIT: See here: https://github.com/mono/CppSharp/blob/main/src/Generator/Generator.cs#L157C47-L157C59 https://github.com/mono/CppSharp/blob/main/src/AST/ClassExtensions.cs#L181

tritao commented 1 year ago

Ok, so to achieve what you want I think you need to set unit.GenerationKind. If you want to add an option to change the default generation behaviour then I think that would be fine.

deadlocklogic commented 1 year ago

Are you using the default driver for generation or you write your own?

No I am testing using the default Driver and GeneratorKind.CPlusPlus. I find it an issue because I don't want to generate code for third-party dependencies. (Because they might have a separate external modular generation).

deadlocklogic commented 1 year ago

@tritao Could we add for any unit not provided explicitly in Module.Headers and generated by the parser, an option in the DriverOptions to mark its TranslationUnit.GenerationKind to GenerationKind.Internal?

tritao commented 1 year ago

@tritao Could we add for any unit not provided explicitly in Module.Headers and generated by the parser, an option in the DriverOptions to mark its TranslationUnit.GenerationKind to GenerationKind.Internal?

Sure, I think that's ok.