blob: 02c2b68799078772a4713a89825d78a6fb29d5da [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001import edu.wpi.first.nativeutils.*
2import org.gradle.internal.os.OperatingSystem
3
4def windowsCompilerArgs = ['/EHsc', '/DNOMINMAX', '/Zi', '/FS', '/Zc:inline', '/MP4']
5def windowsCCompilerArgs = ['/Zi', '/FS', '/Zc:inline']
6def windowsReleaseCompilerArgs = ['/O2', '/MD']
7def windowsDebugCompilerArgs = ['/Od', '/MDd']
8def windowsLinkerArgs = ['/DEBUG:FULL']
9def windowsReleaseLinkerArgs = ['/OPT:REF', '/OPT:ICF']
10
11def linuxCrossCompilerArgs = ['-std=c++14', '-Wformat=2', '-Wall', '-Wextra', '-Werror', '-pedantic', '-Wno-psabi', '-g',
12 '-Wno-unused-parameter', '-Wno-error=deprecated-declarations', '-fPIC', '-rdynamic',
13 '-pthread']
14def linuxCrossCCompilerArgs = ['-Wformat=2', '-Wall', '-Wextra', '-Werror', '-pedantic', '-Wno-psabi', '-g',
15 '-Wno-unused-parameter', '-fPIC', '-rdynamic', '-pthread']
16def linuxCrossLinkerArgs = ['-rdynamic', '-pthread', '-ldl']
17def linuxCrossReleaseCompilerArgs = ['-O2']
18def linuxCrossDebugCompilerArgs = ['-Og']
19
20def linuxCompilerArgs = ['-std=c++14', '-Wformat=2', '-Wall', '-Wextra', '-Werror', '-pedantic', '-Wno-psabi', '-g',
21 '-Wno-unused-parameter', '-Wno-error=deprecated-declarations', '-fPIC', '-rdynamic',
22 '-pthread']
23def linuxCCompilerArgs = ['-Wformat=2', '-Wall', '-Wextra', '-Werror', '-pedantic', '-Wno-psabi', '-g',
24 '-Wno-unused-parameter', '-fPIC', '-rdynamic', '-pthread']
25def linuxLinkerArgs = ['-rdynamic', '-pthread', '-ldl']
26def linuxReleaseCompilerArgs = ['-O2']
27def linuxDebugCompilerArgs = ['-O0']
28def linux32BitArg = '-m32'
29
30def macCompilerArgs = ['-std=c++14', '-Wall', '-Wextra', '-Werror', '-pedantic-errors', '-fPIC', '-g',
31 '-Wno-unused-parameter', '-Wno-error=deprecated-declarations', '-Wno-missing-field-initializers',
32 '-Wno-unused-private-field', '-Wno-unused-const-variable', '-pthread']
33def macCCompilerArgs = ['-Wall', '-Wextra', '-Werror', '-pedantic-errors', '-fPIC', '-g',
34 '-Wno-unused-parameter', '-Wno-missing-field-initializers', '-Wno-unused-private-field']
35def macObjCLinkerArgs = ['-std=c++14', '-stdlib=libc++','-fobjc-arc', '-g', '-fPIC', '-Wall', '-Wextra', '-Werror']
36def macReleaseCompilerArgs = ['-O2']
37def macDebugCompilerArgs = ['-O0']
38def macLinkerArgs = ['-framework', 'CoreFoundation', '-framework', 'AVFoundation', '-framework', 'Foundation', '-framework', 'CoreMedia', '-framework', 'CoreVideo']
39def mac32BitArg = '-m32'
40
41def buildAll = project.hasProperty('buildAll')
42
43def windows64PlatformDetect = {
44 def arch = System.getProperty("os.arch")
45 def isWin = OperatingSystem.current().isWindows()
46 if (buildAll) {
47 return isWin
48 } else {
49 return isWin && arch == 'amd64'
50 }
51}
52
53def windows32PlatformDetect = {
54 def arch = System.getProperty("os.arch")
55 def isWin = OperatingSystem.current().isWindows()
56 if (buildAll) {
57 return isWin
58 } else {
59 return isWin && arch == 'x86'
60 }
61}
62
63def linux32IntelPlatformDetect = {
64 def arch = System.getProperty("os.arch")
65 def isLinux = OperatingSystem.current().isLinux()
66 def isIntel = (arch == 'amd64' || arch == 'i386')
67 if (buildAll) {
68 return isLinux && isIntel
69 } else {
70 return isLinux && arch == 'i386'
71 }
72}
73
74def linux64IntelPlatformDetect = {
75 def arch = System.getProperty("os.arch")
76 def isLinux = OperatingSystem.current().isLinux()
77 def isIntel = (arch == 'amd64' || arch == 'i386')
78 if (buildAll) {
79 return isLinux && isIntel
80 } else {
81 return isLinux && arch == 'amd64'
82 }
83}
84
85def linuxArmPlatformDetect = {
86 def arch = System.getProperty("os.arch")
87 def isIntel = (arch == 'amd64' || arch == 'i386')
88 return OperatingSystem.current().isLinux() && !isIntel
89}
90
91def mac64PlatformDetect = {
92 def arch = System.getProperty("os.arch")
93 def isMac = OperatingSystem.current().isMacOsX()
94 if (buildAll) {
95 return isMac
96 } else {
97 return isMac && arch == 'x86_64'
98 }
99}
100
101def mac32PlatformDetect = {
102 def arch = System.getProperty("os.arch")
103 def isMac = OperatingSystem.current().isMacOsX()
104 if (buildAll) {
105 return isMac
106 } else {
107 return isMac && arch == 'x86'
108 }
109}
110
111if (!project.hasProperty('skipAthena') && !project.hasProperty('onlyRaspbian')) {
112 model {
113 buildConfigs {
114 roboRio(CrossBuildConfig) {
115 architecture = 'athena'
116 operatingSystem = 'linux'
117 toolChainPrefix = 'arm-frc2019-linux-gnueabi-'
118 compilerArgs = linuxCrossCompilerArgs
119 CCompilerArgs = linuxCrossCCompilerArgs
120 linkerArgs = linuxCrossLinkerArgs
121 debugCompilerArgs = linuxCrossDebugCompilerArgs
122 releaseCompilerArgs = linuxCrossReleaseCompilerArgs
123 stripBuildTypes = ['debug', 'release']
124 compilerFamily = 'Gcc'
125 }
126 }
127 }
128}
129
130if (!project.hasProperty('skipRaspbian') && !project.hasProperty('onlyAthena')) {
131 model {
132 buildConfigs {
133 raspbian(CrossBuildConfig) {
134 architecture = 'raspbian'
135 operatingSystem = 'linux'
136 toolChainPrefix = 'arm-raspbian9-linux-gnueabihf-'
137 compilerArgs = linuxCrossCompilerArgs
138 CCompilerArgs = linuxCrossCCompilerArgs
139 linkerArgs = linuxCrossLinkerArgs
140 debugCompilerArgs = linuxCrossDebugCompilerArgs
141 releaseCompilerArgs = linuxCrossReleaseCompilerArgs
142 stripBuildTypes = ['debug', 'release']
143 compilerFamily = 'Gcc'
144 }
145 }
146 }
147}
148
149if (!project.hasProperty('onlyAthena') && !hasProperty('onlyRaspbian')) {
150 model {
151 buildConfigs {
152 winX86(BuildConfig) {
153 architecture = 'x86'
154 operatingSystem = 'windows'
155 compilerArgs = windowsCompilerArgs
156 CCompilerArgs = windowsCCompilerArgs
157 linkerArgs = windowsLinkerArgs
158 releaseCompilerArgs = windowsReleaseCompilerArgs
159 releaseLinkerArgs = windowsReleaseLinkerArgs
160 debugCompilerArgs = windowsDebugCompilerArgs
161 compilerFamily = 'VisualCpp'
162 detectPlatform = windows32PlatformDetect
163 }
164 winX64(BuildConfig) {
165 architecture = 'x86-64'
166 operatingSystem = 'windows'
167 compilerArgs = windowsCompilerArgs
168 CCompilerArgs = windowsCCompilerArgs
169 linkerArgs = windowsLinkerArgs
170 releaseCompilerArgs = windowsReleaseCompilerArgs
171 releaseLinkerArgs = windowsReleaseLinkerArgs
172 debugCompilerArgs = windowsDebugCompilerArgs
173 compilerFamily = 'VisualCpp'
174 detectPlatform = windows64PlatformDetect
175 }
176 linuxX64(BuildConfig) {
177 architecture = 'x86-64'
178 operatingSystem = 'linux'
179 compilerArgs = linuxCompilerArgs
180 CCompilerArgs = linuxCCompilerArgs
181 linkerArgs = linuxLinkerArgs
182 debugCompilerArgs = linuxDebugCompilerArgs
183 releaseCompilerArgs = linuxReleaseCompilerArgs
184 stripBuildTypes = ['debug', 'release']
185 compilerFamily = 'Gcc'
186 detectPlatform = linux64IntelPlatformDetect
187 }
188 macX64(BuildConfig) {
189 architecture = 'x86-64'
190 operatingSystem = 'osx'
191 compilerArgs = macCompilerArgs
192 CCompilerArgs = macCCompilerArgs
193 debugCompilerArgs = macDebugCompilerArgs
194 releaseCompilerArgs = macReleaseCompilerArgs
195 objCppCompilerArgs = macObjCLinkerArgs
196 linkerArgs = macLinkerArgs
197 compilerFamily = 'Clang'
198 detectPlatform = mac64PlatformDetect
199 }
200 }
201 }
202}
203
204if (project.hasProperty('linuxCross')) {
205 model {
206 buildConfigs {
207 linuxArm(CrossBuildConfig) {
208 architecture = 'nativearm'
209 operatingSystem = 'linux'
210 toolChainPrefix = 'PLEASE_PROVIDE_A_COMPILER_NAME'
211 compilerArgs = linuxCompilerArgs
212 CCompilerArgs = linuxCCompilerArgs
213 linkerArgs = linuxLinkerArgs
214 debugCompilerArgs = linuxDebugCompilerArgs
215 releaseCompilerArgs = linuxReleaseCompilerArgs
216 stripBuildTypes = ['debug', 'release']
217 skipByDefault = true
218 compilerFamily = 'Gcc'
219 }
220 }
221 }
222} else {
223 model {
224 buildConfigs {
225 linuxArm(BuildConfig) {
226 architecture = 'nativearm'
227 operatingSystem = 'linux'
228 compilerArgs = linuxCompilerArgs
229 CCompilerArgs = linuxCCompilerArgs
230 linkerArgs = linuxLinkerArgs
231 debugCompilerArgs = linuxDebugCompilerArgs
232 releaseCompilerArgs = linuxReleaseCompilerArgs
233 stripBuildTypes = ['debug', 'release']
234 compilerFamily = 'Gcc'
235 detectPlatform = linuxArmPlatformDetect
236 }
237 }
238 }
239}
240
241ext.getPublishClassifier = { binary ->
242 return NativeUtils.getPublishClassifier(binary)
243}
244
245ext.getPlatformPath = { binary ->
246 return NativeUtils.getPlatformPath(binary)
247}
248
249ext.appendDebugPathToBinaries = { binaries->
250 binaries.withType(StaticLibraryBinarySpec) {
251 if (it.buildType.name.contains('debug')) {
252 def staticFileDir = it.staticLibraryFile.parentFile
253 def staticFileName = it.staticLibraryFile.name
254 def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.'))
255 staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.'))
256 staticFileName = staticFileName + 'd' + staticFileExtension
257 def newStaticFile = new File(staticFileDir, staticFileName)
258 it.staticLibraryFile = newStaticFile
259 }
260 }
261 binaries.withType(SharedLibraryBinarySpec) {
262 if (it.buildType.name.contains('debug')) {
263 def sharedFileDir = it.sharedLibraryFile.parentFile
264 def sharedFileName = it.sharedLibraryFile.name
265 def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.'))
266 sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.'))
267 sharedFileName = sharedFileName + 'd' + sharedFileExtension
268 def newSharedFile = new File(sharedFileDir, sharedFileName)
269
270 def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile
271 def sharedLinkFileName = it.sharedLibraryLinkFile.name
272 def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.'))
273 sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.'))
274 sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension
275 def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName)
276
277 it.sharedLibraryLinkFile = newLinkFile
278 it.sharedLibraryFile = newSharedFile
279 }
280 }
281}
282
283ext.createComponentZipTasks = { components, names, base, type, project, func ->
284 def stringNames = names.collect {it.toString()}
285 def configMap = [:]
286 components.each {
287 if (it in NativeLibrarySpec && stringNames.contains(it.name)) {
288 it.binaries.each {
289 if (!it.buildable) return
290 def target = getPublishClassifier(it)
291 if (configMap.containsKey(target)) {
292 configMap.get(target).add(it)
293 } else {
294 configMap.put(target, [])
295 configMap.get(target).add(it)
296 }
297 }
298 }
299 }
300 def taskList = []
301 def outputsFolder = file("$project.buildDir/outputs")
302 configMap.each { key, value ->
303 def task = project.tasks.create(base + "-${key}", type) {
304 description = 'Creates component archive for platform ' + key
305 destinationDir = outputsFolder
306 classifier = key
307 baseName = '_M_' + base
308 duplicatesStrategy = 'exclude'
309
310 from(licenseFile) {
311 into '/'
312 }
313
314 func(it, value)
315 }
316 taskList.add(task)
317
318 project.build.dependsOn task
319
320 project.artifacts {
321 task
322 }
323 addTaskToCopyAllOutputs(task)
324 }
325 return taskList
326}
327
328ext.createAllCombined = { list, name, base, type, project ->
329 def outputsFolder = file("$project.buildDir/outputs")
330
331 def task = project.tasks.create(base + "-all", type) {
332 description = "Creates component archive for all classifiers"
333 destinationDir = outputsFolder
334 classifier = "all"
335 baseName = base
336 duplicatesStrategy = 'exclude'
337
338 list.each {
339 if (it.name.endsWith('debug')) return
340 from project.zipTree(it.archivePath)
341 dependsOn it
342 }
343 }
344
345 project.build.dependsOn task
346
347 project.artifacts {
348 task
349 }
350
351 return task
352
353}
354
355ext.includeStandardZipFormat = { task, value ->
356 value.each { binary ->
357 if (binary.buildable) {
358 if (binary instanceof SharedLibraryBinarySpec) {
359 task.dependsOn binary.tasks.link
360 task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) {
361 into getPlatformPath(binary) + '/shared'
362 }
363 def sharedPath = binary.sharedLibraryFile.absolutePath
364 sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
365
366 task.from(new File(sharedPath + '.pdb')) {
367 into getPlatformPath(binary) + '/shared'
368 }
369 task.from(binary.sharedLibraryFile) {
370 into getPlatformPath(binary) + '/shared'
371 }
372 task.from(binary.sharedLibraryLinkFile) {
373 into getPlatformPath(binary) + '/shared'
374 }
375 } else if (binary instanceof StaticLibraryBinarySpec) {
376 task.dependsOn binary.tasks.createStaticLib
377 task.from(binary.staticLibraryFile) {
378 into getPlatformPath(binary) + '/static'
379 }
380 }
381 }
382 }
383}
384
385ext.getCurrentArch = {
386 def arch = System.getProperty('os.arch');
387
388 if (arch.equals("x86") || arch.equals("i386")) {
389 return 'x86'
390 } else if (arch.equals("amd64") || arch.equals("x86_64")) {
391 return 'x86-64'
392 } else {
393 return arch
394 }
395}