buildscript {
    

    repositories {
        mavenLocal()
        mavenCentral()
        gradlePluginPortal()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        google()
    }
    dependencies {


    }
}

// Methods to determine the operating system (OS) and architecture (Arch) of the system.
// These strings are used to determine the classifier of the artifact that contains the
// native libaries. For example, when the operating system is "windows" and the
// architecture is "x86_64", then the classifier will be "windows-x86_64", and thus,
// the JAR file containing the native libraries will be
// jcuda-natives-windows-x86_64-11.0.0.jar
// These methods are taken from
// https://github.com/jcuda/jcuda/blob/master/JCudaJava/src/main/java/jcuda/LibUtils.java
def static getOsString() {
    String vendor = System.getProperty("java.vendor");
    if ("The Android Project" == vendor) {
        return "android";
    } else {
        String osName = System.getProperty("os.name");
        osName = osName.toLowerCase(Locale.ENGLISH);
        if (osName.startsWith("windows")) {
            return "windows";
        } else if (osName.startsWith("mac os")) {
            return "apple";
        } else if (osName.startsWith("linux")) {
            return "linux";
        } else if (osName.startsWith("sun")) {
            return "sun"
        }
        return "unknown"
    }
}

def static getArchString() {
    String osArch = System.getProperty("os.arch");
    osArch = osArch.toLowerCase(Locale.ENGLISH);
    if ("i386" == osArch || "x86" == osArch || "i686" == osArch) {
        return "x86";
    } else if (osArch.startsWith("amd64") || osArch.startsWith("x86_64")) {
        return "x86_64";
    } else if (osArch.startsWith("arm64")) {
        return "arm64";
    } else if (osArch.startsWith("arm")) {
        return "arm";
    } else if ("ppc" == osArch || "powerpc" == osArch) {
        return "ppc";
    } else if (osArch.startsWith("ppc")) {
        return "ppc_64";
    } else if (osArch.startsWith("sparc")) {
        return "sparc";
    } else if (osArch.startsWith("mips64")) {
        return "mips64";
    } else if (osArch.startsWith("mips")) {
        return "mips";
    } else if (osArch.contains("risc")) {
        return "risc";
    }
    return "unknown";
}

allprojects {
    apply plugin: "eclipse"

    version = '1.0'
    ext {
        appName = "ProtoEvo"
        gdxVersion = '1.12.0'
        roboVMVersion = '2.3.16'
        box2DLightsVersion = '1.5'
        ashleyVersion = '1.7.4'
        aiVersion = '1.8.2'
        gdxControllersVersion = '2.2.1'
        shapedrawerVersion = '2.5.0'
        jacksonVersion = '2.14.2'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        google()
        gradlePluginPortal()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        maven { url "https://jitpack.io" }
    }
}

project(":desktop") {
    apply plugin: "java-library"


    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
        
    }
}

project(":core") {
    apply plugin: "java-library"


    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')

        // Add your other dependencies here:

        // JCuda dependencies are below

        def classifier = getOsString() + "-" + getArchString()

        // Set JCuda version here, or if multiple modules use JCuda,
        // you should set a global variable like so:
        //
        // ext {
        //  jCudaVersion = "11.0.0"
        // }
        //
        // In your *top level* build gradle, and use
        // rootProject.ext.jCudaVersion instead of jCudaVersion when you need to access it

        def jCudaVersion = "11.0.0"

        // JCuda Java libraries

        implementation(group: 'org.jcuda', name: 'jcuda', version: jCudaVersion) {
            transitive = false
        }
        implementation(group: 'org.jcuda', name: 'jcublas', version: jCudaVersion) {
            transitive = false
        }
        implementation(group: 'org.jcuda', name: 'jcufft', version: jCudaVersion) {
            transitive = false
        }
        implementation(group: 'org.jcuda', name: 'jcusparse', version: jCudaVersion) {
            transitive = false
        }
        implementation(group: 'org.jcuda', name: 'jcurand', version: jCudaVersion) {
            transitive = false
        }
        implementation(group: 'org.jcuda', name: 'jcusolver', version: jCudaVersion) {
            transitive = false
        }
        implementation(group: 'org.jcuda', name: 'jcudnn', version: jCudaVersion) {
            transitive = false
        }

        // JCuda native libraries

        implementation group: 'org.jcuda', name: 'jcuda-natives',
                classifier: classifier, version: jCudaVersion
        implementation group: 'org.jcuda', name: 'jcublas-natives',
                classifier: classifier, version: jCudaVersion
        implementation group: 'org.jcuda', name: 'jcufft-natives',
                classifier: classifier, version: jCudaVersion
        implementation group: 'org.jcuda', name: 'jcusparse-natives',
                classifier: classifier, version: jCudaVersion
        implementation group: 'org.jcuda', name: 'jcurand-natives',
                classifier: classifier, version: jCudaVersion
        implementation group: 'org.jcuda', name: 'jcusolver-natives',
                classifier: classifier, version: jCudaVersion
        implementation group: 'org.jcuda', name: 'jcudnn-natives',
                classifier: classifier, version: jCudaVersion
//        implementation 'org.jcuda:jcuda-natives:11.8.0'
//        implementation 'org.jcuda:jcuda:11.8.0'0
//        val cudaClassifier = "${getOsString()}-${getArchString()}"
//        implementation("org.jcuda:jcuda:11.2.0") {
//            isTransitive = false
//        }
//        implementation("org.jcuda:jcuda-natives:11.2.0:$cudaClassifier")

        api group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.19.0'

        api "com.github.javafaker:javafaker:1.0.2"
        api "com.google.guava:guava:31.1-jre"
        api "com.google.guava:guava-collections:r03"
        testImplementation "org.hamcrest:hamcrest-all:1.3"
        testImplementation "org.hamcrest:hamcrest-core:2.1"
        testImplementation "org.hamcrest:hamcrest-library:2.1"
        testImplementation "junit:junit:4.13.1"

        api "com.badlogicgames.gdx:gdx:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"

        api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"

        api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"

//        api group: 'org.jcuda', name: 'jcuda-natives', version: '11.8.0'

        api group: 'org.lwjgl', name: 'lwjgl-opencl', version: '3.3.1'
        api "com.aparapi:aparapi:2.0.0"
//        api 'org.lwjgl.lwjgl:lwjgl:2.9.3'

//        api fileTree('libs') { include '*.jar' }
//        api file('libs/PixelFlow.jar')
//        implementation group: 'org.processing', name: 'core', version: '3.3.6'

        implementation "space.earlygrey:shapedrawer:$shapedrawerVersion"

        api "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
        api "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
        api "com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion"
        api "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:$jacksonVersion"

//        api 'de.ruedigermoeller:fst:3.0.3'
        api 'de.ruedigermoeller:fst:2.56'
        api "com.esotericsoftware:kryo:5.6.0"

        api "org.joml:joml:1.10.5"
    }
}
