Native: Set arguments depending on compiler version

Is there a way of determing what the C++ compiler version is? My use-case is to add certain compiler arguments depending on the version of Gcc.

Curretnly the only way I’m seeing to achieve this, requires both deep-diving and writing some fragile code, asillustraed by te following:

task foo << {
    def registry = (project as org.gradle.api.internal.project.ProjectInternal).services
    def factory = services.get(org.gradle.nativeplatform.toolchain.internal.gcc.version.CompilerMetaDataProviderFactory)
    def ver = factory.gcc().getGccMetaData( new File('/usr/bin/gcc'),['-v']).version
    println ver.major
    println ver.minor
}