-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
318 lines (277 loc) · 9.98 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
import org.gradle.internal.os.OperatingSystem
import java.nio.file.Files
import java.nio.file.Paths
apply plugin: 'maven-publish'
ext.version = "2.2"
ext.libVersion = "${ext.version.replace(".", "")}"
def getPlatform() {
def platform
def os_name = System.getProperty("os.name")
def os_arch = System.getProperty("os.arch")
if (os_arch == 'amd64') {
os_arch = 'x86_64'
} else if (os_arch == 'aarch64' || os_arch == 'arm64') {
os_arch = 'arm64'
}
if (OperatingSystem.current().isWindows()) {
platform = "windows-${os_arch}"
} else if (OperatingSystem.current().isLinux()) {
platform = "linux-${os_arch}"
} else if (OperatingSystem.current().isMacOsX()) {
platform = "osx-universal"
} else {
platform = "${os_name}-${os_arch}"
}
return platform
}
def getPlatformPath(platform) {
if (platform == "linux-athena") {
return "linux/athena"
} else if (platform == "linux-arm32") {
return "linux/arm32"
} else if (platform == "linux-arm64") {
return "linux/arm64"
} else if (platform == "linux-x86_64") {
return "linux/x86-64"
} else if (platform == "osx-universal") {
return "osx/universal"
} else if (platform == "windows-x86_64") {
return "windows/x86-64"
} else if (platform == "windows-arm64") {
return "windows/arm64"
} else {
return ""
}
}
def platform
if (!project.hasProperty('platform')) {
println "No 'platform' property specified; using the build system's platform"
platform = getPlatform()
} else {
platform = project.platform
}
ext.platformPath = getPlatformPath(platform)
ext.platformClassifier = ext.platformPath.replaceFirst('/', '')
// Determine what repo to publish to. Default is development. Valid options are development and release
if (!project.hasProperty('repo')) {
ext.repo = 'development'
}
def pubVersion = "$ext.version-2"
def outputsFolder = file("$project.buildDir/outputs")
def baseArtifactId = 'ceres'
def artifactGroupId = 'edu.wpi.first.thirdparty.frc2025.ceres'
def zipBaseName = '_GROUP_edu_wpi_first_thirdparty_frc2025_ceres_ID_ceres-cpp_CLS'
def versionFile = file("$outputsFolder/version.txt")
def licenseFiles = files("LICENSE.md", "AMD_LICENSE", "CAMD_LICENSE", "CCOLAMD_LICENSE", "CERES_LICENSE", "CHOLMOD_LICENSE", "COLAMD_LICENSE", "EIGEN_LICENSE", "OPENBLAS_LICENSE",)
def outputClassifierStatic = project.ext.platformClassifier + 'static'
println platformPath
task copyAllOutputs(type: Copy) {
destinationDir = outputsFolder
}
ext.addTaskToCopyAllOutputs = { task ->
copyAllOutputs.dependsOn task
copyAllOutputs.inputs.file task.archiveFile
copyAllOutputs.from task.archiveFile
}
['Debug', 'RelWithDebInfo'].each { buildtype ->
task "configure$buildtype" (type: Exec) {
def baseArgs = ["-B", "build$buildtype", "-DCMAKE_BUILD_TYPE=$buildtype", "-G", "Ninja", "--fresh"]
if (platform == "windows-arm64") {
// Need to set CMAKE_CROSSCOMPILING because getarch can't be crosscompiled and executed on the host.
// Also, TARGET must be generic. You need to set it if crosscompiling, but setting it to ARMV8, it will try to use assembly, which fails on Windows
baseArgs += ["-DCMAKE_CROSSCOMPILING=1", "-DCMAKE_SYSTEM_NAME=Windows", "-DCMAKE_SYSTEM_PROCESSOR=ARM64", "-DTARGET=GENERIC", "-DARCH=ARM64"]
} else if (platform.startsWith("linux-arm64")) {
baseArgs += ["-DTARGET=ARMV8", "-DARCH=ARM64"]
} else if (platform.startsWith("linux-arm32")) {
baseArgs += ["-DTARGET=ARMV6", "-DARCH=ARM"]
}
if (project.hasProperty("toolchain")) {
baseArgs += ["--toolchain=$toolchain"]
}
outputs.dir "build$buildtype"
executable "cmake"
args baseArgs
}
task "build$buildtype" (type: Exec) {
dependsOn "configure$buildtype"
def baseArgs = ["--build", "build$buildtype"]
outputs.dir "build$buildtype"
executable "cmake"
args baseArgs
}
task "install$buildtype" (type: Exec) {
dependsOn "build$buildtype"
def baseArgs = ["--install", "build$buildtype", '--prefix', "build$buildtype/install"]
outputs.dir "build$buildtype/install"
executable "cmake"
args baseArgs
}
task "merge${buildtype}StaticLibs"(type: Exec) {
dependsOn("install$buildtype")
def buildDirectory = Paths.get(projectDir.canonicalPath).resolve("build$buildtype").resolve("install")
if (project.platformPath.startsWith('windows')) {
workingDir buildDirectory.resolve("lib").toString()
executable 'lib'
def inputFiles
if (buildtype == "Debug") {
inputFiles = ['ceres-debug']
} else {
inputFiles = ['ceres']
}
inputFiles += ['amd_static', 'camd_static', 'ccolamd_static', 'colamd_static', 'cholmod_static', 'suitesparseconfig_static', "openblas"]
inputFiles.each {
args "${buildDirectory.resolve("lib")}/$it" + ".lib"
}
args "/OUT:ceres-$buildtype${project.libVersion}.lib"
} else if (project.platformPath.startsWith('osx')) {
executable 'libtool'
workingDir buildDirectory.resolve("lib").toString()
def outputLibName = "libceres-$buildtype${project.libVersion}.a"
def inputFiles
if (buildtype == "Debug") {
inputFiles = ['libceres-debug']
} else {
inputFiles = ['libceres']
}
inputFiles += ['libamd', 'libcamd', 'libccolamd', 'libcolamd', 'libcholmod', 'libsuitesparseconfig']
inputFiles.each {
args "${buildDirectory.resolve("lib")}/$it" + ".a"
}
args '-static', '-o', outputLibName
outputs.file buildDirectory.resolve("lib/${outputLibName}")
} else {
workingDir buildDirectory.resolve("lib").toString()
executable 'ar'
args = ['-M']
def inputString = "create libceres-$buildtype${project.libVersion}.a\n"
def inputFiles
if (buildtype == "Debug") {
inputFiles = ['libceres-debug']
} else {
inputFiles = ['libceres']
}
inputFiles += ['libamd', 'libcamd', 'libccolamd', 'libcolamd', 'libcholmod', 'libsuitesparseconfig', 'libopenblas']
inputFiles.each {
def inFile = 'addlib ' + it + ".a\n"
inputString += inFile
}
inputString += "save\nend\n"
standardInput = new ByteArrayInputStream(inputString.getBytes())
}
}
}
task outputVersions() {
description = 'Prints the versions of this to a file for use by the downstream packaging project'
group = 'Build'
outputs.files(versionFile)
doFirst {
buildDir.mkdir()
outputsFolder.mkdir()
}
doLast {
versionFile.write pubVersion
}
}
task cppHeadersZip(type: Zip) {
dependsOn outputVersions
destinationDirectory = outputsFolder
archiveBaseName = zipBaseName
archiveClassifier = "headers"
from(licenseFiles) {
into '/'
}
from("buildDebug/install/include/ceres") {
exclude "**/miniglog/**"
into '/ceres'
}
from("buildDebug/install/include/ceres/internal/miniglog") {
into '/'
}
from("buildDebug/install/include/openblas") {
into '/openblas'
}
from("buildDebug/install/include/suitesparse") {
into '/suitesparse'
}
includeEmptyDirs = false
// Just need to depend on any install task
dependsOn installDebug
}
task cppSourcesZip(type: Zip) {
// Just need to depend on any build task
dependsOn buildDebug
destinationDirectory = outputsFolder
archiveClassifier = 'sources'
archiveBaseName = zipBaseName
duplicatesStrategy = 'exclude'
from(licenseFiles) {
into '/'
}
from('buildDebug/_deps/') {
into '/'
include "*-src/**/*"
}
includeEmptyDirs = false
}
task cppLibsZipStatic(type: Zip) {
dependsOn mergeRelWithDebInfoStaticLibs
destinationDirectory = outputsFolder
archiveClassifier = outputClassifierStatic
archiveBaseName = zipBaseName
duplicatesStrategy = 'exclude'
from(licenseFiles) {
into '/'
}
from("buildRelWithDebInfo/install/lib") {
into project.platformPath + '/static'
include "**/libceres-RelWithDebInfo${project.libVersion}.a"
include "**/ceres-RelWithDebInfo${project.libVersion}.lib"
include '**/*.pdb'
}
includeEmptyDirs = false
}
task cppLibsZipStaticDebug(type: Zip) {
dependsOn mergeDebugStaticLibs
destinationDirectory = outputsFolder
archiveClassifier = outputClassifierStatic + 'debug'
archiveBaseName = zipBaseName
duplicatesStrategy = 'exclude'
from(licenseFiles) {
into '/'
}
from("buildDebug/install/lib") {
into project.platformPath + '/static'
include "**/libceres-Debug${project.libVersion}.a"
include "**/ceres-Debug${project.libVersion}.lib"
include '**/*.pdb'
}
includeEmptyDirs = false
}
addTaskToCopyAllOutputs(cppSourcesZip)
addTaskToCopyAllOutputs(cppHeadersZip)
if (!project.hasProperty('skipRelease')) {
addTaskToCopyAllOutputs(cppLibsZipStatic)
}
if (!project.hasProperty('skipDebug')) {
addTaskToCopyAllOutputs(cppLibsZipStaticDebug)
}
model {
publishing {
publications {
cpp(MavenPublication) {
artifact cppHeadersZip
artifact cppSourcesZip
artifact cppLibsZipStatic
artifact cppLibsZipStaticDebug
artifactId = "${baseArtifactId}-cpp"
groupId artifactGroupId
version pubVersion
}
}
repositories {
maven {
url "${System.getProperty('user.home')}/releases/maven/${project.repo}"
}
}
}
}