apply plugin: 'cpp'

model {
    platforms {
        x86 {
            architecture "x86"
        }
        x64 {
            architecture "x86_64"
        }
        itanium {
            architecture "ia-64"
        }
    }
}

model {
    buildTypes {
        debug
        release
    }
}

model {
    components {
        hello(NativeLibrarySpec) {
            targetPlatform "x86"
            targetPlatform "x64"
        }
        main(NativeExecutableSpec) {
            targetPlatform "x86"
            targetPlatform "x64"
            sources {
                cpp.lib library: 'hello', linkage: 'static'
            }
        }
    }
}

// Apply arguments for debug binaries (these options are not yet set automatically)
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'
            }
        }
    }
}

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 }
        }
    }
}
