Hi,
I think I’m having trouble with something very simple for other devs here, but I just can’t figure it out on my own.
I’m writing a multiplatform C++ project. It will run on embedded and on linux PC. To get this to work as expected, I would like to have platform specific files (both cpp and hpp files). I keep some configuration variables in hpp files.
So when I write a basic gradle project with common sources and platform specific ones, I can’t use exported headers across SourceSets. For example:
Any suggestions? I think I’ve seen some discussion on having a separate exported headers and nonexported ones - was there any progress on thin in latest builds (2.6 or 2.7)?
Btw I solved it in other project with specifying two separate sourcesets and taking only one into compilation, but it’s a lot of duplication.
I hope you guy will not mind that I’m reviving this thread, but the problem I had before is still live and kicking. As you can read in the post above, I can’t figure out a good way of sharing header files between platform specific parts of code and the common part. Even though I guess this is something that is a “known issue” I upload also a zip with a test project that shows the issue. I simplified it to show that also any headers, even though they are exportedHeaders are not share between sourceSets in the same binary.
Is there anything that could be done about that - I will try to take a look at the gradle code, but I’m more C++ developer and it may be out of my expertize.
Separate source sets are compiled separately, so I wouldn’t expect a file in the linux64 source set to be available in the cpp source set. You can make this work by adding a dependency between the source sets. That will make the exported headers from one source set available when compiling another source set.
This makes your sample project compile.
model {
components {
myBin.sources.common.lib myBin.sources.linux64
}
}
I’m really grateful that you found the time to take a look at that. I will test it in a minute (I will try to make two flavors with different shared header files).
Thank you very much. I will upload the corrected example when I get it ready.
Ok, I spent some time on your suggestion. Adding lib definition helped in that case, but I think I didn’t define the example well enough. The main idea was to have a platform specific code/headers that could used with a common code/headers in a given spec. I modified the example to reflect that with addition of your suggestion of adding the dependency.
And my error:
Attempt to mutate closed view of model of type ‘org.gradle.model.ModelMap<org.gradle.language.base.LanguageSourceSet>’ given to rule 'myBin(org.gradle.nativeplatform.NativeExecutableSpec)