apply plugin: "c"
apply plugin: "cunit"

model {
    flavors {
        passing
        failing
    }
    platforms {
        x86 {
            architecture "x86"
        }
    }
    repositories {
        libs(PrebuiltLibraries) {
            cunit {
                headers.srcDir "libs/cunit/2.1-2/include"
                binaries.withType(StaticLibraryBinary) {
                    staticLibraryFile =
                        file("libs/cunit/2.1-2/lib/" +
                             findCUnitLibForPlatform(targetPlatform))
                }
            }
        }
    }
    components {
        operators(NativeLibrarySpec) {
            targetPlatform "x86"
        }
    }
}
model {
    binaries {
        withType(CUnitTestSuiteBinarySpec) {
            lib library: "cunit", linkage: "static"

            if (flavor == flavors.failing) {
                cCompiler.define "PLUS_BROKEN"
            }
        }
    }
}

def findCUnitLibForPlatform(Platform platform) {
    if (platform.operatingSystem.windows) {
//        return "vs2010/cunit.lib"
        return "vs2013/cunit.lib"
//        return "cygwin/cunit.lib"
//        return "mingw/cunit.lib"
    } else if (platform.operatingSystem.macOsX) {
        return "osx/libcunit.a"
    } else {
        return "linux/libcunit.a"
    }
}
