This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/jni.build.gradle

74 lines
2.1 KiB
Groovy
Raw Normal View History

2020-04-28 14:16:47 +00:00
def cDir = new File(rootProject.projectDir.absolutePath, 'src/main/c')
class JNIPlatform {
String name
String[] cmakeArgs
String libExtension
JNIPlatform(String name, String libExtension, File rootDir) {
this.name = name
this.cmakeArgs = ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake"] as String[]
this.libExtension = libExtension
}
}
JNIPlatform[] jniPlatforms = [
new JNIPlatform("linux-x86_64", ".so", rootDir),
new JNIPlatform("linux-x86", ".so", rootDir),
new JNIPlatform("linux-armhf", ".so", rootDir),
new JNIPlatform("linux-arm64", ".so", rootDir),
new JNIPlatform("windows-x86_64", ".dll", rootDir),
new JNIPlatform("windows-x86", ".dll", rootDir)
]
task cleanJNI {}
task compileJNI {}
for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) {
buildDir.mkdir()
}
tasks.create(name: "cmake-${platform.name}", group: 'jni', type: Exec) {
workingDir buildDir
executable 'cmake'
args platform.cmakeArgs + ['..']
}
tasks.create(name: "compileJNI-${platform.name}", group: 'jni', type: Exec) {
workingDir buildDir
executable 'make'
dependsOn tasks.getByName("cmake-${platform.name}")
}
compileJNI.dependsOn tasks.getByName("compileJNI-${platform.name}")
tasks.create(name: "cleanJNI-${platform.name}", group: 'jni', type: Delete) {
delete buildDir.absolutePath
}
cleanJNI.dependsOn tasks.getByName("cleanJNI-${platform.name}")
}
clean.dependsOn cleanJNI
processResources.dependsOn compileJNI
processResources {
for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) {
buildDir.mkdir()
}
def file = new File(buildDir, 'libscriptcraft' + platform.libExtension)
inputs.files file
from(file.absolutePath) {
into new File('natives', platform.name).path
}
}
}