apply plugin: 'cpp'

// tag::platforms[]
model {
    platforms {
        x86 {
            architecture "x86"
        }
        x64 {
            architecture "x86_64"
        }
        itanium {
            architecture "ia-64"
        }
    }
}
// end::platforms[]

// tag::build-types[]
model {
    buildTypes {
        debug
        release
    }
}
// end::build-types[]

// tag::target-platforms[]
model {
    components {
        hello(NativeLibrarySpec) {
            targetPlatform "x86"
            targetPlatform "x64"
        }
        main(NativeExecutableSpec) {
            targetPlatform "x86"
            targetPlatform "x64"
            sources {
                cpp.lib library: 'hello', linkage: 'static'
            }
        }
    }
}
// end::target-platforms[]

// Apply arguments for debug binaries (these options are not yet set automatically)
// tag::build-type-config[]
model {
    binaries {
        all {
            if (toolChain in Gcc && buildType == buildTypes.debug) {
                cppCompiler.args "-g"
            }
            if (toolChain in VisualCpp && buildType == buildTypes.debug) {
                cppCompiler.args '/Zi'
                cppCompiler.define 'DEBUG'
                linker.args '/DEBUG'
            }
        }
    }
}
// end::build-type-config[]

model {
    // Apply custom arguments for different target platforms
    binaries {
        all {
            if (toolChain in Gcc && targetPlatform == platforms.x86) {
                cppCompiler.args '-O3'
            }
        }
    }

    // Tasks to build all binaries for a tool chain
    tasks {
        gccExecutables(Task) {
            dependsOn $.binaries.findAll { it.toolChain in Gcc }
        }
        visualCppExecutables(Task) {
            dependsOn $.binaries.findAll { it.toolChain in VisualCpp }
        }
    }
}
