bufferallocator.gradle 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // build file for native buffer allocator, created by pavl_g on 5/17/22.
  2. // directories for native source
  3. String bufferAllocatorAndroidPath = 'src/native/jme_bufferallocator'
  4. String bufferAllocatorHeaders = 'src/native/headers'
  5. //Pre-compiled libs directory
  6. def rootPath = rootProject.projectDir.absolutePath
  7. String bufferAllocatorPreCompiledLibsDir =
  8. rootPath + File.separator + "build" + File.separator + 'native' + File.separator + 'android' + File.separator + 'allocator'
  9. // directories for build
  10. String bufferAllocatorBuildDir = "$buildDir" + File.separator + "bufferallocator"
  11. String bufferAllocatorJniDir = bufferAllocatorBuildDir + File.separator + "jni"
  12. String bufferAllocatorHeadersBuildDir = bufferAllocatorJniDir + File.separator + "headers"
  13. String bufferAllocatorBuildLibsDir = bufferAllocatorBuildDir + File.separator + "libs"
  14. // copy native src to build dir
  15. task copyJmeBufferAllocator(type: Copy) {
  16. from file(bufferAllocatorAndroidPath)
  17. into file(bufferAllocatorJniDir)
  18. }
  19. // copy native headers to build dir
  20. task copyJmeHeadersBufferAllocator(type: Copy, dependsOn: copyJmeBufferAllocator) {
  21. from file(bufferAllocatorHeaders)
  22. into file(bufferAllocatorHeadersBuildDir)
  23. }
  24. // compile and build copied natives in build dir
  25. task buildBufferAllocatorNativeLib(type: Exec, dependsOn: [copyJmeBufferAllocator, copyJmeHeadersBufferAllocator]) {
  26. workingDir bufferAllocatorBuildDir
  27. executable rootProject.ndkCommandPath
  28. args "-j" + Runtime.runtime.availableProcessors()
  29. }
  30. task updatePreCompiledLibsBufferAllocator(type: Copy, dependsOn: buildBufferAllocatorNativeLib) {
  31. from file(bufferAllocatorBuildLibsDir)
  32. into file(bufferAllocatorPreCompiledLibsDir)
  33. }
  34. // Copy pre-compiled libs to build directory (when not building new libs)
  35. task copyPreCompiledLibsBufferAllocator(type: Copy) {
  36. from file(bufferAllocatorPreCompiledLibsDir)
  37. into file(bufferAllocatorBuildLibsDir)
  38. }
  39. // ndkExists is a boolean from the build.gradle in the root project
  40. // buildNativeProjects is a string set to "true"
  41. if (ndkExists && buildNativeProjects == "true") {
  42. // build native libs and update stored pre-compiled libs to commit
  43. compileJava.dependsOn { updatePreCompiledLibsBufferAllocator }
  44. } else {
  45. // use pre-compiled native libs (not building new ones)
  46. compileJava.dependsOn { copyPreCompiledLibsBufferAllocator }
  47. }
  48. // package the native object files inside the lib folder in a production jar
  49. jar.into("lib") { from bufferAllocatorBuildLibsDir }