Gradle native - compile cpp with different flags

I’m porting a makefile project in Gradle. In this makefile there are two sets of source files, say setA e and setB.
setA is compiled with flags flagsA, and setB is compiled with flags flagsB; all objects files are then linked toghether.

How can I reproduce this in Gradle?