blob: 5acadb030bcc774e57a1aa67e1df01384c10a431 [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
James Kuszmaulcf324122023-01-14 14:07:17 -08005if (project.hasProperty('ciDebugOnly')) {
6 toolchainsPlugin.registerReleaseBuildType = false
7}
8
Brian Silverman8fce7482020-01-05 13:18:21 -08009nativeUtils.addWpiNativeUtils()
James Kuszmaulcf324122023-01-14 14:07:17 -080010nativeUtils.withCrossRoboRIO()
11nativeUtils.withCrossLinuxArm32()
12nativeUtils.withCrossLinuxArm64()
Brian Silverman8fce7482020-01-05 13:18:21 -080013nativeUtils {
Austin Schuh812d0d12021-11-04 20:16:48 -070014 wpi {
15 configureDependencies {
James Kuszmaulb13e13f2023-11-22 20:44:04 -080016 opencvYear = "frc2024"
17 googleTestYear = "frc2024"
Maxwell Henderson80bec322024-01-09 15:48:44 -080018 niLibVersion = "2024.2.1"
James Kuszmaulb13e13f2023-11-22 20:44:04 -080019 opencvVersion = "4.8.0-2"
20 googleTestVersion = "1.14.0-1"
Austin Schuh812d0d12021-11-04 20:16:48 -070021 }
Brian Silverman8fce7482020-01-05 13:18:21 -080022 }
Brian Silverman8fce7482020-01-05 13:18:21 -080023}
24
25nativeUtils.wpi.addWarnings()
26nativeUtils.wpi.addWarningsAsErrors()
Austin Schuh75263e32022-02-22 18:05:32 -080027
28if (project.name != 'wpilibcExamples') {
29 nativeUtils.wpi.addReleaseSymbolGeneration()
30}
Brian Silverman8fce7482020-01-05 13:18:21 -080031
32nativeUtils.setSinglePrintPerPlatform()
Austin Schuh1e69f942020-11-14 15:06:14 -080033nativeUtils.enableSourceLink()
34
James Kuszmaulcf324122023-01-14 14:07:17 -080035nativeUtils.wpi.addMacMinimumVersionArg()
36
Austin Schuh1e69f942020-11-14 15:06:14 -080037nativeUtils.platformConfigs.each {
James Kuszmaulcf324122023-01-14 14:07:17 -080038 if (it.name.contains('osx')) {
39 it.linker.args << '-Wl,-rpath,\'@loader_path\''
Austin Schuh1e69f942020-11-14 15:06:14 -080040 it.linker.args << "-headerpad_max_install_names"
James Kuszmaulcf324122023-01-14 14:07:17 -080041 } else if (it.name.contains('linux')) {
42 it.linker.args << '-Wl,-rpath,\'$ORIGIN\''
Austin Schuh1e69f942020-11-14 15:06:14 -080043 }
44}
Brian Silverman8fce7482020-01-05 13:18:21 -080045
James Kuszmaulb13e13f2023-11-22 20:44:04 -080046// Compress debug info on Linux
47nativeUtils.platformConfigs.each {
48 if (it.name.contains('linux')) {
49 it.cppCompiler.debugArgs.add("-gz=zlib")
50 }
51}
52
James Kuszmaulcf324122023-01-14 14:07:17 -080053// NativeUtils adds the following OpenCV warning suppression for Linux, but not
54// for macOS
55// https://github.com/opencv/opencv/issues/20269
56nativeUtils.platformConfigs.osxuniversal.cppCompiler.args.add("-Wno-deprecated-anon-enum-enum-conversion")
57
Austin Schuh812d0d12021-11-04 20:16:48 -070058nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings")
59
Brian Silverman8fce7482020-01-05 13:18:21 -080060model {
61 components {
62 all {
63 nativeUtils.useAllPlatforms(it)
64 }
65 }
66 binaries {
67 withType(NativeBinarySpec).all {
68 nativeUtils.usePlatformArguments(it)
69 }
70 }
71}
72
Austin Schuh812d0d12021-11-04 20:16:48 -070073apply plugin: DisableBuildingGTest
74
75if (project.hasProperty('buildServer')) {
76 tasks.withType(org.gradle.nativeplatform.test.tasks.RunTestExecutable) {
77 def exeFile = file(it.executable)
78 def folder = exeFile.parentFile
79
80 it.doLast {
81 folder.deleteDir()
82 }
83 }
84}
85
Brian Silverman8fce7482020-01-05 13:18:21 -080086ext.appendDebugPathToBinaries = { binaries->
87 binaries.withType(StaticLibraryBinarySpec) {
88 if (it.buildType.name.contains('debug')) {
89 def staticFileDir = it.staticLibraryFile.parentFile
90 def staticFileName = it.staticLibraryFile.name
91 def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.'))
92 staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.'))
93 staticFileName = staticFileName + 'd' + staticFileExtension
94 def newStaticFile = new File(staticFileDir, staticFileName)
95 it.staticLibraryFile = newStaticFile
96 }
97 }
98 binaries.withType(SharedLibraryBinarySpec) {
99 if (it.buildType.name.contains('debug')) {
100 def sharedFileDir = it.sharedLibraryFile.parentFile
101 def sharedFileName = it.sharedLibraryFile.name
102 def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.'))
103 sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.'))
104 sharedFileName = sharedFileName + 'd' + sharedFileExtension
105 def newSharedFile = new File(sharedFileDir, sharedFileName)
106
107 def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile
108 def sharedLinkFileName = it.sharedLibraryLinkFile.name
109 def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.'))
110 sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.'))
111 sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension
112 def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName)
113
114 it.sharedLibraryLinkFile = newLinkFile
115 it.sharedLibraryFile = newSharedFile
116 }
117 }
118}
119
120ext.createComponentZipTasks = { components, names, base, type, project, func ->
121 def stringNames = names.collect {it.toString()}
122 def configMap = [:]
123 components.each {
124 if (it in NativeLibrarySpec && stringNames.contains(it.name)) {
125 it.binaries.each {
126 if (!it.buildable) return
Austin Schuh812d0d12021-11-04 20:16:48 -0700127 def target = nativeUtils.getPublishClassifier(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800128 if (configMap.containsKey(target)) {
129 configMap.get(target).add(it)
130 } else {
131 configMap.put(target, [])
132 configMap.get(target).add(it)
133 }
134 }
135 }
136 }
137 def taskList = []
138 def outputsFolder = file("$project.buildDir/outputs")
139 configMap.each { key, value ->
140 def task = project.tasks.create(base + "-${key}", type) {
141 description = 'Creates component archive for platform ' + key
142 destinationDirectory = outputsFolder
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800143 archiveClassifier = key
Brian Silverman8fce7482020-01-05 13:18:21 -0800144 archiveBaseName = '_M_' + base
145 duplicatesStrategy = 'exclude'
146
147 from(licenseFile) {
148 into '/'
149 }
150
151 func(it, value)
152 }
153 taskList.add(task)
154
155 project.build.dependsOn task
156
157 project.artifacts {
158 task
159 }
160 addTaskToCopyAllOutputs(task)
161 }
162 return taskList
163}
164
165ext.includeStandardZipFormat = { task, value ->
166 value.each { binary ->
167 if (binary.buildable) {
168 if (binary instanceof SharedLibraryBinarySpec) {
169 task.dependsOn binary.tasks.link
170 task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) {
171 into nativeUtils.getPlatformPath(binary) + '/shared'
172 }
173 def sharedPath = binary.sharedLibraryFile.absolutePath
174 sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
175
176 task.from(new File(sharedPath + '.pdb')) {
177 into nativeUtils.getPlatformPath(binary) + '/shared'
178 }
179 task.from(binary.sharedLibraryFile) {
180 into nativeUtils.getPlatformPath(binary) + '/shared'
181 }
182 task.from(binary.sharedLibraryLinkFile) {
183 into nativeUtils.getPlatformPath(binary) + '/shared'
184 }
185 } else if (binary instanceof StaticLibraryBinarySpec) {
186 task.dependsOn binary.tasks.createStaticLib
187 task.from(binary.staticLibraryFile) {
188 into nativeUtils.getPlatformPath(binary) + '/static'
189 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800190 def pdbDir = binary.staticLibraryFile.parentFile
191 task.from(pdbDir) {
192 include '*.pdb'
193 into nativeUtils.getPlatformPath(binary) + '/static'
194 }
195 task.from(new File(pdbDir, "SourceLink.json")) {
196 into nativeUtils.getPlatformPath(binary) + '/static'
197 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800198 }
199 }
200 }
201}