// Android Cast wrapper for third-party/wireguard-android/tunnel (upstream build uses its own catalog).
plugins {
    id 'com.android.library'
}

def wireguardRoot = rootProject.file('third-party/wireguard-android/tunnel')
def wireguardPkg = providers.gradleProperty('wireguardPackageName').getOrElse('com.wireguard.android')

android {
    namespace "${wireguardPkg}.tunnel"
    compileSdk 34

    defaultConfig {
        minSdk 24
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    sourceSets {
        main {
            java.srcDirs "${wireguardRoot}/src/main/java"
            manifest.srcFile "${wireguardRoot}/src/main/AndroidManifest.xml"
        }
    }

    externalNativeBuild {
        cmake {
            path "${wireguardRoot}/tools/CMakeLists.txt"
        }
    }

    lint {
        disable 'LongLogTag', 'NewApi'
    }

    buildTypes {
        all {
            externalNativeBuild {
                cmake {
                    targets 'libwg-go.so', 'libwg.so', 'libwg-quick.so'
                    arguments "-DGRADLE_USER_HOME=${gradle.gradleUserHomeDir}"
                    arguments '-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON'
                }
            }
        }
        release {
            externalNativeBuild {
                cmake {
                    arguments "-DANDROID_PACKAGE_NAME=${wireguardPkg}"
                }
            }
        }
        debug {
            externalNativeBuild {
                cmake {
                    arguments "-DANDROID_PACKAGE_NAME=${wireguardPkg}.debug"
                }
            }
        }
    }
}

dependencies {
    implementation 'androidx.annotation:annotation:1.9.1'
    implementation 'androidx.collection:collection:1.6.0'
    compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
}
