blob: 8036ccaa4a725e2d0270e3190469c1cf40b8455b [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 Kuszmaulcf324122023-01-14 14:07:17 -080016 niLibVersion = "2023.3.0"
17 opencvVersion = "4.6.0-3"
18 googleTestVersion = "1.12.1-1"
Austin Schuh812d0d12021-11-04 20:16:48 -070019 }
Brian Silverman8fce7482020-01-05 13:18:21 -080020 }
Brian Silverman8fce7482020-01-05 13:18:21 -080021}
22
23nativeUtils.wpi.addWarnings()
24nativeUtils.wpi.addWarningsAsErrors()
Austin Schuh75263e32022-02-22 18:05:32 -080025
26if (project.name != 'wpilibcExamples') {
27 nativeUtils.wpi.addReleaseSymbolGeneration()
28}
Brian Silverman8fce7482020-01-05 13:18:21 -080029
30nativeUtils.setSinglePrintPerPlatform()
Austin Schuh1e69f942020-11-14 15:06:14 -080031nativeUtils.enableSourceLink()
32
James Kuszmaulcf324122023-01-14 14:07:17 -080033nativeUtils.wpi.addMacMinimumVersionArg()
34
Austin Schuh1e69f942020-11-14 15:06:14 -080035nativeUtils.platformConfigs.each {
James Kuszmaulcf324122023-01-14 14:07:17 -080036 if (it.name.contains('osx')) {
37 it.linker.args << '-Wl,-rpath,\'@loader_path\''
Austin Schuh1e69f942020-11-14 15:06:14 -080038 it.linker.args << "-headerpad_max_install_names"
James Kuszmaulcf324122023-01-14 14:07:17 -080039 } else if (it.name.contains('linux')) {
40 it.linker.args << '-Wl,-rpath,\'$ORIGIN\''
Austin Schuh1e69f942020-11-14 15:06:14 -080041 }
42}
Brian Silverman8fce7482020-01-05 13:18:21 -080043
James Kuszmaulcf324122023-01-14 14:07:17 -080044// NativeUtils adds the following OpenCV warning suppression for Linux, but not
45// for macOS
46// https://github.com/opencv/opencv/issues/20269
47nativeUtils.platformConfigs.osxuniversal.cppCompiler.args.add("-Wno-deprecated-anon-enum-enum-conversion")
48
49// NativeUtils uses the wrong compiler arguments for roboRIO targets, but it's
50// too late to fix NativeUtils for the 2023 season. This temporarily overwrites
51// the flags.
52nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
53 cppCompiler.args.remove('-Wno-error=deprecated-declarations')
54}
55
Austin Schuh812d0d12021-11-04 20:16:48 -070056nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings")
57
Brian Silverman8fce7482020-01-05 13:18:21 -080058model {
59 components {
60 all {
61 nativeUtils.useAllPlatforms(it)
62 }
63 }
64 binaries {
65 withType(NativeBinarySpec).all {
66 nativeUtils.usePlatformArguments(it)
67 }
68 }
69}
70
Austin Schuh812d0d12021-11-04 20:16:48 -070071apply plugin: DisableBuildingGTest
72
73if (project.hasProperty('buildServer')) {
74 tasks.withType(org.gradle.nativeplatform.test.tasks.RunTestExecutable) {
75 def exeFile = file(it.executable)
76 def folder = exeFile.parentFile
77
78 it.doLast {
79 folder.deleteDir()
80 }
81 }
82}
83
Brian Silverman8fce7482020-01-05 13:18:21 -080084ext.appendDebugPathToBinaries = { binaries->
85 binaries.withType(StaticLibraryBinarySpec) {
86 if (it.buildType.name.contains('debug')) {
87 def staticFileDir = it.staticLibraryFile.parentFile
88 def staticFileName = it.staticLibraryFile.name
89 def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.'))
90 staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.'))
91 staticFileName = staticFileName + 'd' + staticFileExtension
92 def newStaticFile = new File(staticFileDir, staticFileName)
93 it.staticLibraryFile = newStaticFile
94 }
95 }
96 binaries.withType(SharedLibraryBinarySpec) {
97 if (it.buildType.name.contains('debug')) {
98 def sharedFileDir = it.sharedLibraryFile.parentFile
99 def sharedFileName = it.sharedLibraryFile.name
100 def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.'))
101 sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.'))
102 sharedFileName = sharedFileName + 'd' + sharedFileExtension
103 def newSharedFile = new File(sharedFileDir, sharedFileName)
104
105 def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile
106 def sharedLinkFileName = it.sharedLibraryLinkFile.name
107 def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.'))
108 sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.'))
109 sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension
110 def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName)
111
112 it.sharedLibraryLinkFile = newLinkFile
113 it.sharedLibraryFile = newSharedFile
114 }
115 }
116}
117
118ext.createComponentZipTasks = { components, names, base, type, project, func ->
119 def stringNames = names.collect {it.toString()}
120 def configMap = [:]
121 components.each {
122 if (it in NativeLibrarySpec && stringNames.contains(it.name)) {
123 it.binaries.each {
124 if (!it.buildable) return
Austin Schuh812d0d12021-11-04 20:16:48 -0700125 def target = nativeUtils.getPublishClassifier(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800126 if (configMap.containsKey(target)) {
127 configMap.get(target).add(it)
128 } else {
129 configMap.put(target, [])
130 configMap.get(target).add(it)
131 }
132 }
133 }
134 }
135 def taskList = []
136 def outputsFolder = file("$project.buildDir/outputs")
137 configMap.each { key, value ->
138 def task = project.tasks.create(base + "-${key}", type) {
139 description = 'Creates component archive for platform ' + key
140 destinationDirectory = outputsFolder
141 classifier = key
142 archiveBaseName = '_M_' + base
143 duplicatesStrategy = 'exclude'
144
145 from(licenseFile) {
146 into '/'
147 }
148
149 func(it, value)
150 }
151 taskList.add(task)
152
153 project.build.dependsOn task
154
155 project.artifacts {
156 task
157 }
158 addTaskToCopyAllOutputs(task)
159 }
160 return taskList
161}
162
163ext.includeStandardZipFormat = { task, value ->
164 value.each { binary ->
165 if (binary.buildable) {
166 if (binary instanceof SharedLibraryBinarySpec) {
167 task.dependsOn binary.tasks.link
168 task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) {
169 into nativeUtils.getPlatformPath(binary) + '/shared'
170 }
171 def sharedPath = binary.sharedLibraryFile.absolutePath
172 sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
173
174 task.from(new File(sharedPath + '.pdb')) {
175 into nativeUtils.getPlatformPath(binary) + '/shared'
176 }
177 task.from(binary.sharedLibraryFile) {
178 into nativeUtils.getPlatformPath(binary) + '/shared'
179 }
180 task.from(binary.sharedLibraryLinkFile) {
181 into nativeUtils.getPlatformPath(binary) + '/shared'
182 }
183 } else if (binary instanceof StaticLibraryBinarySpec) {
184 task.dependsOn binary.tasks.createStaticLib
185 task.from(binary.staticLibraryFile) {
186 into nativeUtils.getPlatformPath(binary) + '/static'
187 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800188 def pdbDir = binary.staticLibraryFile.parentFile
189 task.from(pdbDir) {
190 include '*.pdb'
191 into nativeUtils.getPlatformPath(binary) + '/static'
192 }
193 task.from(new File(pdbDir, "SourceLink.json")) {
194 into nativeUtils.getPlatformPath(binary) + '/static'
195 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800196 }
197 }
198 }
199}