I may be mistaken, but from my current understanding of how Gradle works with source sets, you can’t change a source set for different targets (platforms, build types, flavors, etc.). AFAIK, this is because a source set is just a collection of files that is then shared between the different output binaries. Binaries are generated for all the different platform, build type and flavor combinations.
There are some ways to work around this. The easiest is probably to have compile-time defines to indicate the target platform. The build.gradle file then contains something like:
cppCompiler.define '__OS_WINDOWS__' // Or any other custom definition
This is what we’re using now (see here), but IMHO there should be another more elegant way.
Components do have target variations, so an option would be to create platform specific components. This should work normally, but there’s the burden that you’re manually taking care of the component variants, which might not be an option (especially for native libraries).
Maybe there’s a simpler way, but this is what I’ve found so far.