mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
259 lines
11 KiB
Groovy
259 lines
11 KiB
Groovy
// 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
|
|
}
|
|
|
|
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 {
|
|
gcc(Gcc) {
|
|
target('arm') {
|
|
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
|
|
}
|
|
}
|
|
// Workaround for OS X. Macs for some reason want to use Xcode's gcc
|
|
// (which just wraps Clang), so we have to explicitly make it so
|
|
// that trying to compile with Clang will call gcc instead
|
|
macGcc(Clang) {
|
|
target('arm') {
|
|
cppCompiler.executable = compilerPrefix + 'g++'
|
|
linker.executable = compilerPrefix + 'g++'
|
|
assembler.executable = compilerPrefix + 'gcc'
|
|
// 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 + 'ar'
|
|
}
|
|
}
|
|
}
|
|
|
|
// The only platform is arm linux
|
|
platforms {
|
|
arm {
|
|
architecture 'arm'
|
|
operatingSystem 'linux'
|
|
}
|
|
}
|
|
}
|
|
|
|
ext.niLibraryHeadersRoot = "${rootDir}/ni-libraries/include"
|
|
ext.niLibraryHeadersChipObject = "${rootDir}/ni-libraries/include/FRC_FPGA_ChipObject"
|
|
|
|
// 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 "${compilerPrefix}objcopy", '--only-keep-debug', library, debugLibrary }
|
|
exec { commandLine "${compilerPrefix}strip", '-g', library }
|
|
exec { commandLine "${compilerPrefix}objcopy", "--add-gnu-debuglink=$debugLibrary", library }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|