build.gradle 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. if (toolChain.name.startsWith('mingw')) {
  33. cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
  34. } else {
  35. cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
  36. }
  37. cppCompiler.args "-fpermissive"
  38. cppCompiler.args "-static"
  39. linker.args "-static"
  40. }
  41. else if (toolChain in VisualCpp) {
  42. cppCompiler.args "/I${org.gradle.internal.jvm.Jvm.current().javaHome}\\include\\win32"
  43. }
  44. cppCompiler.define('WIN32')
  45. // linker.args 'Shlwapi.lib', 'Advapi32.lib'
  46. }
  47. }
  48. }
  49. }
  50. // C++ sources for binary compilation
  51. sources {
  52. bulletjme {
  53. cpp {
  54. source {
  55. srcDir 'src/native/cpp'
  56. srcDir bulletSrcPath
  57. exclude 'BulletMultiThreaded/GpuSoftBodySolvers/**'
  58. include '**/*.cpp'
  59. }
  60. exportedHeaders {
  61. srcDir 'src/native/cpp'
  62. srcDir bulletSrcPath
  63. include '**/*.h'
  64. }
  65. }
  66. }
  67. }
  68. // Java source sets for IDE acces and source jar bundling / mavenization
  69. sourceSets {
  70. main {
  71. java {
  72. srcDir 'src/native/cpp'
  73. }
  74. }
  75. }
  76. // Set of target platforms, will be available based on build system
  77. model {
  78. toolChains {
  79. gcc(Gcc)
  80. mingw_x86(Gcc) {
  81. eachPlatform() {
  82. cCompiler.executable "i686-w64-mingw32-gcc"
  83. cppCompiler.executable "i686-w64-mingw32-g++"
  84. linker.executable "i686-w64-mingw32-g++"
  85. assembler.executable "i686-w64-mingw32-g++"
  86. staticLibArchiver.executable "i686-w64-mingw32-gcc-ar"
  87. }
  88. target("windows_x86")
  89. }
  90. mingw_x86_64(Gcc) {
  91. eachPlatform() {
  92. cCompiler.executable "x86_64-w64-mingw32-gcc"
  93. cppCompiler.executable "x86_64-w64-mingw32-g++"
  94. linker.executable "x86_64-w64-mingw32-g++"
  95. assembler.executable "x86_64-w64-mingw32-g++"
  96. staticLibArchiver.executable "x86_64-w64-mingw32-gcc-ar"
  97. }
  98. target("windows_x86_64")
  99. }
  100. }
  101. platforms{
  102. // osx_universal { // TODO: universal binary doesn't work?
  103. // architecture 'x86_64'
  104. // architecture 'x86'
  105. // operatingSystem 'osx'
  106. // }
  107. osx_x86 {
  108. architecture "x86"
  109. operatingSystem "osx"
  110. }
  111. osx_x86_64 {
  112. architecture "x86_64"
  113. operatingSystem "osx"
  114. }
  115. linux_x86 {
  116. architecture "x86"
  117. operatingSystem "linux"
  118. }
  119. linux_x86_64 {
  120. architecture "x86_64"
  121. operatingSystem "linux"
  122. }
  123. windows_x86 {
  124. architecture "x86"
  125. operatingSystem "windows"
  126. }
  127. windows_x86_64 {
  128. architecture "x86_64"
  129. operatingSystem "windows"
  130. }
  131. }
  132. }
  133. // Download bullet if not available
  134. task downloadBullet(type: MyDownload) {
  135. sourceUrl = bulletUrl
  136. target = file(bulletZipFile)
  137. }
  138. // Unzip bullet if not available
  139. task unzipBullet(type: Copy) {
  140. def zipFile = file(bulletZipFile)
  141. def outputDir = file(".")
  142. from zipTree(zipFile)
  143. into outputDir
  144. }
  145. unzipBullet.dependsOn {
  146. def zipFilePath = project.projectDir.absolutePath + File.separator + bulletZipFile
  147. def zipFile = new File(zipFilePath)
  148. if (!zipFile.exists()) {
  149. downloadBullet
  150. }
  151. }
  152. compileJava.dependsOn {
  153. if(buildNativeProjects=="true"){
  154. def bulletUnzipDir = new File(project.projectDir.absolutePath + File.separator + bulletFolder)
  155. if (!bulletUnzipDir.isDirectory()) {
  156. unzipBullet
  157. }
  158. }
  159. }
  160. binaries.withType(StaticLibraryBinarySpec) {
  161. buildable = false
  162. }
  163. // Adds all available binaries to java jar task
  164. binaries.withType(SharedLibraryBinary) { binary ->
  165. // For all binaries that can't be built on the current system
  166. if(buildNativeProjects!="true"){
  167. buildable = false;
  168. }
  169. if (!buildable) {
  170. //Get from libs folder if no fresh build is available in the build folder and add to jar file
  171. if(!binary.tasks.outputFile.get(0).exists()){
  172. def fileName = binary.tasks.outputFile.get(0).getName();
  173. 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}")
  174. if(precompiledFile.exists()){
  175. jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") { from precompiledFile }
  176. }
  177. return
  178. } else{
  179. // Add binary to jar file if the binary exists in the build folder already,
  180. // e.g. when the build of jme3-bullet-native has been run on a virtual box
  181. // and the project hasn't been cleaned yet.
  182. jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") { from binary.tasks.outputFile }
  183. return
  184. }
  185. }
  186. // For all binaries that can be built on the current system
  187. def builderTask = binary.tasks
  188. // Add output to jar file
  189. jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") { from builderTask.outputFile }
  190. // Add depend on build
  191. jar.dependsOn builderTask
  192. // Add output to libs folder
  193. task "copyBinaryToLibs${targetPlatform}"(type: Copy, dependsOn: builderTask) {
  194. from builderTask.outputFile
  195. into "libs/native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}"
  196. }
  197. // Add depend on copy
  198. jar.dependsOn("copyBinaryToLibs${targetPlatform}")
  199. }
  200. // Helper class to wrap ant dowload task
  201. class MyDownload extends DefaultTask {
  202. @Input
  203. String sourceUrl
  204. @OutputFile
  205. File target
  206. @TaskAction
  207. void download() {
  208. ant.get(src: sourceUrl, dest: target)
  209. }
  210. }