build.gradle 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. apply plugin: 'cpp'
  2. import java.nio.file.Paths
  3. def rootPath = rootProject.projectDir.absolutePath
  4. String bulletSrcPath = bulletFolder + '/src'
  5. if (!hasProperty('mainClass')) {
  6. ext.mainClass = ''
  7. }
  8. dependencies {
  9. compile project(':jme3-bullet')
  10. }
  11. clean { dependsOn 'cleanHeaders', 'cleanUnzipped' }
  12. // clean up auto-generated C++ headers
  13. task cleanHeaders(type: Delete) {
  14. delete fileTree(dir: 'src/native/cpp', include: 'com_jme3_bullet_*.h')
  15. }
  16. // clean up unzipped files
  17. task cleanUnzipped(type: Delete) {
  18. delete bulletFolder
  19. }
  20. // clean up the downloaded archive
  21. task cleanZipFile(type: Delete) {
  22. delete bulletZipFile
  23. }
  24. model {
  25. components {
  26. bulletjme(NativeLibrarySpec) {
  27. String[] targets=[
  28. "Windows64",
  29. "Windows32",
  30. "Mac64",
  31. "Linux64",
  32. "Linux32",
  33. "LinuxArm",
  34. "LinuxArmHF",
  35. "LinuxArm64"
  36. ];
  37. String[] filter=gradle.rootProject.ext.usePrebuildNatives==true?null:buildForPlatforms.split(",");
  38. if(filter==null)println("No filter set. build for all");
  39. for(String target:targets){
  40. if(filter==null){
  41. targetPlatform(target);
  42. }else{
  43. for(String f:filter){
  44. if(f.equals(target)){
  45. targetPlatform(target);
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. sources {
  52. cpp {
  53. source {
  54. srcDir 'src/native/cpp'
  55. srcDir bulletSrcPath
  56. exclude 'Bullet3Collision/**'
  57. exclude 'Bullet3Dynamics/**'
  58. exclude 'Bullet3Geometry/**'
  59. exclude 'Bullet3OpenCL/**'
  60. exclude 'Bullet3Serialize/**'
  61. include '**/*.cpp'
  62. exclude '**/*All.cpp'
  63. }
  64. exportedHeaders {
  65. srcDir 'src/native/cpp'
  66. srcDir bulletSrcPath
  67. exclude 'Bullet3Collision/**'
  68. exclude 'Bullet3Dynamics/**'
  69. exclude 'Bullet3Geometry/**'
  70. exclude 'Bullet3OpenCL/**'
  71. exclude 'Bullet3Serialize/**'
  72. include '**/*.h'
  73. }
  74. }
  75. }
  76. }
  77. }
  78. toolChains {
  79. visualCpp(VisualCpp)
  80. gcc(Gcc)
  81. clang(Clang)
  82. gccArm(Gcc) {
  83. // Fun Fact: Gradle uses gcc as linker frontend, so we don't specify ld directly here
  84. target("LinuxArm"){
  85. path "/usr/bin"
  86. cCompiler.executable = "arm-linux-gnueabi-gcc-8"
  87. cppCompiler.executable = "arm-linux-gnueabi-g++-8"
  88. linker.executable = "arm-linux-gnueabi-gcc-8"
  89. assembler.executable = "arm-linux-gnueabi-as"
  90. }
  91. target("LinuxArmHF"){
  92. path "/usr/bin"
  93. cCompiler.executable = "arm-linux-gnueabihf-gcc-8"
  94. cppCompiler.executable = "arm-linux-gnueabihf-g++-8"
  95. linker.executable = "arm-linux-gnueabihf-gcc-8"
  96. assembler.executable = "arm-linux-gnueabihf-as"
  97. }
  98. target("LinuxArm64"){
  99. path "/usr/bin"
  100. cCompiler.executable = "aarch64-linux-gnu-gcc-8"
  101. cppCompiler.executable = "aarch64-linux-gnu-g++-8"
  102. linker.executable = "aarch64-linux-gnu-gcc-8"
  103. assembler.executable = "aarch64-linux-gnu-as"
  104. }
  105. }
  106. }
  107. binaries {
  108. withType(SharedLibraryBinarySpec) {
  109. def javaHome = org.gradle.internal.jvm.Jvm.current().javaHome
  110. def os = targetPlatform.operatingSystem.name
  111. def arch = targetPlatform.architecture.name
  112. def fileName = sharedLibraryFile.name
  113. // Gradle decided to change underscores to dashes - fix that.
  114. arch = arch.replaceAll('-', '_')
  115. // For all binaries that can't be built on the current system
  116. if (buildNativeProjects != "true") buildable = false
  117. if (buildable) {
  118. cppCompiler.define('BT_NO_PROFILE')
  119. if (toolChain in VisualCpp) {
  120. cppCompiler.args "/I$javaHome\\include"
  121. } else{
  122. cppCompiler.args '-I', "$javaHome/include"
  123. }
  124. if (os == "osx") {
  125. cppCompiler.args '-I', "$javaHome/include/darwin"
  126. cppCompiler.args "-O3"
  127. cppCompiler.args "-U_FORTIFY_SOURCE"
  128. } else if (os == "linux") {
  129. cppCompiler.args "-fvisibility=hidden"
  130. cppCompiler.args '-I', "$javaHome/include/linux"
  131. cppCompiler.args "-fPIC"
  132. cppCompiler.args "-O3"
  133. cppCompiler.args "-U_FORTIFY_SOURCE"
  134. cppCompiler.args "-fpermissive"
  135. linker.args "-fvisibility=hidden"
  136. } else if (os == "windows") {
  137. if (toolChain in Gcc) {
  138. if (toolChain.name.startsWith('mingw')) cppCompiler.args '-I', "$projectDir/src/native/cpp/fake_win32"
  139. else cppCompiler.args '-I', "$javaHome/include/win32"
  140. cppCompiler.args "-fpermissive"
  141. cppCompiler.args "-static"
  142. cppCompiler.args "-O3"
  143. cppCompiler.args "-U_FORTIFY_SOURCE"
  144. linker.args "-static"
  145. linker.args "-Wl,--exclude-all-symbols"
  146. } else if (toolChain in VisualCpp) {
  147. cppCompiler.args "/I$javaHome\\include\\win32"
  148. }
  149. cppCompiler.define('WIN32')
  150. }
  151. tasks.all {
  152. dependsOn unzipBulletIfNeeded
  153. dependsOn ':jme3-bullet:compileJava'
  154. }
  155. task "copyBinaryToLibs${targetPlatform.name}"(type: Copy, dependsOn: tasks) {
  156. from sharedLibraryFile
  157. into "${rootPath}/build/native/bullet/native/${os}/${arch}"
  158. }
  159. // Add depend on copy
  160. jar.dependsOn("copyBinaryToLibs${targetPlatform.name}")
  161. }
  162. }
  163. withType(StaticLibraryBinarySpec) {
  164. buildable = false
  165. }
  166. }
  167. platforms {
  168. Windows32 {
  169. architecture "x86"
  170. operatingSystem "windows"
  171. }
  172. Windows64 {
  173. architecture "x86_64"
  174. operatingSystem "windows"
  175. }
  176. Mac64 {
  177. architecture "x86_64"
  178. operatingSystem "osx"
  179. }
  180. Linux32 {
  181. architecture "x86"
  182. operatingSystem "linux"
  183. }
  184. Linux64 {
  185. architecture "x86_64"
  186. operatingSystem "linux"
  187. }
  188. LinuxArm {
  189. architecture "arm"
  190. operatingSystem "linux"
  191. }
  192. LinuxArmHF {
  193. architecture "armhf"
  194. operatingSystem "linux"
  195. }
  196. LinuxArm64 {
  197. architecture "aarch64"
  198. operatingSystem "linux"
  199. }
  200. }
  201. }
  202. // Java source sets for IDE access and source jar bundling / mavenization
  203. sourceSets {
  204. main {
  205. java {
  206. srcDir 'src/native/cpp'
  207. }
  208. resources {
  209. srcDir file(Paths.get(rootPath, 'build', 'native', 'bullet'))
  210. }
  211. }
  212. }
  213. task downloadBullet(type: MyDownload) {
  214. sourceUrl = bulletUrl
  215. target = file(bulletZipFile)
  216. }
  217. task unzipBullet(type: Copy) {
  218. from zipTree(bulletZipFile)
  219. into file('.')
  220. }
  221. unzipBullet.dependsOn {
  222. if (!file(bulletZipFile).exists()) {
  223. downloadBullet
  224. }
  225. }
  226. task unzipBulletIfNeeded {
  227. }
  228. unzipBulletIfNeeded.dependsOn {
  229. if (buildNativeProjects == "true") {
  230. unzipBullet
  231. }
  232. }
  233. // Helper class to wrap ant download task
  234. class MyDownload extends DefaultTask {
  235. @Input
  236. String sourceUrl
  237. @OutputFile
  238. File target
  239. @TaskAction
  240. void download() {
  241. ant.get(src: sourceUrl, dest: target)
  242. }
  243. }