-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.gradle
462 lines (411 loc) · 17.1 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
// 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
}
// $artifact is set in the gradle.properties file
// or by a -Partifact= option on the command line.
ext {
groupID = 'com.github.stephengold'
lbjVersion = '21.3.2'
baseName = "${artifact}-${lbjVersion}" // 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'
}
// Generate all JNI header files before compiling any C/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.
Linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
Linux_ARM32hf {
architecture 'armhf'
operatingSystem 'linux'
}
Linux_ARM64 {
architecture 'aarch64'
operatingSystem 'linux'
}
MacOSX64 {
architecture 'x86_64'
operatingSystem 'osx'
}
MacOSX_ARM64 {
architecture 'arm-v8'
operatingSystem 'osx'
}
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 on Linux
gcc(Gcc) // default when compiling on Linux
clang(Clang) // used when compiling on macOS
}
components {
// To build native libraries for Android, use "android.gradle" instead.
bulletjme(NativeLibrarySpec) {
targetPlatform 'Linux64'
targetPlatform 'Linux_ARM32hf'
targetPlatform 'Linux_ARM64'
targetPlatform 'MacOSX64'
targetPlatform 'MacOSX_ARM64'
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
buildable = true
// Decide whether to build for the target platform:
if (buildable && project.hasProperty('target')) {
// set in gradle.properties file or -Ptarget= on the command line
String targetArg = project.ext.target
buildable = (pName == targetArg)
}
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')
}
}
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
}
// buildtype-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'
}
// flavor-specific CPP defines:
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 {
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 { // not buildable
//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).configureEach { // 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')
// Register style-checking tasks:
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 = 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 = baseName }
tasks.register('sourcesJar', Jar) {
archiveBaseName = 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', 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', 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', 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', baseName + '.pom.asc'
}
publishing {
publications {
maven(MavenPublication) {
artifactId = artifact
from components.java
groupId = groupID
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 = groupID + ':' + artifact
scm {
connection = 'scm:git:git://github.com/stephengold/Libbulletjme.git'
developerConnection = 'scm:git:ssh://github.com:stephengold/Libbulletjme.git'
url = websiteUrl + '/tree/master'
}
url = websiteUrl
}
version = lbjVersion
}
}
}
publishMavenPublicationToMavenLocal.dependsOn('assemble')
publishMavenPublicationToMavenLocal.doLast {
println 'installed locally as ' + baseName
}
// Register tasks to sign artifacts for publication:
// Signing relies on the existence of 3 properties
// (signing.keyId, signing.password, and signing.secretKeyRingFile)
// which should be set in the ~/.gradle/gradle.properties file
// or by -P options on the command line.
signing {
sign configurations.archives
sign publishing.publications.maven
}
tasks.withType(Sign).configureEach {
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'
}