Modify exportedHeaders of native component

Hi guys,

I would like to modify the exportedHeaders of a native component based on the operating system. Is such a thing possible and if yes how would one go about doing that?

If that isn’t possible, I am open to any suggestions of how one might achieve similar behavior.

Regards,
Ante

You could add groovy code to the Closure you feed to exportedHeaders, and/or set a variable based on the OS:

exportedHeaders {
  if(isWindows)
    include '*-win.h'
  else
    include '*-linux.h'
  srcDir "${osDependentVariable}/headers"
}

So I tried this but it doesn’t seem to work, I presume it is because I was trying to add exportedHeaders to late.

class AddExtraHeaderDir extends RuleSource {
        @Mutate
        void addHeaderDirForPlatform(ModelMap<NativeComponentSpec> nativeComponentSpec, File projectDir, applyDefaultSourceConventions) {
            nativeComponentSpec.afterEach(new Action<NativeComponentSpec>() {
                public void execute(NativeComponentSpec componentSpec) {
                    componentSpec.getSources().withType(LanguageSourceSet.class).afterEach(new Action<LanguageSourceSet>() {
                        public void execute(LanguageSourceSet languageSourceSet) {
                            languageSourceSet.exportedHeaders.srcDirs "${projectDir}/OSDependent/Mac"
                        }
                    });
                }
            });
        }
    }
    
    apply plugin: AddHeaderDir

Thanks, this will work as solution.

Another way that works is to define your sourceSet in the

binaries.all {
    sources {
         testSource(CppSourceSet) {
             exportedHeaders {
                 if(targetPlatform.operatingSystem.windows) {
                     srcDirs "path to directory"
                 }
             }
         }
    }
}

block where you have access to the targetPlatform