forked from scanse/sweep-sdk
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcpp.gradle
101 lines (88 loc) · 3.52 KB
/
cpp.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
defineWpiUtilProperties()
defineHALProperties()
defineNetworkTablesProperties()
defineWpiLibProperties()
defineCsCoreProperties()
def cppSetupModel = { project ->
project.model {
components {
sweep(NativeLibrarySpec) {
targetPlatform 'arm'
setupDefines(project, binaries)
binaries.all {
tasks.withType(CppCompile) {
cppCompiler.args "-DNAMESPACED_WPILIB"
addHalLibraryLinks(it, linker, targetPlatform)
addWpiUtilLibraryLinks(it, linker, targetPlatform)
addNetworkTablesLibraryLinks(it, linker, targetPlatform)
addWpilibLibraryLinks(it, linker, targetPlatform)
addCsCoreLibraryLinks(it, linker, targetPlatform)
}
}
sources {
cpp {
source {
srcDirs = [cppSrc, cppLibrarySrc]
includes = ["**/*.cpp"]
}
exportedHeaders {
srcDirs = [cppInclude, driverLibraryInclude, cppLibraryInclude, wpilibInclude, halInclude, wpiUtilInclude, netTablesInclude, cscoreInclude]
includes = ['**/*.h']
}
if (useDriver) {
lib project: ':arm:driver', library: 'sweepDriver', linkage: 'static'
}
}
}
}
}
}
}
ext.mergeStaticSetup = { pjt ->
if (combineStaticLibs && useDriver) {
pjt.tasks.whenObjectAdded { task ->
def name = task.name.toLowerCase()
if (name.contains('create') && name.contains('staticlibrary')) {
def libraryPath = task.outputFile.parent
def library = file(task.outputFile.absolutePath)
project(':arm:driver').model {
binaries {
withType(StaticLibraryBinarySpec) { binary ->
ext.driverLibrary = new File(binary.staticLibraryFile.absolutePath)
}
}
}
task.doLast {
library.renameTo(file("${library}.m"))
copy {
from driverLibrary
into libraryPath
}
ByteArrayOutputStream mriFile = new ByteArrayOutputStream()
mriFile << "create lib${libraryName}.a\n"
mriFile << "addlib lib${libraryName}.a.m\n"
mriFile << "addlib lib${libraryName}Driver.a\n"
mriFile << "save\n"
mriFile << "end\n"
def stdIn = new ByteArrayInputStream(mriFile.buf)
def tool = project(':arm:driver').binTools('ar')
exec {
standardInput = stdIn
workingDir = libraryPath
commandLine tool, '-M'
}
}
}
}
}
}
project(':arm:cpp') {
apply plugin: 'cpp'
apply from: "${rootDir}/toolchains/arm.gradle"
if (!useDriver) {
apply from: "${rootDir}/java/java.gradle"
}
cppSetupModel(project)
project.debugStripSetup()
mergeStaticSetup(project)
}