-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcppSettings.gradle
243 lines (214 loc) · 9.75 KB
/
cppSettings.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
// These add the nilibraries shared library to the linker args
def niLibraryPath = file('ni-libraries/lib').path
def niLibrary = niLibraryPath + "/libnilibraries.so"
configurations.create('armDeps')
dependencies {
armDeps ntcoreDep('cpp', 'arm', 'zip')
armDeps wpiUtilDep('arm')
armDeps cscoreDep('cpp', 'athena-uberzip', 'zip')
}
def depLocation = "$buildDir/dependencies"
configurations.armDeps.files.each { file ->
def depName = file.name.substring(0, file.name.indexOf('-'))
def t = tasks.create("downloadArm${depName.capitalize()}", Copy) {
description = "Downloads and unzips the $depName dependency."
group = 'Dependencies'
from zipTree(file)
into "$depLocation/${depName.toLowerCase()}"
}
}
task downloadNetworkTables {
description = 'Downloads all needed versions of networktables.'
group = 'Dependencies'
dependsOn downloadArmNetworkTables
}
task downloadWpiutil {
description = 'Downloads all needed versions of WPIUtil.'
group = 'Dependencies'
dependsOn downloadArmWpiutil
}
task downloadCscore {
description = 'Downloads all needed versions of cscore.'
group = 'Dependencies'
dependsOn downloadArmCscore
}
if (enableSimulation) {
configurations.create('nativeDeps')
dependencies {
nativeDeps ntcoreDep('cpp', 'desktop', 'zip')
nativeDeps wpiUtilDep('desktop')
}
configurations.nativeDeps.files.each { file ->
def depName = file.name.substring(0, file.name.indexOf('-'))
def t = tasks.create("downloadNative${depName.capitalize()}", Copy) {
description = "Downloads and unzips the $depName dependency."
group = 'Dependencies'
from zipTree(file)
into "$depLocation/${depName.toLowerCase()}"
}
}
downloadNetworkTables.dependsOn downloadNativeNetworkTables
downloadWpiutil.dependsOn downloadNativeWpiutil
}
def netTablesUnzipLocation = "$depLocation/networktables"
def wpiUtilUnzipLocation = "$depLocation/wpiutil"
def csCoreUnzipLocation = "$depLocation/cscore"
task clean(type: Delete) {
description = "Deletes the build directory"
group = "Build"
delete buildDir
}
if (!hasProperty("toolChainPath")) {
ext.toolChainPath = null
}
subprojects {
ext.defineWpiUtilProperties = {
ext.wpiUtil = wpiUtilUnzipLocation
ext.wpiUtilInclude = "$wpiUtilUnzipLocation/include"
ext.wpiUtilLibArmLocation = "$wpiUtilUnzipLocation/Linux/arm"
if (enableSimulation) {
ext.wpiUtilLibDesktopLocation = "$wpiUtilUnzipLocation/Linux/amd64"
}
ext.wpiUtilSharedLib = "$wpiUtilLibArmLocation/libwpiutil.so"
ext.wpiUtilSharedLibDebug = "$wpiUtilLibArmLocation/libwpiutil.so.debug"
ext.wpiUtilStaticLib = "$wpiUtilLibArmLocation/libwpiutil.a"
ext.addWpiUtilLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').downloadWpiutil
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args wpiUtilSharedLib
}
}
ext.addStaticWpiUtilLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').downloadWpiutil
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args wpiUtilStaticLib
}
}
}
// This defines a project property that projects depending on network tables can use to setup that dependency.
ext.defineNetworkTablesProperties = {
ext.netTables = netTablesUnzipLocation
ext.netTablesInclude = "$netTablesUnzipLocation/include"
ext.netLibArmLocation = "$netTablesUnzipLocation/Linux/arm"
if (enableSimulation) {
ext.netLibDesktopLocation = "$netTablesUnzipLocation/Linux/amd64"
}
ext.netSharedLib = "$netLibArmLocation/libntcore.so"
ext.netSharedLibDebug = "$netLibArmLocation/libntcore.so.debug"
ext.netStaticLib = "$netLibArmLocation/libntcore.a"
ext.addNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').downloadNetworkTables
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args netSharedLib
}
addWpiUtilLibraryLinks(compileTask, linker, targetPlatform)
}
ext.addStaticNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').downloadNetworkTables
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args netStaticLib
}
addStaticWpiUtilLibraryLinks(compileTask, linker, targetPlatform)
}
}
// This defines a project property that projects depending on cscore can use to setup that dependency.
ext.defineCsCoreProperties = {
ext.csCore = csCoreUnzipLocation
ext.csCoreInclude = "$csCoreUnzipLocation/include"
ext.csLibArmLocation = "$csCoreUnzipLocation/lib"
ext.csSharedLib = "$csLibArmLocation/libcscore.so"
ext.cvSharedLib = "$csLibArmLocation/libopencv.so"
ext.addCsCoreLibraryLinks = { compileTask, linker, targetPlatform ->
compileTask.dependsOn project(':').downloadCscore
String architecture = targetPlatform.architecture
if (architecture.contains('arm')) {
linker.args << '-L' + csLibArmLocation
linker.args csSharedLib
linker.args cvSharedLib
}
}
}
ext.defineCrossCompilerProperties = {
// We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
// If this ever changes, the prefix will need to be changed here
ext.compilerPrefix = 'arm-frc-linux-gnueabi-'
}
plugins.withType(CppPlugin).whenPluginAdded {
defineCrossCompilerProperties()
model {
buildTypes {
debug
}
// Adds a custom toolchain for our compiler prefix and options
toolChains {
roborioGcc(Gcc) {
if (toolChainPath != null)
path toolChainPath
target('roborio-arm') {
cCompiler.executable = compilerPrefix + cCompiler.executable
cppCompiler.executable = compilerPrefix + cppCompiler.executable
linker.executable = compilerPrefix + linker.executable
assembler.executable = compilerPrefix + assembler.executable
// Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
// arm, and doesn't understand this flag, so it is removed from both
cppCompiler.withArguments { args ->
args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-Og' << '-g3' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
args.remove('-m32')
}
linker.withArguments { args ->
args << '-rdynamic'
args.remove('-m32')
}
staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
}
}
}
platforms {
'roborio-arm' {
architecture 'arm'
operatingSystem 'linux'
}
}
}
ext.niLibraryHeadersRoot = "${rootDir}/ni-libraries/include"
ext.niLibraryHeadersChipObject = "${rootDir}/ni-libraries/include/FRC_FPGA_ChipObject"
ext.binTool = { tool ->
if (toolChainPath != null) return "${toolChainPath}/${compilerPrefix}${tool}"
return "${compilerPrefix}${tool}"
}
// This task adds the appropriate linker flags for the NI libraries
ext.addNiLibraryLinks = { linker, targetPlatform ->
String architecture = targetPlatform.architecture
if (architecture.contains('arm')){
linker.args << '-L' + niLibraryPath
linker.args niLibrary
}
}
// This task sets up the shared libraries to be stripped
ext.debugStripSetup = { project->
if (!project.hasProperty('debug')) {
project.tasks.whenObjectAdded { task ->
def name = task.name.toLowerCase()
if (name.contains('link') && name.contains('sharedlibrary')) {
def library = task.outputFile.absolutePath
def debugLibrary = task.outputFile.absolutePath + ".debug"
task.doLast {
exec { commandLine binTool('objcopy'), '--only-keep-debug', library, debugLibrary }
exec { commandLine binTool('strip'), '-g', library }
exec { commandLine binTool('objcopy'), "--add-gnu-debuglink=$debugLibrary", library }
}
}
}
}
}
}
}