bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

Add properties jniinclude and jnicinclude #689

Closed HGuillemet closed 8 months ago

HGuillemet commented 1 year ago

Add new properties for declaring separately the list of headers to parse and the list of headers to include in JNI code.

saudet commented 1 year ago

This looks OK, but I don't think I'm going to merge it because I realized we can already do what you want by modifying the platform.include property inside an init() method like this one here: https://github.com/bytedeco/javacpp-presets/blob/master/pytorch/src/main/java/org/bytedeco/pytorch/presets/torch.java#L1795

In your case, I'd put the top-level header files in @Platform(include=... and leave it there when init() gets called by the Generator, but modify it as required when it gets called by the Parser. We can literally code anything in there, including calling clang from the LLVM presets, so it's a lot more flexible than an annotation value.

HGuillemet commented 1 year ago

I considered this option, but currently allIncludes is filled from include properties before init is called. And I don't think init() is called by Generator. is it ?

saudet commented 1 year ago

The init() method gets called as part of Loader.loadProperties(), at the very beginning of Parser.parse(), same for Generator.

HGuillemet commented 1 year ago

Ok. I'll load this include list from a resource file from init(). How to know if init is called from parser or from generator ?

saudet commented 1 year ago

We might want to add something for that, but just checking the stack with Loader.getCallerClass() or something should suffice, so if that works I'm inclined to use that.