blob: 220ec06a1ce9a51b7c24ceae31391ae4c04a4bb0 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001import org.gradle.internal.os.OperatingSystem
2
Austin Schuh812d0d12021-11-04 20:16:48 -07003nativeUtils.skipInstallPdb = project.hasProperty('buildServer')
4
Brian Silverman8fce7482020-01-05 13:18:21 -08005nativeUtils.addWpiNativeUtils()
6nativeUtils.withRoboRIO()
7nativeUtils.withRaspbian()
8nativeUtils.withBionic()
9nativeUtils {
Austin Schuh812d0d12021-11-04 20:16:48 -070010 wpi {
11 configureDependencies {
12 wpiVersion = "-1"
Austin Schuh75263e32022-02-22 18:05:32 -080013 niLibVersion = "2022.4.0"
Austin Schuh812d0d12021-11-04 20:16:48 -070014 opencvVersion = "4.5.2-1"
15 googleTestVersion = "1.9.0-5-437e100-1"
Austin Schuh75263e32022-02-22 18:05:32 -080016 imguiVersion = "1.86-1"
Austin Schuh812d0d12021-11-04 20:16:48 -070017 wpimathVersion = "-1"
18 }
Brian Silverman8fce7482020-01-05 13:18:21 -080019 }
Brian Silverman8fce7482020-01-05 13:18:21 -080020}
21
22nativeUtils.wpi.addWarnings()
23nativeUtils.wpi.addWarningsAsErrors()
Austin Schuh75263e32022-02-22 18:05:32 -080024
25if (project.name != 'wpilibcExamples') {
26 nativeUtils.wpi.addReleaseSymbolGeneration()
27}
Brian Silverman8fce7482020-01-05 13:18:21 -080028
29nativeUtils.setSinglePrintPerPlatform()
Austin Schuh1e69f942020-11-14 15:06:14 -080030nativeUtils.enableSourceLink()
31
32nativeUtils.platformConfigs.each {
Austin Schuh812d0d12021-11-04 20:16:48 -070033 if (it.name.contains('windows')) {
34 return
35 }
Austin Schuh1e69f942020-11-14 15:06:14 -080036 it.linker.args << '-Wl,-rpath,\'$ORIGIN\''
37 if (it.name == 'osxx86-64') {
38 it.linker.args << "-headerpad_max_install_names"
39 }
40}
Brian Silverman8fce7482020-01-05 13:18:21 -080041
Austin Schuh812d0d12021-11-04 20:16:48 -070042nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings")
43
Brian Silverman8fce7482020-01-05 13:18:21 -080044model {
45 components {
46 all {
47 nativeUtils.useAllPlatforms(it)
48 }
49 }
50 binaries {
51 withType(NativeBinarySpec).all {
52 nativeUtils.usePlatformArguments(it)
53 }
54 }
55}
56
Austin Schuh812d0d12021-11-04 20:16:48 -070057apply plugin: DisableBuildingGTest
58
59if (project.hasProperty('buildServer')) {
60 tasks.withType(org.gradle.nativeplatform.test.tasks.RunTestExecutable) {
61 def exeFile = file(it.executable)
62 def folder = exeFile.parentFile
63
64 it.doLast {
65 folder.deleteDir()
66 }
67 }
68}
69
Brian Silverman8fce7482020-01-05 13:18:21 -080070ext.appendDebugPathToBinaries = { binaries->
71 binaries.withType(StaticLibraryBinarySpec) {
72 if (it.buildType.name.contains('debug')) {
73 def staticFileDir = it.staticLibraryFile.parentFile
74 def staticFileName = it.staticLibraryFile.name
75 def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.'))
76 staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.'))
77 staticFileName = staticFileName + 'd' + staticFileExtension
78 def newStaticFile = new File(staticFileDir, staticFileName)
79 it.staticLibraryFile = newStaticFile
80 }
81 }
82 binaries.withType(SharedLibraryBinarySpec) {
83 if (it.buildType.name.contains('debug')) {
84 def sharedFileDir = it.sharedLibraryFile.parentFile
85 def sharedFileName = it.sharedLibraryFile.name
86 def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.'))
87 sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.'))
88 sharedFileName = sharedFileName + 'd' + sharedFileExtension
89 def newSharedFile = new File(sharedFileDir, sharedFileName)
90
91 def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile
92 def sharedLinkFileName = it.sharedLibraryLinkFile.name
93 def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.'))
94 sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.'))
95 sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension
96 def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName)
97
98 it.sharedLibraryLinkFile = newLinkFile
99 it.sharedLibraryFile = newSharedFile
100 }
101 }
102}
103
104ext.createComponentZipTasks = { components, names, base, type, project, func ->
105 def stringNames = names.collect {it.toString()}
106 def configMap = [:]
107 components.each {
108 if (it in NativeLibrarySpec && stringNames.contains(it.name)) {
109 it.binaries.each {
110 if (!it.buildable) return
Austin Schuh812d0d12021-11-04 20:16:48 -0700111 def target = nativeUtils.getPublishClassifier(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800112 if (configMap.containsKey(target)) {
113 configMap.get(target).add(it)
114 } else {
115 configMap.put(target, [])
116 configMap.get(target).add(it)
117 }
118 }
119 }
120 }
121 def taskList = []
122 def outputsFolder = file("$project.buildDir/outputs")
123 configMap.each { key, value ->
124 def task = project.tasks.create(base + "-${key}", type) {
125 description = 'Creates component archive for platform ' + key
126 destinationDirectory = outputsFolder
127 classifier = key
128 archiveBaseName = '_M_' + base
129 duplicatesStrategy = 'exclude'
130
131 from(licenseFile) {
132 into '/'
133 }
134
135 func(it, value)
136 }
137 taskList.add(task)
138
139 project.build.dependsOn task
140
141 project.artifacts {
142 task
143 }
144 addTaskToCopyAllOutputs(task)
145 }
146 return taskList
147}
148
149ext.includeStandardZipFormat = { task, value ->
150 value.each { binary ->
151 if (binary.buildable) {
152 if (binary instanceof SharedLibraryBinarySpec) {
153 task.dependsOn binary.tasks.link
154 task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) {
155 into nativeUtils.getPlatformPath(binary) + '/shared'
156 }
157 def sharedPath = binary.sharedLibraryFile.absolutePath
158 sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
159
160 task.from(new File(sharedPath + '.pdb')) {
161 into nativeUtils.getPlatformPath(binary) + '/shared'
162 }
163 task.from(binary.sharedLibraryFile) {
164 into nativeUtils.getPlatformPath(binary) + '/shared'
165 }
166 task.from(binary.sharedLibraryLinkFile) {
167 into nativeUtils.getPlatformPath(binary) + '/shared'
168 }
169 } else if (binary instanceof StaticLibraryBinarySpec) {
170 task.dependsOn binary.tasks.createStaticLib
171 task.from(binary.staticLibraryFile) {
172 into nativeUtils.getPlatformPath(binary) + '/static'
173 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800174 def pdbDir = binary.staticLibraryFile.parentFile
175 task.from(pdbDir) {
176 include '*.pdb'
177 into nativeUtils.getPlatformPath(binary) + '/static'
178 }
179 task.from(new File(pdbDir, "SourceLink.json")) {
180 into nativeUtils.getPlatformPath(binary) + '/static'
181 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800182 }
183 }
184 }
185}