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

102 lines
3.0 KiB

// stb_image url for download
String stbiUrl = 'http://www.nothings.org/stb_image.c'
String stbiDownloadTarget = 'stb_image.c'
// stb_image is not downloaded. The single source file is included in the repo
String stbiFolder = 'stb_image'
//Working directory for the ndk build.
//Must be the parent directory of the jni directory
//Libs directory (output of ndk) will be created in this directory as well
String stbiBuildDir = "${buildDir}" + 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(stbiBuildDir + File.separator + 'jni')
// 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(stbiBuildDir + File.separator + 'jni')
// println "copyStbiJmeFiles sourceDir: " + sourceDir
// println "copyStbiJmeFiles outputDir: " + outputDir
from sourceDir
into outputDir
}
jar.into("lib") { from stbiBuildDir + File.separator + 'libs' }
task generateStbiHeaders(dependsOn:copyStbiJmeFiles) {
String destDir = stbiBuildDir + File.separator + 'jni'
String classes = ""
.concat("com.jme3.texture.plugins.AndroidNativeImageLoader, ")
// println "stb_image classes = " + classes
// println "stb_image destDir = " + destDir
// println "stb_image classpath = " + project.projectClassPath
ant.javah(
classpath: project.projectClassPath,
destdir: destDir,
class: classes
)
}
task buildStbiNativeLib(type: Exec, dependsOn: generateStbiHeaders) {
// println "stb_image build dir: " + buildLibDir
// println "ndkCommandPath: " + project.ndkCommandPath
args 'TARGET_PLATFORM=android-9'
workingDir stbiBuildDir
executable project.ndkCommandPath
}
compileJava.dependsOn {
// ndkPath is defined in the root project gradle.properties file
if (ndkCommandPath != null && new File(ndkCommandPath).exists()) {
buildStbiNativeLib
}
}
// 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)
}
}