-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.gradle
121 lines (101 loc) · 3.17 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
allprojects {
repositories {
mavenCentral()
jcenter()
mavenLocal()
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
ext.slf4jVersion = '1.7.25'
group = 'com.sedmelluq'
import org.apache.tools.ant.taskdefs.condition.Os
def getBuildParameters(base, bits) {
def bitSuffix = (bits == 32) ? 'x86' : 'x86-64'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return [
'identifier': "win-${bitSuffix}",
'library': "${base}.dll",
'setupArguments': ["-DBITZ:STRING=${bits}", '-A', (bits == 64 ? 'x64' : 'Win32')],
'buildArguments': ['--config', 'Release'],
'env': [:]
]
} else if (Os.isFamily(Os.FAMILY_MAC)) {
return [
'identifier': 'darwin',
'library': "lib${base}.dylib",
'setupArguments': ["-DBITZ:STRING=${bits}"],
'buildArguments': [],
'env': ['CXXFLAGS': "-m${bits}", 'CFLAGS': "-m${bits}", 'LDFLAGS': "-m${bits}"]
]
} else {
return [
'identifier': "linux-${bitSuffix}",
'library': "lib${base}.so",
'setupArguments': ["-DBITZ:STRING=${bits}"],
'buildArguments': [],
'env': ['CXXFLAGS': "-m${bits}", 'CFLAGS': "-m${bits}", 'LDFLAGS': "-m${bits}"]
]
}
}
def getHomeDirectory() {
def directory = file(System.getProperty('java.home'))
return directory.name == 'jre' ? directory.parentFile.absolutePath : directory.absolutePath
}
def createBuildTask(tasksHolder, config, bits) {
def parameters = getBuildParameters(config.name, bits)
def buildDirectory = "${config.buildBase}/${parameters.identifier}"
def distDirectory = "${config.projectBase}/dist/${parameters.identifier}"
def deployDirectory = "${config.deployBase}/src/main/resources/natives/${parameters.identifier}"
def taskBase = "${config.name}-${bits}"
if (Os.isFamily(Os.FAMILY_MAC) && bits != 64) {
return
}
parameters.env.put('DIST_DIR', distDirectory)
parameters.env.put('JAVA_HOME', getHomeDirectory())
def setupTask = tasksHolder.create("${taskBase}-setup", Exec) {
doFirst {
if (config.setupDoFirst) {
config.setupDoFirst(config, bits)
}
file(buildDirectory).with {
it.deleteDir()
it.mkdirs()
}
}
workingDir buildDirectory
executable 'cmake'
args(parameters.setupArguments + ['../..'])
environment parameters.env
}
def buildTask = tasksHolder.create("${taskBase}-build", Exec) {
workingDir buildDirectory
executable 'cmake'
args(['--build', '.'] + parameters.buildArguments)
environment parameters.env
}
def deployTask = tasksHolder.create("${taskBase}-deploy") { doLast {
copy {
from distDirectory
into deployDirectory
}
}}
tasksHolder.create("${taskBase}-deploy-only") { doLast {
copy {
from distDirectory
into deployDirectory
}
}}
if (config.setupDependency) {
setupTask.dependsOn(config.setupDependency)
}
buildTask.dependsOn(setupTask)
deployTask.dependsOn(buildTask)
config.compileTask.dependsOn(deployTask)
if (!file("${deployDirectory}/${parameters.library}").exists()) {
config.checkTask.dependsOn(deployTask)
}
}