-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdependencies.gradle
250 lines (223 loc) · 10.1 KB
/
dependencies.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
ext.getOpenCvPlatformPackage = { targetPlatform ->
if (targetPlatform.architecture.arm && project.hasProperty('compilerPrefix') && project.hasProperty('armSuffix')) {
return "linux-arm${project.armSuffix}"
} else if (targetPlatform.architecture.arm) {
return 'linux-arm'
} else if (targetPlatform.operatingSystem.linux) {
if (targetPlatform.architecture.amd64) {
return 'linux-x86_64'
} else {
return 'linux-' + targetPlatform.architecture.name
}
} else if (targetPlatform.operatingSystem.windows) {
if (targetPlatform.architecture.amd64) {
return 'windows-x86_64_2015'
} else {
return 'windows-' + targetPlatform.architecture.name + '_2015'
}
} else if (targetPlatform.operatingSystem.macOsX) {
if (targetPlatform.architecture.amd64) {
return 'osx-x86_64'
} else {
return 'osx-' + targetPlatform.architecture.name
}
} else {
return targetPlatform.operatingSystem.name + '-' + targetPlatform.architecture.name
}
}
task downloadOpenCvHeaders() {
description = 'Downloads the OpenCV Headers maven dependency.'
group = 'WPILib'
def depFolder = "${buildDir}/dependencies"
def openCvHeadersZip = file("${depFolder}/opencv-headers.zip")
outputs.file(openCvHeadersZip)
def openCvHeaders
doFirst {
def openCvHeadersDependency = project.dependencies.create("org.opencv:opencv-headers:3.1.0@jar")
def openCvHeadersConfig = project.configurations.detachedConfiguration(openCvHeadersDependency)
openCvHeadersConfig.setTransitive(false)
openCvHeaders = openCvHeadersConfig.files[0].canonicalFile
}
doLast {
copy {
from openCvHeaders
rename 'opencv-headers(.+)', 'opencv-headers.zip'
into depFolder
}
}
}
ext.useOpenCv = { project ->
def openCvUnzipLocation = "${project.buildDir}/opencv"
project.tasks.create(name: "unzipOpenCvHeaders", type: Copy) {
description = 'Unzips the OpenCV maven dependency so that the include files and libraries can be used'
group = 'OpenCv'
dependsOn downloadOpenCvHeaders
from zipTree(downloadOpenCvHeaders.outputs.files.singleFile)
into "${openCvUnzipLocation}/include"
}
project.ext.openCv = openCvUnzipLocation
project.ext.openCvInclude = "$openCvUnzipLocation/include"
project.ext.addOpenCvLibraryLinks = { compileTask, linker, targetPlatform ->
def openCvPlatform = project.getOpenCvPlatformPackage(targetPlatform)
def openCvNativesFolder = "${project.openCv}/${openCvPlatform}"
if (project.tasks.findByPath("unzipOpenCvNatives_${openCvPlatform}") == null) {
project.tasks.create(name: "downloadOpenCvNatives_${openCvPlatform}") {
description = 'Downloads the OpenCV natives maven dependency.'
group = 'OpenCv'
def depFolder = "${project.buildDir}/dependencies"
def openCvNativesZip = file("${depFolder}/opencv-natives-${openCvPlatform}.zip")
outputs.file(openCvNativesZip)
def openCvNatives
doFirst {
def openCvNativesDependency = project.dependencies.create("org.opencv:opencv-natives:3.1.0:${openCvPlatform}@jar")
def openCvNativesConfig = project.configurations.detachedConfiguration(openCvNativesDependency)
openCvNativesConfig.setTransitive(false)
openCvNatives = openCvNativesConfig.files[0].canonicalFile
}
doLast {
copy {
from openCvNatives
rename 'opencv-natives(.+)', "opencv-natives-${openCvPlatform}.zip"
into depFolder
}
}
}
project.tasks.create(name: "unzipOpenCvNatives_${openCvPlatform}", type: Copy) {
description = 'Unzips the OpenCV maven dependency so that the include files and libraries can be used'
group = 'OpenCv'
dependsOn "downloadOpenCvNatives_${openCvPlatform}"
from zipTree(project.tasks["downloadOpenCvNatives_${openCvPlatform}"].outputs.files.singleFile)
into openCvNativesFolder
exclude '**/MANIFEST.MF'
}
}
compileTask.dependsOn "unzipOpenCvHeaders", "unzipOpenCvNatives_${openCvPlatform}"
if (targetPlatform.operatingSystem.windows) {
linker.args new String("${openCvNativesFolder}\\opencv.lib").replace('/', '\\')
linker.args new String("${openCvNativesFolder}\\Release\\libjpeg.lib").replace('/', '\\')
linker.args new String("${openCvNativesFolder}\\Release\\libpng.lib").replace('/', '\\')
linker.args new String("${openCvNativesFolder}\\Release\\zlib.lib").replace('/', '\\')
linker.args "kernel32.lib"
linker.args "user32.lib"
linker.args "gdi32.lib"
linker.args "Ole32.lib"
linker.args "OleAut32.lib"
linker.args "comdlg32.lib"
linker.args "advapi32.lib"
linker.args "Vfw32.lib"
} else {
linker.args "-L${openCvNativesFolder}"
linker.args "-lopencv"
linker.args "-ldl"
}
}
}
ext.getWpiLibDeps = { project, cs = false ->
if (project.isArm && project.hasProperty('compilerPrefix') && project.hasProperty('armSuffix')) {
return "arm${project.armSuffix}"
} else if (project.isArm) {
return 'arm'
} else if (System.getProperty("os.name").startsWith("Windows")) {
return 'windows2015'
} else if (cs) {
return 'linux'
} else {
return 'desktop'
}
}
ext.useWpiUtil = { project ->
project.tasks.create(name: "downloadWpiUtil") {
description = 'Downloads the wpiutil maven dependency.'
group = 'WPILib'
def depFolder = "${project.buildDir}/dependencies"
def utilZip = file("${depFolder}/wpiutil.zip")
outputs.file(utilZip)
def wpiUtil
doFirst {
def wpiUtilDependency = project.dependencies.create("edu.wpi.first.wpilib:wpiutil:+:${project.getWpiLibDeps(project)}@zip")
def wpiUtilConfig = project.configurations.detachedConfiguration(wpiUtilDependency)
wpiUtilConfig.setTransitive(false)
wpiUtil = wpiUtilConfig.files[0].canonicalFile
}
doLast {
copy {
from wpiUtil
rename 'wpiutil(.+)', 'wpiutil.zip'
into depFolder
}
}
}
def wpiUtilUnzipLocation = "${project.buildDir}/wpiutil"
// Create a task that will unzip the wpiutil files into a temporary build directory
project.tasks.create(name: "unzipWpiUtil", type: Copy) {
description = 'Unzips the wpiutil maven dependency so that the include files and libraries can be used'
group = 'WPILib'
dependsOn project.tasks.downloadWpiUtil
from zipTree(project.tasks.downloadWpiUtil.outputs.files.singleFile)
into wpiUtilUnzipLocation
}
project.ext.wpiUtil = wpiUtilUnzipLocation
project.ext.wpiUtilInclude = "$wpiUtilUnzipLocation/include"
project.ext.addWpiUtilStaticLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project.tasks.unzipWpiUtil
String path = project.getPlatformPath2(targetPlatform)
if (targetPlatform.operatingSystem.windows) {
linker.args "${project.wpiUtil}/${path}/wpiutil.lib"
} else if (targetPlatform.operatingSystem.macOsX) {
// TODO: Figure out Mac OS
linker.args << "-force_load ${project.wpiUtil}/${path}/libwpiutil.a"
} else {
linker.args << "-Wl,--whole-archive"
linker.args "${project.wpiUtil}/${path}/libwpiutil.a"
linker.args << "-Wl,--no-whole-archive"
}
}
}
ext.useCsCore = { project ->
project.tasks.create(name: "downloadCsCore") {
description = 'Downloads the cscore maven dependency.'
group = 'WPILib'
def depFolder = "${project.buildDir}/dependencies"
def cscoreZip = file("${depFolder}/cscore.zip")
outputs.file(cscoreZip)
def csCore
doFirst {
def csCoreDependency = project.dependencies.create("edu.wpi.cscore.cpp:cscore:+:${project.getWpiLibDeps(project, true)}@zip")
def csCoreConfig = project.configurations.detachedConfiguration(csCoreDependency)
csCoreConfig.setTransitive(false)
csCore = csCoreConfig.files[0].canonicalFile
}
doLast {
copy {
from csCore
rename 'cscore(.+)', 'cscore.zip'
into depFolder
}
}
}
def csUnzipLocation = "${project.buildDir}/cscore"
// Create a task that will unzip the wpiutil files into a temporary build directory
project.tasks.create(name: "unzipCsCore", type: Copy) {
description = 'Unzips the cscore maven dependency so that the include files and libraries can be used'
group = 'WPILib'
dependsOn project.tasks.downloadCsCore
from zipTree(project.tasks.downloadCsCore.outputs.files.singleFile)
into csUnzipLocation
}
project.ext.csCore = csUnzipLocation
project.ext.csCoreInclude = "$csUnzipLocation/include"
project.ext.addCsCoreStaticLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project.tasks.unzipCsCore
String path = project.getPlatformPath2(targetPlatform)
if (targetPlatform.operatingSystem.windows) {
linker.args "${project.csCore}/${path}/cscore.lib"
} else if (targetPlatform.operatingSystem.macOsX) {
// TODO: Figure out Mac OS X
linker.args << "-force_load ${project.csCore}/${path}/libcscore.a"
} else {
linker.args << "-Wl,--whole-archive"
linker.args "${project.csCore}/${path}/libcscore.a"
linker.args << "-Wl,--no-whole-archive"
}
}
}