Add plugin generated code to sources

What is the correct way to add generated code for compilation with native plugins?

I tried this in SourceTask.runTask function and that doesn’t seem to compile the files.

val sources: Set<String> = TreeSet()
source.plus('abc.cpp')
project.extensions.getByType(CppComponent::class.java).source.from.plus(sources)

Also, tried this and same result. Process doesn’t seem to be compiling the files.

val sources: Set<String> = TreeSet()
source.plus('abc.cpp')
project.extensions.getByType(CppComponent::class.java).cppSource.from.plus(sources)

Same result when wrapping the above snippets in project.afterEvaluate block.