blob: 0f8b8a9a5494c7cfda989edeb080b9003c14bae9 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001import org.gradle.internal.os.OperatingSystem
2
3nativeUtils.addWpiNativeUtils()
4nativeUtils.withRoboRIO()
5nativeUtils.withRaspbian()
6nativeUtils.withBionic()
7nativeUtils {
8 wpi {
9 configureDependencies {
10 wpiVersion = "-1"
11 niLibVersion = "2020.10.1"
Austin Schuh1e69f942020-11-14 15:06:14 -080012 opencvVersion = "3.4.7-5"
13 googleTestVersion = "1.9.0-5-437e100-1"
14 imguiVersion = "1.76-9"
15 wpimathVersion = "-1"
Brian Silverman8fce7482020-01-05 13:18:21 -080016 }
17 }
18}
19
20nativeUtils.wpi.addWarnings()
21nativeUtils.wpi.addWarningsAsErrors()
Austin Schuh1e69f942020-11-14 15:06:14 -080022nativeUtils.wpi.addReleaseSymbolGeneration()
Brian Silverman8fce7482020-01-05 13:18:21 -080023
24nativeUtils.setSinglePrintPerPlatform()
Austin Schuh1e69f942020-11-14 15:06:14 -080025nativeUtils.enableSourceLink()
26
27nativeUtils.platformConfigs.each {
28 if (it.name.contains('windows')) return
29 it.linker.args << '-Wl,-rpath,\'$ORIGIN\''
30 if (it.name == 'osxx86-64') {
31 it.linker.args << "-headerpad_max_install_names"
32 }
33}
Brian Silverman8fce7482020-01-05 13:18:21 -080034
35model {
36 components {
37 all {
38 nativeUtils.useAllPlatforms(it)
39 }
40 }
41 binaries {
42 withType(NativeBinarySpec).all {
43 nativeUtils.usePlatformArguments(it)
44 }
45 }
46}
47
48ext.appendDebugPathToBinaries = { binaries->
49 binaries.withType(StaticLibraryBinarySpec) {
50 if (it.buildType.name.contains('debug')) {
51 def staticFileDir = it.staticLibraryFile.parentFile
52 def staticFileName = it.staticLibraryFile.name
53 def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.'))
54 staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.'))
55 staticFileName = staticFileName + 'd' + staticFileExtension
56 def newStaticFile = new File(staticFileDir, staticFileName)
57 it.staticLibraryFile = newStaticFile
58 }
59 }
60 binaries.withType(SharedLibraryBinarySpec) {
61 if (it.buildType.name.contains('debug')) {
62 def sharedFileDir = it.sharedLibraryFile.parentFile
63 def sharedFileName = it.sharedLibraryFile.name
64 def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.'))
65 sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.'))
66 sharedFileName = sharedFileName + 'd' + sharedFileExtension
67 def newSharedFile = new File(sharedFileDir, sharedFileName)
68
69 def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile
70 def sharedLinkFileName = it.sharedLibraryLinkFile.name
71 def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.'))
72 sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.'))
73 sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension
74 def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName)
75
76 it.sharedLibraryLinkFile = newLinkFile
77 it.sharedLibraryFile = newSharedFile
78 }
79 }
80}
81
82ext.createComponentZipTasks = { components, names, base, type, project, func ->
83 def stringNames = names.collect {it.toString()}
84 def configMap = [:]
85 components.each {
86 if (it in NativeLibrarySpec && stringNames.contains(it.name)) {
87 it.binaries.each {
88 if (!it.buildable) return
89 def target = nativeUtils.getPublishClassifier(it)
90 if (configMap.containsKey(target)) {
91 configMap.get(target).add(it)
92 } else {
93 configMap.put(target, [])
94 configMap.get(target).add(it)
95 }
96 }
97 }
98 }
99 def taskList = []
100 def outputsFolder = file("$project.buildDir/outputs")
101 configMap.each { key, value ->
102 def task = project.tasks.create(base + "-${key}", type) {
103 description = 'Creates component archive for platform ' + key
104 destinationDirectory = outputsFolder
105 classifier = key
106 archiveBaseName = '_M_' + base
107 duplicatesStrategy = 'exclude'
108
109 from(licenseFile) {
110 into '/'
111 }
112
113 func(it, value)
114 }
115 taskList.add(task)
116
117 project.build.dependsOn task
118
119 project.artifacts {
120 task
121 }
122 addTaskToCopyAllOutputs(task)
123 }
124 return taskList
125}
126
127ext.includeStandardZipFormat = { task, value ->
128 value.each { binary ->
129 if (binary.buildable) {
130 if (binary instanceof SharedLibraryBinarySpec) {
131 task.dependsOn binary.tasks.link
132 task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) {
133 into nativeUtils.getPlatformPath(binary) + '/shared'
134 }
135 def sharedPath = binary.sharedLibraryFile.absolutePath
136 sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
137
138 task.from(new File(sharedPath + '.pdb')) {
139 into nativeUtils.getPlatformPath(binary) + '/shared'
140 }
141 task.from(binary.sharedLibraryFile) {
142 into nativeUtils.getPlatformPath(binary) + '/shared'
143 }
144 task.from(binary.sharedLibraryLinkFile) {
145 into nativeUtils.getPlatformPath(binary) + '/shared'
146 }
147 } else if (binary instanceof StaticLibraryBinarySpec) {
148 task.dependsOn binary.tasks.createStaticLib
149 task.from(binary.staticLibraryFile) {
150 into nativeUtils.getPlatformPath(binary) + '/static'
151 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800152 def pdbDir = binary.staticLibraryFile.parentFile
153 task.from(pdbDir) {
154 include '*.pdb'
155 into nativeUtils.getPlatformPath(binary) + '/static'
156 }
157 task.from(new File(pdbDir, "SourceLink.json")) {
158 into nativeUtils.getPlatformPath(binary) + '/static'
159 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800160 }
161 }
162 }
163}