Native builds that depend on a custom Exec task

I am using gradle for native (C++) builds. I have a situation where based on some inputs, I generate some header files and I need to include those in the build.

I have the following folder structure

 src/
     -app/
          -main.cpp
     -lib/
         myapp/
                  -myapp.cpp
                  -include/
                            myapp.hpp
                            **generated.hpp**
    -meta/
           -metadata.xml

I have an xsl file that generates src/lib/include/generated.hpp from src/meta/metadata.xml

My gradle script is as follows

plugins {
id ‘native-component’
id ‘cpp’
}

model {
buildTypes {
debug
production
}

components {
    myapp(NativeLibrarySpec) {
        sources {....}
    }
    mybin(NativeExecutableSpec) {
        sources {....}
    }
}

}

Now, I’ve to add an Exec task that generates the hpp by running xslt. But how can I make it part of the model ? If I add an Exec task(or component ?) to the model, how do I make the other components depend on the artefact created by this task/component ? Thanks

You need generatedBy: See Gradle dependencies between normal tasks and native generated tasks.

1 Like

@Schalk_Cronje Wonderful, just what I wanted. Thanks a lot!