blob: a0197b2566273f85861289bbd633760ae876a4e4 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001// These add the nilibraries shared library to the linker args
2def niLibraryPath = file('ni-libraries/lib').path
3def niLibrary = niLibraryPath + "/libnilibraries.so"
4
5configurations.create('armDeps')
6
7dependencies {
8 armDeps ntcoreDep('cpp', 'arm', 'zip')
9 armDeps wpiUtilDep('arm')
10 armDeps cscoreDep('cpp', 'athena-uberzip', 'zip')
11}
12
13def depLocation = "$buildDir/dependencies"
14
15configurations.armDeps.files.each { file ->
16 def depName = file.name.substring(0, file.name.indexOf('-'))
17 def t = tasks.create("downloadArm${depName.capitalize()}", Copy) {
18 description = "Downloads and unzips the $depName dependency."
19 group = 'Dependencies'
20 from zipTree(file)
21 into "$depLocation/${depName.toLowerCase()}"
22 }
23}
24
25task downloadNetworkTables {
26 description = 'Downloads all needed versions of networktables.'
27 group = 'Dependencies'
28 dependsOn downloadArmNetworkTables
29}
30
31task downloadWpiutil {
32 description = 'Downloads all needed versions of WPIUtil.'
33 group = 'Dependencies'
34 dependsOn downloadArmWpiutil
35}
36
37task downloadCscore {
38 description = 'Downloads all needed versions of cscore.'
39 group = 'Dependencies'
40 dependsOn downloadArmCscore
41}
42
43if (enableSimulation) {
44 configurations.create('nativeDeps')
45
46 dependencies {
47 nativeDeps ntcoreDep('cpp', 'desktop', 'zip')
48 nativeDeps wpiUtilDep('desktop')
49 }
50
51 configurations.nativeDeps.files.each { file ->
52 def depName = file.name.substring(0, file.name.indexOf('-'))
53 def t = tasks.create("downloadNative${depName.capitalize()}", Copy) {
54 description = "Downloads and unzips the $depName dependency."
55 group = 'Dependencies'
56 from zipTree(file)
57 into "$depLocation/${depName.toLowerCase()}"
58 }
59 }
60
61 downloadNetworkTables.dependsOn downloadNativeNetworkTables
62 downloadWpiutil.dependsOn downloadNativeWpiutil
63}
64
65def netTablesUnzipLocation = "$depLocation/networktables"
66def wpiUtilUnzipLocation = "$depLocation/wpiutil"
67def csCoreUnzipLocation = "$depLocation/cscore"
68
69task clean(type: Delete) {
70 description = "Deletes the build directory"
71 group = "Build"
72 delete buildDir
73}
74
75if (!hasProperty("toolChainPath")) {
76 ext.toolChainPath = null
77}
78
79subprojects {
80 ext.defineWpiUtilProperties = {
81 ext.wpiUtil = wpiUtilUnzipLocation
82 ext.wpiUtilInclude = "$wpiUtilUnzipLocation/include"
83 ext.wpiUtilLibArmLocation = "$wpiUtilUnzipLocation/Linux/arm"
84 if (enableSimulation) {
85 ext.wpiUtilLibDesktopLocation = "$wpiUtilUnzipLocation/Linux/amd64"
86 }
87 ext.wpiUtilSharedLib = "$wpiUtilLibArmLocation/libwpiutil.so"
88 ext.wpiUtilSharedLibDebug = "$wpiUtilLibArmLocation/libwpiutil.so.debug"
89 ext.wpiUtilStaticLib = "$wpiUtilLibArmLocation/libwpiutil.a"
90
91 ext.addWpiUtilLibraryLinks = { compileTask, linker, targetPlatform ->
92 compileTask.dependsOn project(':').downloadWpiutil
93 String architecture = targetPlatform.architecture
94 if (architecture.contains('arm')) {
95 linker.args wpiUtilSharedLib
96 }
97 }
98
99 ext.addStaticWpiUtilLibraryLinks = { compileTask, linker, targetPlatform ->
100 compileTask.dependsOn project(':').downloadWpiutil
101 String architecture = targetPlatform.architecture
102 if (architecture.contains('arm')) {
103 linker.args wpiUtilStaticLib
104 }
105 }
106 }
107
108 // This defines a project property that projects depending on network tables can use to setup that dependency.
109 ext.defineNetworkTablesProperties = {
110 ext.netTables = netTablesUnzipLocation
111 ext.netTablesInclude = "$netTablesUnzipLocation/include"
112 ext.netLibArmLocation = "$netTablesUnzipLocation/Linux/arm"
113 if (enableSimulation) {
114 ext.netLibDesktopLocation = "$netTablesUnzipLocation/Linux/amd64"
115 }
116 ext.netSharedLib = "$netLibArmLocation/libntcore.so"
117 ext.netSharedLibDebug = "$netLibArmLocation/libntcore.so.debug"
118 ext.netStaticLib = "$netLibArmLocation/libntcore.a"
119
120 ext.addNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform ->
121 compileTask.dependsOn project(':').downloadNetworkTables
122 String architecture = targetPlatform.architecture
123 if (architecture.contains('arm')) {
124 linker.args netSharedLib
125 }
126 addWpiUtilLibraryLinks(compileTask, linker, targetPlatform)
127 }
128
129 ext.addStaticNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform ->
130 compileTask.dependsOn project(':').downloadNetworkTables
131 String architecture = targetPlatform.architecture
132 if (architecture.contains('arm')) {
133 linker.args netStaticLib
134 }
135 addStaticWpiUtilLibraryLinks(compileTask, linker, targetPlatform)
136 }
137 }
138
139 // This defines a project property that projects depending on cscore can use to setup that dependency.
140 ext.defineCsCoreProperties = {
141 ext.csCore = csCoreUnzipLocation
142 ext.csCoreInclude = "$csCoreUnzipLocation/include"
143 ext.csLibArmLocation = "$csCoreUnzipLocation/lib"
144 ext.csSharedLib = "$csLibArmLocation/libcscore.so"
145 ext.cvSharedLib = "$csLibArmLocation/libopencv.so"
146
147 ext.addCsCoreLibraryLinks = { compileTask, linker, targetPlatform ->
148 compileTask.dependsOn project(':').downloadCscore
149 String architecture = targetPlatform.architecture
150 if (architecture.contains('arm')) {
151 linker.args << '-L' + csLibArmLocation
152 linker.args csSharedLib
153 linker.args cvSharedLib
154 }
155 }
156 }
157
158 ext.defineCrossCompilerProperties = {
159 // We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
160 // If this ever changes, the prefix will need to be changed here
161 ext.compilerPrefix = 'arm-frc-linux-gnueabi-'
162 }
163
164 plugins.withType(CppPlugin).whenPluginAdded {
165 defineCrossCompilerProperties()
166 model {
167 buildTypes {
168 debug
169 }
170 // Adds a custom toolchain for our compiler prefix and options
171 toolChains {
172 roborioGcc(Gcc) {
173 if (toolChainPath != null)
174 path toolChainPath
175 target('roborio-arm') {
176 cCompiler.executable = compilerPrefix + cCompiler.executable
177 cppCompiler.executable = compilerPrefix + cppCompiler.executable
178 linker.executable = compilerPrefix + linker.executable
179 assembler.executable = compilerPrefix + assembler.executable
180 // Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
181 // arm, and doesn't understand this flag, so it is removed from both
182 cppCompiler.withArguments { args ->
183 args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
184 args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-Og' << '-g3' << '-rdynamic'
185 //TODO: When the compiler allows us to actually call deprecated functions from within
186 // deprecated function, remove this line (this will cause calling deprecated functions
187 // to be treated as a warning rather than an error).
188 args << '-Wno-error=deprecated-declarations'
189 args.remove('-m32')
190 }
191 linker.withArguments { args ->
192 args << '-rdynamic'
193 args.remove('-m32')
194 }
195 staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
196 }
197 }
198 }
199
200 platforms {
201 'roborio-arm' {
202 architecture 'arm'
203 operatingSystem 'linux'
204 }
205 }
206 }
207
208 ext.niLibraryHeadersRoot = "${rootDir}/ni-libraries/include"
209 ext.niLibraryHeadersChipObject = "${rootDir}/ni-libraries/include/FRC_FPGA_ChipObject"
210
211 ext.binTool = { tool ->
212 if (toolChainPath != null) return "${toolChainPath}/${compilerPrefix}${tool}"
213 return "${compilerPrefix}${tool}"
214 }
215
216 // This task adds the appropriate linker flags for the NI libraries
217 ext.addNiLibraryLinks = { linker, targetPlatform ->
218 String architecture = targetPlatform.architecture
219 if (architecture.contains('arm')){
220 linker.args << '-L' + niLibraryPath
221 linker.args niLibrary
222 }
223 }
224
225 // This task sets up the shared libraries to be stripped
226 ext.debugStripSetup = { project->
227 if (!project.hasProperty('debug')) {
228 project.tasks.whenObjectAdded { task ->
229 def name = task.name.toLowerCase()
230 if (name.contains('link') && name.contains('sharedlibrary')) {
231 def library = task.outputFile.absolutePath
232 def debugLibrary = task.outputFile.absolutePath + ".debug"
233 task.doLast {
234 exec { commandLine binTool('objcopy'), '--only-keep-debug', library, debugLibrary }
235 exec { commandLine binTool('strip'), '-g', library }
236 exec { commandLine binTool('objcopy'), "--add-gnu-debuglink=$debugLibrary", library }
237 }
238 }
239 }
240 }
241 }
242 }
243}