A complete 3D game development suite written purely in Java.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jmonkeyengine/jme3-android-native/stb_image.gradle

127 lines
4.1 KiB

// stb_image url for download
String stbiUrl = 'https://raw.githubusercontent.com/nothings/stb/master/stb_image.h'
String stbiDownloadTarget = 'stb_image.h'
// stb_image is not downloaded. The single source file is included in the repo
String stbiFolder = 'stb_image'
//Working directories for the ndk build.
String stbiBuildDir = "${buildDir}" + File.separator + 'stb_image'
String stbiBuildJniDir = stbiBuildDir + File.separator + 'jni'
String stbiBuildLibsDir = stbiBuildDir + File.separator + 'libs'
//Pre-compiled libs directory
String stbiPreCompiledLibsDir = 'libs' + File.separator + 'stb_image'
// jME Android Native source files path
String stbiJmeAndroidPath = 'src/native/jme_stbi'
// Download external source files if not available
task downloadStbImage(type: MyDownload) {
sourceUrl = stbiUrl
target = file(stbiFolder + File.separator + stbiDownloadTarget)
}
// Copy stb_image files to jni directory
task copyStbiFiles(type: Copy) {
def sourceDir = file(stbiFolder)
def outputDir = file(stbiBuildJniDir)
// println "copyStbiFiles sourceDir: " + sourceDir
// println "copyStbiFiles outputDir: " + outputDir
from sourceDir
into outputDir
}
copyStbiFiles.dependsOn {
def stbiFilePath = project.projectDir.absolutePath + stbiFolder + File.separator + stbiDownloadTarget
def stbiFile = new File(stbiFilePath)
// println "zipFile path: " + zipFile.absolutePath
// println "zipFile exists: " + zipFile.exists()
if (!stbiFile.exists()) {
downloadStbImage
}
}
// Copy jME Android native files to jni directory
task copyStbiJmeFiles(type: Copy, dependsOn:copyStbiFiles) {
def sourceDir = file(stbiJmeAndroidPath)
def outputDir = file(stbiBuildJniDir)
// println "copyStbiJmeFiles sourceDir: " + sourceDir
// println "copyStbiJmeFiles outputDir: " + outputDir
from sourceDir
into outputDir
}
task generateStbiHeaders(dependsOn: copyStbiJmeFiles) << {
String destDirPath = stbiBuildJniDir
String classes = ""
.concat("com.jme3.texture.plugins.AndroidNativeImageLoader, ")
// println "stb_image classes = " + classes
// println "stb_image destDir = " + destDir
// println "stb_image classpath = " + project.projectClassPath
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-d', destDirPath
args '-classpath', project.projectClassPath
args "com.jme3.texture.plugins.AndroidNativeImageLoader"
}
}
task buildStbiNativeLib(type: Exec, dependsOn: generateStbiHeaders) {
// println "stb_image build dir: " + stbiBuildDir
// println "ndkCommandPath: " + rootProject.ndkCommandPath
workingDir stbiBuildDir
executable rootProject.ndkCommandPath
args '-j8'
}
task updatePreCompiledStbiLibs(type: Copy, dependsOn: buildStbiNativeLib) {
def sourceDir = new File(stbiBuildLibsDir)
def outputDir = new File(stbiPreCompiledLibsDir)
// println "updatePreCompiledStbiLibs sourceDir: " + sourceDir
// println "updatePreCompiledStbiLibs outputDir: " + outputDir
from sourceDir
into outputDir
}
// Copy pre-compiled libs to build directory (when not building new libs)
task copyPreCompiledStbiLibs(type: Copy) {
def sourceDir = file(stbiPreCompiledLibsDir)
def outputDir = file(stbiBuildLibsDir)
// println "copyStbiJmeFiles sourceDir: " + sourceDir
// println "copyStbiJmeFiles outputDir: " + outputDir
from sourceDir
into outputDir
}
if (rootProject.ndkExists) {
// build native libs and update stored pre-compiled libs to commit
compileJava.dependsOn { updatePreCompiledStbiLibs }
} else {
// use pre-compiled native libs (not building new ones)
compileJava.dependsOn { copyPreCompiledStbiLibs }
}
jar.into("lib") { from stbiBuildLibsDir }
// Helper class to wrap ant dowload task
class MyDownload extends DefaultTask {
@Input
String sourceUrl
@OutputFile
File target
@TaskAction
void download() {
ant.get(src: sourceUrl, dest: target)
}
}