-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
539 lines (489 loc) · 20.7 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
// Gradle script to build Libbulletjme Maven artifacts and desktop native libraries
plugins {
id 'application' // to build JVM applications
id 'checkstyle' // to analyze Java sourcecode for style violations
id 'cpp' // to compile C/C++ code and link native libraries
id 'java-library' // to build JVM libraries
id 'maven-publish' // to publish artifacts to Maven repositories
id 'signing' // to sign artifacts for publication
}
ext {
group = 'com.github.stephengold'
artifact = 'Libbulletjme'
version = '21.3.1'
baseName = "${artifact}-${version}" // for artifacts
websiteUrl = 'https://github.com/stephengold/Libbulletjme'
}
sourceSets.main.java {
srcDir 'src/main/java'
srcDir 'src/main/native' // for IDE access (no Java there)
}
sourceSets.test.java {
srcDir 'src/test/java'
}
// Regenerate all JNI header files before compiling any C++ code.
tasks.withType(CppCompile) {
dependsOn('classes', 'compileTestJava')
}
String javaHome = org.gradle.internal.jvm.Jvm.current().javaHome.absolutePath
model {
buildTypes {
Debug
Release
}
flavors {
Dp // double-precision arithmetic
DpMt // double-precision arithmetic, multithreaded
Sp // single-precision arithmetic
SpMt // single-precision arithmetic, multithreaded
SpMtQuickprof // single-precision arithmetic, multithreaded, Quickprof profiling
SpQuickprof // single-precision arithmetic, Quickprof profiling
}
platforms {
// To build native libraries for Android, use "android.gradle" instead.
Linux32 {
architecture 'x86'
operatingSystem 'linux'
}
Linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
Linux_ARM32 { // omitted from recent Minie releases
architecture 'armel'
operatingSystem 'linux'
}
Linux_ARM32hf {
architecture 'armhf'
operatingSystem 'linux'
}
Linux_ARM64 {
architecture 'aarch64'
operatingSystem 'linux'
}
MacOSX32 {
architecture 'x86'
operatingSystem 'osx'
}
MacOSX64 {
architecture 'x86_64'
operatingSystem 'osx'
}
MacOSX_ARM64 {
architecture 'arm-v8'
operatingSystem 'osx'
}
Windows32 {
architecture 'x86'
operatingSystem 'windows'
}
Windows64 {
architecture 'x86_64'
operatingSystem 'windows'
}
}
toolChains { // prioritize among the native toolchains
visualCpp(VisualCpp) // used when compiling on Windows
//clang(Clang) // to prefer Clang over Gcc
//gcc9Arm(Gcc) {
// target('Linux_ARM32') {
// cppCompiler.executable = 'arm-linux-gnueabi-g++-9'
// linker.executable = 'arm-linux-gnueabi-g++-9'
// }
// target('Linux_ARM32hf') {
// cppCompiler.executable = 'arm-linux-gnueabihf-g++-9'
// linker.executable = 'arm-linux-gnueabihf-g++-9'
// }
// target('Linux_ARM64') {
// cppCompiler.executable = 'aarch64-linux-gnu-g++-9'
// linker.executable = 'aarch64-linux-gnu-g++-9'
// }
//}
//gcc8Arm32hf(Gcc) {
// target('Linux_ARM32hf') {
// cppCompiler.executable = 'arm-linux-gnueabihf-g++-8'
// linker.executable = 'arm-linux-gnueabihf-g++-8'
// }
//}
gcc(Gcc) // used when compiling on Linux
gcc6Arm32hf(Gcc) { // used at Travis CI (job .5)
target('Linux_ARM32hf') {
cppCompiler.executable = 'arm-linux-gnueabihf-g++-6'
linker.executable = 'arm-linux-gnueabihf-g++-6'
}
}
gcc6Arm64(Gcc) { // used at Travis CI (jobs .6 and .7)
target('Linux_ARM64') {
cppCompiler.executable = 'aarch64-linux-gnu-g++-6'
linker.executable = 'aarch64-linux-gnu-g++-6'
}
}
gcc7Arm32(Gcc) { // used at Travis CI (job .4)
target('Linux_ARM32') {
cppCompiler.executable = 'arm-linux-gnueabi-g++-7'
linker.executable = 'arm-linux-gnueabi-g++-7'
}
}
clang(Clang) // used when compiling on macOS
}
components {
// To build native libraries for Android, use "android.gradle" instead.
bulletjme(NativeLibrarySpec) {
targetPlatform 'Linux32'
targetPlatform 'Linux64'
targetPlatform 'Linux_ARM32' // omitted from recent Minie releases
targetPlatform 'Linux_ARM32hf'
targetPlatform 'Linux_ARM64'
targetPlatform 'MacOSX32'
targetPlatform 'MacOSX64'
targetPlatform 'MacOSX_ARM64'
targetPlatform 'Windows32'
targetPlatform 'Windows64'
sources.cpp.source {
srcDir 'src/main/native/bullet3'
srcDir 'src/main/native/glue'
srcDir 'src/main/native/v-hacd/src'
include '**/*.cpp'
}
binaries.withType(SharedLibraryBinarySpec) {
String pName = targetPlatform.name
//println " - $pName $buildType $flavor" // to debug this script
// Decide whether to build for the target platform:
Boolean isDebug = (buildType == buildTypes.Debug)
Boolean isMt = (flavor == flavors.SpMt || flavor == flavors.SpMtQuickprof || flavor == flavors.DpMt)
if (project.hasProperty('github')) {
// CI build with -Pgithub= specified on the command line
String github = project.ext.github
if (github == 'debug64') { // skip all except debug/64-bit/non-ARM
buildable = isDebug && pName.contains('64') && !pName.contains('_ARM')
} else if (github == 'debug64arm') { // skip all except debug/64-bit/ARM
buildable = isDebug && pName.contains('64') && pName.contains('_ARM')
}
} else if (project.hasProperty('travis')) {
// CI build with -Ptravis= specified on the command line
String travis = project.ext.travis
if (travis == 'amd64') { // using g++-7, skip Mt flavors
buildable = (!isMt) && !pName.contains('_ARM')
} else if (travis == 'amd64mt') { // using g++-7 to build Mt flavors
buildable = isMt && (pName == 'Linux64')
} else if (travis == 'arm32') {
buildable = (pName == 'Linux_ARM32')
} else if (travis == 'arm32hf') {
buildable = (pName == 'Linux_ARM32hf')
} else if (travis == 'arm64') {
buildable = (pName == 'Linux_ARM64')
} else if (travis == 'osx_intel') { // xcode9.4.1 job
buildable = pName.startsWith('MacOSX') && !pName.contains('_ARM')
} else if (travis == 'osx_arm') { // xcode14.2 job
buildable = (pName == 'MacOSX_ARM64')
}
} else {
// non-CI build (neither -Pgithub= nor -Ptravis= specified)
buildable = !pName.startsWith('Linux_ARM')
//buildable = (pName == 'Linux64') // to build Linux64 only
//buildable = (pName == 'Windows64') // to build Windows64 only
//buildable = (pName == 'Linux_ARM32hf') // to build Linux_ARM32hf only
}
Boolean isDp = (flavor == flavors.Dp || flavor == flavors.DpMt)
Boolean isQuickprof = (flavor == flavors.SpMtQuickprof || flavor == flavors.SpQuickprof)
String os = targetPlatform.operatingSystem.name
if (buildable) {
// Decide whether to build the current flavor:
if (project.hasProperty('flavor')) {
// -Pflavor= specified on the command line
String flavorArg = project.ext.flavor
buildable = (flavor.name == flavorArg)
} else if (isMt) {
// Skip Mt for MacOSX (Xcode does not support OpenMP) and 32-bit targets
buildable = (os != 'osx') && pName.contains('64')
}
//if (isDp) buildable = false // to skip all double-precision flavors
//if (isMt) buildable = false // to skip all multithreaded flavors
if (isQuickprof) buildable = false // to skip all Quickprof flavors
}
// flavor-specific CPP defines:
if (isDebug) {
cppCompiler.define '_DEBUG'
//cppCompiler.define 'BT_ADDITIONAL_DEBUG'
//cppCompiler.define 'BT_DEBUG_MEMORY_ALLOCATIONS'
//cppCompiler.define 'DEBUG_PERSISTENCY'
//cppCompiler.define 'VERBOSE_RESIDUAL_PRINTF'
}
if (isDp) {
cppCompiler.define 'BT_USE_DOUBLE_PRECISION'
}
if (isMt) {
cppCompiler.define 'BT_THREADSAFE'
cppCompiler.define 'BT_USE_OPENMP'
}
if (isQuickprof) {
cppCompiler.define 'BT_ENABLE_PROFILE'
//cppCompiler.define 'BT_LINUX_REALTIME'
}
String q = pName + buildType.name + flavor.name
if (toolChain in VisualCpp) {
cppCompiler.define 'WIN32'
cppCompiler.args '/EHsc' // synchronous exceptions only
cppCompiler.args "/I$javaHome/include"
cppCompiler.args "/I$javaHome/include/win32"
cppCompiler.args "/I$projectDir/src/main/native/bullet3"
cppCompiler.args "/I$projectDir/src/main/native/bullet3/BulletDynamics/Featherstone"
cppCompiler.args "/I$projectDir/src/main/native/bullet3/LinearMath"
cppCompiler.args "/I$projectDir/src/main/native/v-hacd/inc"
cppCompiler.args "/I$projectDir/src/main/native/v-hacd/public"
linker.args 'ws2_32.lib' // for htons()
if (isDebug) {
cppCompiler.args '/FS' // to serialize PDB-file writes
cppCompiler.args '/MTd' // to use LIBCMTD
cppCompiler.args '/Zi' // to generate a PDB file containing debug info
//cppCompiler.args '/Z7' // to embed debug info in OBJ files
linker.args '/DEBUG'
if (buildable) {
String pdbFile = 'build/libs/bulletjme/shared/'
pdbFile += pName + '/debug/'
pdbFile += flavor.name + '/bulletjme.pdb'
project.tasks.register('copyPdbToDist' + q, Copy) {
dependsOn "bulletjme${q}SharedLibrary"
from pdbFile
rename { String filename ->
return q + '_' + filename
}
into 'dist'
}
jar.dependsOn('copyPdbToDist' + q)
}
} else { // buildType == Release
cppCompiler.args '/O2'
cppCompiler.args '/Ob3'
}
if (isMt) {
cppCompiler.args '/openmp'
}
} else { // toolChain in Clang or Gcc
//cppCompiler.args '-v' // to log compiler details
//linker.args '-v' // to log linker details
cppCompiler.args '-I', "$javaHome/include"
cppCompiler.args '-I', "$projectDir/src/main/native/bullet3"
cppCompiler.args '-I', "$projectDir/src/main/native/bullet3/BulletDynamics/Featherstone"
cppCompiler.args '-I', "$projectDir/src/main/native/bullet3/LinearMath"
cppCompiler.args '-I', "$projectDir/src/main/native/v-hacd/inc"
cppCompiler.args '-I', "$projectDir/src/main/native/v-hacd/public"
cppCompiler.args '-std=c++11'
cppCompiler.args '-Werror=return-type'
if (isDebug) {
cppCompiler.args '-O0', '-g3'
} else { // buildType == Release
cppCompiler.args '-O3'
}
if (isMt) {
cppCompiler.args '-fopenmp'
linker.args '-lgomp'
}
if (os == 'osx') {
cppCompiler.args '-I', "$javaHome/include/darwin"
} else if (os == 'linux') {
cppCompiler.args '-I', "$javaHome/include/linux"
cppCompiler.args '-fPIC'
cppCompiler.args '-fvisibility=hidden'
linker.args '-fvisibility=hidden'
} else if (os == 'windows') { // not tested recently
cppCompiler.define 'WIN32'
cppCompiler.args '-I', "$javaHome/include/win32"
cppCompiler.args '-static'
linker.args '-static'
linker.args '-Wl,--exclude-all-symbols'
} else {
buildable = false
}
}
if (buildable) {
println 'Build ' + q + ' using ' + toolChain
project.tasks.register('copyToDist' + q, Copy) {
dependsOn "bulletjme${q}SharedLibrary"
from sharedLibraryFile
rename { String filename ->
return q + '_' + filename
}
into 'dist'
}
jar.dependsOn('copyToDist' + q)
} else {
//println 'Do not build ' + q // to debug this script
}
}
binaries.withType(StaticLibraryBinarySpec) {
buildable = false
}
}
}
}
dependencies {
testImplementation(libs.junit4)
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType(JavaCompile) { // Java compile-time options:
options.compilerArgs << '-Xdiags:verbose'
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_20)) {
// Suppress warnings that source value 8 is obsolete.
options.compilerArgs << '-Xlint:-options'
}
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true // to provide detailed deprecation warnings
options.encoding = 'UTF-8'
options.headerOutputDirectory = new File('src/main/native/glue')
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_1_10)) {
options.release = 8
}
}
application {
mainClass = 'jme3utilities.minie.TestApp'
}
tasks.withType(JavaExec).configureEach { // Java runtime options:
classpath sourceSets.main.runtimeClasspath
enableAssertions true
}
run.dependsOn('assemble')
test.dependsOn('assemble')
checkstyle {
toolVersion libs.versions.checkstyle.get()
}
tasks.register('checkstyle') {
dependsOn 'checkstyleMain', 'checkstyleTest'
description 'Checks the style of all Java sourcecode.'
}
checkstyleMain.dependsOn('compileTestJava')
// Register publishing tasks:
tasks.register('install') {
dependsOn 'publishMavenPublicationToMavenLocal'
description 'Installs Maven artifacts to the local repository.'
}
assemble.dependsOn('copyToDistJars')
tasks.register('copyToDistJars', Copy) {
dependsOn 'jar', 'javadocJar', 'signArchives', 'signMavenPublication', 'sourcesJar'
from 'build/libs'
include '*.jar', '*.jar.asc'
into 'dist'
}
jar {
archiveBaseName = project.ext.baseName
doLast {
println "using Java ${JavaVersion.current()} (${System.getProperty("java.vendor")})"
}
manifest {
attributes 'Created-By': "${JavaVersion.current()} (${System.getProperty("java.vendor")})"
}
}
java.withJavadocJar()
javadocJar { archiveBaseName = project.ext.baseName }
tasks.register('sourcesJar', Jar) {
archiveBaseName = project.ext.baseName
archiveClassifier = 'sources'
description 'Creates a JAR of Java sourcecode.'
from 'src/main/java' // default is ".allSource", which includes resources
}
// add javadoc/source jar tasks as artifacts
artifacts {
archives jar, sourcesJar
}
javadoc.dependsOn('compileTestJava')
assemble.dependsOn('module', 'moduleAsc', 'pom', 'pomAsc')
tasks.register('module', Copy) {
dependsOn 'generateMetadataFileForMavenPublication'
description 'Copies the module metadata to dist.'
from "${buildDir}/publications/maven/module.json"
into 'dist'
rename 'module.json', project.ext.baseName + '.module'
}
tasks.register('moduleAsc', Copy) {
dependsOn 'signMavenPublication'
description 'Copies the signature of the module metadata to dist.'
from "${buildDir}/publications/maven/module.json.asc"
into 'dist'
rename 'module.json.asc', project.ext.baseName + '.module.asc'
}
tasks.register('pom', Copy) {
dependsOn 'generatePomFileForMavenPublication'
description 'Copies the Maven POM to dist.'
from "${buildDir}/publications/maven/pom-default.xml"
into 'dist'
rename 'pom-default.xml', project.ext.baseName + '.pom'
}
tasks.register('pomAsc', Copy) {
dependsOn 'signMavenPublication'
description 'Copies the signature of the Maven POM to dist.'
from "${buildDir}/publications/maven/pom-default.xml.asc"
into 'dist'
rename 'pom-default.xml.asc', project.ext.baseName + '.pom.asc'
}
publishing {
publications {
maven(MavenPublication) {
artifactId artifact
from components.java
groupId project.ext.group
pom {
description = 'a JNI interface for Bullet Physics and V-HACD'
developers {
developer {
email = '[email protected]'
name = 'Stephen Gold'
}
}
licenses {
license {
distribution = 'repo'
name = 'New BSD (3-clause) License'
url = 'https://opensource.org/licenses/BSD-3-Clause'
}
}
name = project.ext.group + ':' + artifact
scm {
connection = 'scm:git:git://github.com/stephengold/Libbulletjme.git'
developerConnection = 'scm:git:ssh://github.com:stephengold/Libbulletjme.git'
url = project.ext.websiteUrl + '/tree/master'
}
url = 'https://stephengold.github.io/Libbulletjme'
}
version project.ext.version
}
}
}
publishMavenPublicationToMavenLocal.dependsOn('assemble')
publishMavenPublicationToMavenLocal.doLast {
println 'installed locally as ' + project.ext.baseName
}
// Register signing tasks:
// Signing relies on the existence of 3 properties
// (signing.keyId, signing.password, and signing.secretKeyRingFile)
// which should be stored in ~/.gradle/gradle.properties
signing {
sign configurations.archives
sign publishing.publications.maven
}
tasks.withType(Sign) {
onlyIf { project.hasProperty('signing.keyId') }
}
signMavenPublication.dependsOn('module')
// Register cleanup tasks:
clean.dependsOn('cleanCxx', 'cleanDist', 'cleanLogs')
tasks.register('cleanCxx', Delete) {
delete '.cxx'
}
tasks.register('cleanDist', Delete) { // files to be distributed
delete 'dist'
}
tasks.register('cleanLogs', Delete) { // JVM crash logs
delete fileTree(dir: '.', include: 'hs_err_pid*.log')
}
// Register javadoc to (web)site tasks, triggered by push-master.yml:
tasks.register('copyJavadocToSite') {
dependsOn 'copyMasterJavadocToSite'
}
tasks.register('copyMasterJavadocToSite', Copy) {
dependsOn 'javadoc'
from "${buildDir}/docs/javadoc"
into 'build/site/javadoc/master'
}