/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import com.facebook.fresco.buildsrc.Deps
import com.facebook.fresco.buildsrc.GradleDeps
import com.facebook.fresco.buildsrc.TestDeps

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

kotlin {
    jvmToolchain(11)
}

dependencies {
    compileOnly Deps.inferAnnotation
    compileOnly Deps.javaxAnnotation
    compileOnly Deps.jsr305

    implementation Deps.SoLoader.nativeloader
    implementation Deps.Bolts.tasks
    implementation project(':fbcore')
    implementation project(':imagepipeline-base')
    implementation project(':middleware')

    testImplementation TestDeps.junit

    androidTestCompileOnly Deps.inferAnnotation

    androidTestImplementation project(':imagepipeline')
    androidTestImplementation TestDeps.junit
    androidTestImplementation TestDeps.AndroidX.testRules
    androidTestImplementation TestDeps.AndroidX.testRunner
}

// We download various C++ open-source dependencies from SourceForge into nativedeps/downloads.
// We then copy both downloaded code and our custom makefiles and headers into nativedeps/merge.

task fetchNativeDeps(dependsOn: [copyLibwebp, copyLibpng, copyLibjpeg]) {
}

android {
    ndkVersion GradleDeps.Native.version

    def ndkLibs = [['static-webp', [copyLibjpeg, copyLibpng, copyLibwebp]]]

    buildToolsVersion FrescoConfig.buildToolsVersion
    compileSdkVersion FrescoConfig.compileSdkVersion

    namespace "com.facebook.webpsupport"

    defaultConfig {
        minSdkVersion FrescoConfig.minSdkVersion
        targetSdkVersion FrescoConfig.targetSdkVersion
    }

    sourceSets {
        main {
            jni.srcDirs = []
            jniLibs.srcDirs = ndkLibs.collect { "$buildDir/${it[0]}" }
        }
    }

    lintOptions {
        abortOnError false
    }
    ndkLibs.each { lib -> makeNdkTasks lib[0], lib[1] }
    preBuild.dependsOn(
        "ndk_build_static-webp",
        "copyLibjpeg",
        "copyLibpng",
        "copyLibwebp"
    )
}

apply plugin: "com.vanniktech.maven.publish"
