Brian Silverman | 890a32a | 2018-03-11 15:41:56 -0700 | [diff] [blame^] | 1 | task downloadWpiUtil() { |
| 2 | description = 'Downloads the C++ ARM wpiutil maven dependency.' |
| 3 | group = 'WPILib' |
| 4 | def depFolder = "$buildDir/dependencies" |
| 5 | def utilZip = file("$depFolder/wpiutil.zip") |
| 6 | outputs.file(utilZip) |
| 7 | def armWpiUtil |
| 8 | |
| 9 | doFirst { |
| 10 | def armWpiUtilDependency = project.dependencies.create("edu.wpi.first.wpilib:wpiutil:+:arm@zip") |
| 11 | def armWpiUtilConfig = project.configurations.detachedConfiguration(armWpiUtilDependency) |
| 12 | armWpiUtilConfig.setTransitive(false) |
| 13 | armWpiUtil = armWpiUtilConfig.files[0].canonicalFile |
| 14 | } |
| 15 | |
| 16 | doLast { |
| 17 | copy { |
| 18 | from armWpiUtil |
| 19 | rename 'wpiutil(.+)', 'wpiutil.zip' |
| 20 | into depFolder |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | def wpiUtilUnzipLocation = "$buildDir/wpiutil" |
| 26 | |
| 27 | // Create a task that will unzip the wpiutil files into a temporary build directory |
| 28 | task unzipWpiUtil(type: Copy) { |
| 29 | description = 'Unzips the wpiutil maven dependency so that the include files and libraries can be used' |
| 30 | group = 'WPILib' |
| 31 | dependsOn downloadWpiUtil |
| 32 | |
| 33 | from zipTree(downloadWpiUtil.outputs.files.singleFile) |
| 34 | into wpiUtilUnzipLocation |
| 35 | } |
| 36 | |
| 37 | ext.defineWpiUtilProperties = { |
| 38 | ext.wpiUtil = wpiUtilUnzipLocation |
| 39 | ext.wpiUtilInclude = "$wpiUtilUnzipLocation/include" |
| 40 | ext.wpiUtilLibArmLocation = "$wpiUtilUnzipLocation/Linux/arm" |
| 41 | ext.wpiUtilSharedLib = "$wpiUtilLibArmLocation/libwpiutil.so" |
| 42 | ext.wpiUtilSharedLibDebug = "$wpiUtilLibArmLocation/libwpiutil.so.debug" |
| 43 | ext.addWpiUtilLibraryLinks = { compileTask, linker, targetPlatform -> |
| 44 | compileTask.dependsOn project(':').unzipWpiUtil |
| 45 | String architecture = targetPlatform.architecture |
| 46 | if (architecture.contains('arm')) { |
| 47 | linker.args wpiUtilSharedLib |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | ext.NIInclude = "$buildDir/NI/include" |
| 53 | |
| 54 | def halUnzipLocation = "$buildDir/hal" |
| 55 | |
| 56 | task downloadHAL() { |
| 57 | description = 'Downloads the C++ ARM HAL maven dependency.' |
| 58 | |
| 59 | group = 'WPILib' |
| 60 | def depFolder = "$buildDir/dependencies" |
| 61 | def libZip = file("$depFolder/hal.zip") |
| 62 | outputs.file(libZip) |
| 63 | def armHal |
| 64 | |
| 65 | |
| 66 | doFirst { |
| 67 | def armHALDependency = project.dependencies.create("edu.wpi.first.wpilib:hal:+@zip") |
| 68 | def armHALConfig = project.configurations.detachedConfiguration(armHALDependency) |
| 69 | armHALConfig.setTransitive(false) |
| 70 | armHal = armHALConfig.files[0].canonicalFile |
| 71 | } |
| 72 | |
| 73 | doLast { |
| 74 | copy { |
| 75 | from armHal |
| 76 | rename 'hal(.+)', 'hal.zip' |
| 77 | into depFolder |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Create a task that will unzip the hal files into a temporary build directory |
| 83 | task unzipHAL(type: Copy) { |
| 84 | description = 'Unzips the hal maven dependency so that the include files and libraries can be used' |
| 85 | group = 'WPILib' |
| 86 | dependsOn downloadHAL |
| 87 | |
| 88 | from zipTree(downloadHAL.outputs.files.singleFile) |
| 89 | into halUnzipLocation |
| 90 | } |
| 91 | |
| 92 | ext.defineHALProperties = { |
| 93 | ext.hal = halUnzipLocation |
| 94 | ext.halInclude = "$halUnzipLocation/include" |
| 95 | ext.halLocation = "$halUnzipLocation/lib" |
| 96 | ext.halSharedLib = "$halLocation/libHALAthena.so" |
| 97 | |
| 98 | ext.addHalLibraryLinks = { compileTask, linker, targetPlatform -> |
| 99 | compileTask.dependsOn project(':').unzipHAL |
| 100 | String architecture = targetPlatform.architecture |
| 101 | if (architecture.contains('arm')) { |
| 102 | // Grab all the shared libraries and link them |
| 103 | linker.args halSharedLib |
| 104 | linker.args "$halLocation/libnilibraries.so" |
| 105 | |
| 106 | def libraryPath = halLocation |
| 107 | |
| 108 | linker.args << '-L' + libraryPath |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | task downloadNetworkTables() { |
| 114 | description = 'Downloads the C++ ARM NetworkTables maven dependency.' |
| 115 | group = 'WPILib' |
| 116 | def depFolder = "$buildDir/dependencies" |
| 117 | def ntZip = file("$depFolder/ntcore.zip") |
| 118 | outputs.file(ntZip) |
| 119 | def armNetTables |
| 120 | |
| 121 | doFirst { |
| 122 | def armNtDependency = project.dependencies.create('edu.wpi.first.wpilib.networktables.cpp:NetworkTables:+:arm@zip') |
| 123 | def armConfig = project.configurations.detachedConfiguration(armNtDependency) |
| 124 | armConfig.setTransitive(false) |
| 125 | armNetTables = armConfig.files[0].canonicalFile |
| 126 | } |
| 127 | |
| 128 | doLast { |
| 129 | copy { |
| 130 | from armNetTables |
| 131 | rename 'NetworkTables(.+)', 'ntcore.zip' |
| 132 | into depFolder |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | def netTablesUnzipLocation = "$buildDir/networktables" |
| 138 | |
| 139 | // Create a task that will unzip the networktables files into a temporary build directory |
| 140 | task unzipNetworkTables(type: Copy) { |
| 141 | description = 'Unzips the networktables maven dependency so that the include files and libraries can be used' |
| 142 | group = 'WPILib' |
| 143 | dependsOn downloadNetworkTables |
| 144 | |
| 145 | from zipTree(downloadNetworkTables.outputs.files.singleFile) |
| 146 | into netTablesUnzipLocation |
| 147 | } |
| 148 | |
| 149 | // This defines a project property that projects depending on network tables can use to setup that dependency. |
| 150 | ext.defineNetworkTablesProperties = { |
| 151 | ext.netTables = netTablesUnzipLocation |
| 152 | ext.netTablesInclude = "$netTablesUnzipLocation/include" |
| 153 | ext.netLibArmLocation = "$netTablesUnzipLocation/Linux/arm" |
| 154 | ext.netSharedLib = "$netLibArmLocation/libntcore.so" |
| 155 | ext.netSharedLibDebug = "$netLibArmLocation/libntcore.so.debug" |
| 156 | |
| 157 | ext.addNetworkTablesLibraryLinks = { compileTask, linker, targetPlatform -> |
| 158 | compileTask.dependsOn project(':').unzipNetworkTables |
| 159 | String architecture = targetPlatform.architecture |
| 160 | if (architecture.contains('arm')) { |
| 161 | linker.args netSharedLib |
| 162 | } |
| 163 | addWpiUtilLibraryLinks(compileTask, linker, targetPlatform) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | |
| 168 | def wpilibUnzipLocation = "$buildDir/wpilib" |
| 169 | |
| 170 | task downloadWpilib() { |
| 171 | description = 'Downloads the C++ ARM wpilib maven dependency.' |
| 172 | |
| 173 | group = 'WPILib' |
| 174 | def depFolder = "$buildDir/dependencies" |
| 175 | def libZip = file("$depFolder/athena-wpilibc.zip") |
| 176 | outputs.file(libZip) |
| 177 | def armWPILib |
| 178 | |
| 179 | |
| 180 | doFirst { |
| 181 | def armWpiLibDependency = project.dependencies.create("edu.wpi.first.wpilibc:athena:+@zip") |
| 182 | def armWpiLibConfig = project.configurations.detachedConfiguration(armWpiLibDependency) |
| 183 | armWpiLibConfig.setTransitive(false) |
| 184 | armWPILib = armWpiLibConfig.files[0].canonicalFile |
| 185 | } |
| 186 | |
| 187 | doLast { |
| 188 | copy { |
| 189 | from armWPILib |
| 190 | rename 'athena(.+)', 'athena-wpilibc.zip' |
| 191 | into depFolder |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // Create a task that will unzip the wpilib files into a temporary build directory |
| 197 | task unzipWpilib(type: Copy) { |
| 198 | description = 'Unzips the wpilib maven dependency so that the include files and libraries can be used' |
| 199 | group = 'WPILib' |
| 200 | dependsOn downloadWpilib |
| 201 | |
| 202 | from zipTree(downloadWpilib.outputs.files.singleFile) |
| 203 | into wpilibUnzipLocation |
| 204 | } |
| 205 | |
| 206 | ext.defineWpiLibProperties = { |
| 207 | ext.wpilib = wpilibUnzipLocation |
| 208 | ext.wpilibInclude = "$wpilibUnzipLocation/include" |
| 209 | ext.wpilibLocation = "$wpilibUnzipLocation/lib" |
| 210 | ext.wpilibSharedLib = "$wpilibLocation/libwpilibc.so" |
| 211 | |
| 212 | ext.addWpilibLibraryLinks = { compileTask, linker, targetPlatform -> |
| 213 | compileTask.dependsOn project(':').unzipWpilib |
| 214 | String architecture = targetPlatform.architecture |
| 215 | if (architecture.contains('arm')) { |
| 216 | // Grab all the shared libraries and link them |
| 217 | linker.args wpilibSharedLib |
| 218 | |
| 219 | def libraryPath = wpilibLocation |
| 220 | |
| 221 | linker.args << '-L' + libraryPath |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | def cscoreUnzipLocation = "$buildDir/cscore" |
| 227 | |
| 228 | task downloadCsCore() { |
| 229 | description = 'Downloads the C++ ARM CsCore maven dependency.' |
| 230 | |
| 231 | group = 'WPILib' |
| 232 | def depFolder = "$buildDir/dependencies" |
| 233 | def libZip = file("$depFolder/cscore.zip") |
| 234 | outputs.file(libZip) |
| 235 | def armCsCore |
| 236 | |
| 237 | |
| 238 | doFirst { |
| 239 | def armCsDependency = project.dependencies.create("edu.wpi.cscore.cpp:cscore:+:athena-uberzip@zip") |
| 240 | def armCsConfig = project.configurations.detachedConfiguration(armCsDependency) |
| 241 | armCsConfig.setTransitive(false) |
| 242 | armCsCore = armCsConfig.files[0].canonicalFile |
| 243 | } |
| 244 | |
| 245 | doLast { |
| 246 | copy { |
| 247 | from armCsCore |
| 248 | rename 'cscore(.+)', 'cscore.zip' |
| 249 | into depFolder |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // Create a task that will unzip the cscore files into a temporary build directory |
| 255 | task unzipCsCore(type: Copy) { |
| 256 | description = 'Unzips the cscore maven dependency so that the include files and libraries can be used' |
| 257 | group = 'WPILib' |
| 258 | dependsOn downloadCsCore |
| 259 | |
| 260 | from zipTree(downloadCsCore.outputs.files.singleFile) |
| 261 | into cscoreUnzipLocation |
| 262 | } |
| 263 | |
| 264 | ext.defineCsCoreProperties = { |
| 265 | ext.cscore = cscoreUnzipLocation |
| 266 | ext.cscoreInclude = "$cscoreUnzipLocation/include" |
| 267 | ext.cscoreLocation = "$cscoreUnzipLocation/lib" |
| 268 | ext.opencvSharedLib = "$cscoreLocation/libopencv.so" |
| 269 | ext.cscoreSharedLib = "$cscoreLocation/libcscore.so" |
| 270 | |
| 271 | ext.addCsCoreLibraryLinks = { compileTask, linker, targetPlatform -> |
| 272 | compileTask.dependsOn project(':').unzipCsCore |
| 273 | String architecture = targetPlatform.architecture |
| 274 | if (architecture.contains('arm')) { |
| 275 | // Grab all the shared libraries and link them |
| 276 | linker.args opencvSharedLib |
| 277 | linker.args cscoreSharedLib |
| 278 | |
| 279 | def libraryPath = cscoreLocation |
| 280 | |
| 281 | linker.args << '-L' + libraryPath |
| 282 | } |
| 283 | } |
| 284 | } |