build.gradle 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. apply plugin: 'cpp'
  2. String bulletSrcPath = bulletFolder + '/src'
  3. if (!hasProperty('mainClass')) {
  4. ext.mainClass = ''
  5. }
  6. dependencies {
  7. compile project(':jme3-bullet')
  8. }
  9. // Defines created C++ libraries
  10. libraries {
  11. bulletjme {
  12. }
  13. all {
  14. binaries.all {
  15. if (toolChain in VisualCpp) {
  16. cppCompiler.args "/I${org.gradle.internal.jvm.Jvm.current().javaHome}\\include"
  17. } else{
  18. cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
  19. }
  20. if (targetPlatform.operatingSystem.name == "osx") {
  21. cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin"
  22. } else if (targetPlatform.operatingSystem.name == "linux") {
  23. cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
  24. cppCompiler.args "-fPIC"
  25. cppCompiler.args "-fpermissive"
  26. // cppCompiler.args "-static-libgcc"
  27. // cppCompiler.args "-static-libstdc++"
  28. // linker.args "-static-libgcc"
  29. // linker.args "-static-libstdc++"
  30. } else if (targetPlatform.operatingSystem.name == "windows") {
  31. if (toolChain in Gcc) {
  32. cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
  33. }
  34. else if (toolChain in VisualCpp) {
  35. cppCompiler.args "/I${org.gradle.internal.jvm.Jvm.current().javaHome}\\include\\win32"
  36. }
  37. cppCompiler.define('WIN32')
  38. // linker.args 'Shlwapi.lib', 'Advapi32.lib'
  39. }
  40. }
  41. }
  42. }
  43. // C++ sources for binary compilation
  44. sources {
  45. bulletjme {
  46. cpp {
  47. source {
  48. srcDir 'src/native/cpp'
  49. srcDir bulletSrcPath
  50. exclude 'BulletMultiThreaded/GpuSoftBodySolvers/**'
  51. include '**/*.cpp'
  52. }
  53. exportedHeaders {
  54. srcDir 'src/native/cpp'
  55. srcDir bulletSrcPath
  56. include '**/*.h'
  57. }
  58. }
  59. }
  60. }
  61. // Java source sets for IDE acces and source jar bundling / mavenization
  62. sourceSets {
  63. main {
  64. java {
  65. srcDir 'src/native/cpp'
  66. }
  67. }
  68. }
  69. // Set of target platforms, will be available based on build system
  70. model {
  71. platforms{
  72. // osx_universal { // TODO: universal binary doesn't work?
  73. // architecture 'x86_64'
  74. // architecture 'x86'
  75. // operatingSystem 'osx'
  76. // }
  77. osx_x86 {
  78. architecture "x86"
  79. operatingSystem "osx"
  80. }
  81. osx_x86_64 {
  82. architecture "x86_64"
  83. operatingSystem "osx"
  84. }
  85. linux_x86 {
  86. architecture "x86"
  87. operatingSystem "linux"
  88. }
  89. linux_x86_64 {
  90. architecture "x86_64"
  91. operatingSystem "linux"
  92. }
  93. windows_x86 {
  94. architecture "x86"
  95. operatingSystem "windows"
  96. }
  97. windows_x86_64 {
  98. architecture "x86_64"
  99. operatingSystem "windows"
  100. }
  101. }
  102. }
  103. // Download bullet if not available
  104. task downloadBullet(type: MyDownload) {
  105. sourceUrl = bulletUrl
  106. target = file(bulletZipFile)
  107. }
  108. // Unzip bullet if not available
  109. task unzipBullet(type: Copy) {
  110. def zipFile = file(bulletZipFile)
  111. def outputDir = file(".")
  112. from zipTree(zipFile)
  113. into outputDir
  114. }
  115. unzipBullet.dependsOn {
  116. def zipFilePath = project.projectDir.absolutePath + File.separator + bulletZipFile
  117. def zipFile = new File(zipFilePath)
  118. if (!zipFile.exists()) {
  119. downloadBullet
  120. }
  121. }
  122. compileJava.dependsOn {
  123. if(buildNativeProjects=="true"){
  124. def bulletUnzipDir = new File(project.projectDir.absolutePath + File.separator + bulletFolder)
  125. if (!bulletUnzipDir.isDirectory()) {
  126. unzipBullet
  127. }
  128. }
  129. }
  130. binaries.withType(StaticLibraryBinarySpec) {
  131. buildable = false
  132. }
  133. // Adds all available binaries to java jar task
  134. binaries.withType(SharedLibraryBinary) { binary ->
  135. // For all binaries that can't be built on the current system
  136. if(buildNativeProjects!="true"){
  137. buildable = false;
  138. }
  139. if (!buildable) {
  140. //Get from libs folder if no fresh build is available in the build folder and add to jar file
  141. if(!binary.tasks.outputFile.get(0).exists()){
  142. def fileName = binary.tasks.outputFile.get(0).getName();
  143. def precompiledFile = new File(project.projectDir.absolutePath + File.separator + "libs" + File.separator + "native" + File.separator + "${targetPlatform.operatingSystem.name}" + File.separator + "${targetPlatform.architecture.name}" + File.separator + "${fileName}")
  144. if(precompiledFile.exists()){
  145. jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") { from precompiledFile }
  146. }
  147. return
  148. } else{
  149. // Add binary to jar file if the binary exists in the build folder already,
  150. // e.g. when the build of jme3-bullet-native has been run on a virtual box
  151. // and the project hasn't been cleaned yet.
  152. jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") { from binary.tasks.outputFile }
  153. return
  154. }
  155. }
  156. // For all binaries that can be built on the current system
  157. def builderTask = binary.tasks
  158. // Add output to jar file
  159. jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") { from builderTask.outputFile }
  160. // Add depend on build
  161. jar.dependsOn builderTask
  162. // Add output to libs folder
  163. task "copyBinaryToLibs${targetPlatform}"(type: Copy, dependsOn: builderTask) {
  164. from builderTask.outputFile
  165. into "libs/native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}"
  166. }
  167. // Add depend on copy
  168. jar.dependsOn("copyBinaryToLibs${targetPlatform}")
  169. }
  170. // Helper class to wrap ant dowload task
  171. class MyDownload extends DefaultTask {
  172. @Input
  173. String sourceUrl
  174. @OutputFile
  175. File target
  176. @TaskAction
  177. void download() {
  178. ant.get(src: sourceUrl, dest: target)
  179. }
  180. }