83 lines
2.0 KiB
Plaintext
83 lines
2.0 KiB
Plaintext
val cDir = File(rootProject.projectDir.absolutePath, "src/main/c")
|
|
|
|
class JNIPlatform(val name: String, val libExtension: String, rootDir: File) {
|
|
val cmakeArgs: Array<String> = arrayOf("-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake")
|
|
}
|
|
|
|
val jniPlatforms = arrayOf(
|
|
JNIPlatform("linux-x86_64", ".so", rootDir),
|
|
JNIPlatform("linux-x86", ".so", rootDir),
|
|
JNIPlatform("linux-armhf", ".so", rootDir),
|
|
JNIPlatform("linux-arm64", ".so", rootDir),
|
|
JNIPlatform("windows-x86_64", ".dll", rootDir),
|
|
JNIPlatform("windows-x86", ".dll", rootDir)
|
|
)
|
|
|
|
tasks.register("cleanJNI") {
|
|
group = "jni"
|
|
}
|
|
tasks.register("compileJNI") {
|
|
group = "jni"
|
|
}
|
|
|
|
jniPlatforms.forEach {
|
|
val buildDir = File(cDir, "build-${it.name}")
|
|
|
|
tasks.register<Exec>("cmake-${it.name}") {
|
|
doFirst {
|
|
if (!buildDir.exists()) {
|
|
buildDir.mkdir()
|
|
}
|
|
}
|
|
|
|
group = "jni"
|
|
workingDir(buildDir)
|
|
|
|
executable("cmake")
|
|
args(it.cmakeArgs, "..")
|
|
}
|
|
|
|
tasks.register<Exec>("compileJNI-${it.name}") {
|
|
group = "jni"
|
|
workingDir(buildDir)
|
|
|
|
executable("make")
|
|
|
|
dependsOn(tasks["cmake-${it.name}"])
|
|
}
|
|
|
|
tasks.named("compileJNI") {
|
|
dependsOn(tasks["compileJNI-${it.name}"])
|
|
}
|
|
|
|
tasks.register<Delete>("cleanJNI-${it.name}") {
|
|
group = "jni"
|
|
delete(buildDir)
|
|
}
|
|
|
|
tasks.named("cleanJNI") {
|
|
dependsOn(tasks["cleanJNI-${it.name}"])
|
|
}
|
|
}
|
|
|
|
tasks.named("clean") {
|
|
dependsOn(tasks["cleanJNI"])
|
|
}
|
|
|
|
tasks.named<Copy>("processResources") {
|
|
dependsOn(tasks["compileJNI"])
|
|
|
|
jniPlatforms.forEach {
|
|
val buildDir = File(cDir, "build-${it.name}")
|
|
if (!buildDir.exists()) {
|
|
buildDir.mkdir()
|
|
}
|
|
|
|
val file = File(buildDir, "libscriptcraft${it.libExtension}")
|
|
inputs.files(file)
|
|
|
|
from(file.absolutePath) {
|
|
into(File("natives", it.name).path)
|
|
}
|
|
}
|
|
} |