blob: 4d8894f8620ac9e3775b70036934f56409a2df50 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001apply plugin: 'cpp'
2apply plugin: 'google-test-test-suite'
3apply plugin: 'visual-studio'
4apply plugin: 'edu.wpi.first.NativeUtils'
5apply plugin: 'edu.wpi.first.GradleJni'
6apply plugin: SingleNativeBuild
7apply plugin: ExtraTasks
8
9apply from: "${rootDir}/shared/config.gradle"
10
11ext {
12 baseId = nativeName
13 groupId = "edu.wpi.first.${nativeName}"
14}
15
16apply from: "${rootDir}/shared/java/javacommon.gradle"
17
18dependencies {
19 if (!project.hasProperty('noWpiutil')) {
20 implementation project(':wpiutil')
21 devImplementation project(':wpiutil')
22 }
23}
24
25project(':').libraryBuild.dependsOn build
26
27ext {
28 staticGtestConfigs = [:]
29}
30
31staticGtestConfigs["${nativeName}Test"] = []
32
33apply from: "${rootDir}/shared/googletest.gradle"
34
35model {
36 components {
37 "${nativeName}Base"(NativeLibrarySpec) {
38 if (project.hasProperty('setBaseName')) {
39 baseName = setBaseName
40 }
41 sources {
42 cpp {
43 source {
44 srcDirs 'src/main/native/cpp'
James Kuszmaulcf324122023-01-14 14:07:17 -080045 if (project.hasProperty('generatedSources')) {
46 srcDir generatedSources
47 }
Brian Silverman8fce7482020-01-05 13:18:21 -080048 include '**/*.cpp'
Austin Schuh1e69f942020-11-14 15:06:14 -080049 exclude '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -080050 }
51 exportedHeaders {
52 srcDir 'src/main/native/include'
53 if (project.hasProperty('generatedHeaders')) {
54 srcDir generatedHeaders
55 }
56 include '**/*.h'
57 }
58 }
59 }
60 binaries.all {
61 if (it instanceof SharedLibraryBinarySpec) {
62 it.buildable = false
63 return
64 }
Austin Schuh812d0d12021-11-04 20:16:48 -070065 it.cppCompiler.define 'WPILIB_EXPORTS'
66 it.cCompiler.define 'WPILIB_EXPORTS'
Brian Silverman8fce7482020-01-05 13:18:21 -080067 if (!project.hasProperty('noWpiutil')) {
68 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
69 }
70 if (project.hasProperty('splitSetup')) {
71 splitSetup(it)
72 }
73 }
74 }
75 "${nativeName}"(NativeLibrarySpec) {
76 if (project.hasProperty('setBaseName')) {
77 baseName = setBaseName
78 }
79 sources {
80 cpp {
81 source {
82 srcDirs "${rootDir}/shared/singlelib"
83 include '**/*.cpp'
84 }
85 exportedHeaders {
86 srcDir 'src/main/native/include'
87 if (project.hasProperty('generatedHeaders')) {
88 srcDir generatedHeaders
89 }
90 }
91 }
92 }
93 if (!project.hasProperty('noWpiutil')) {
94 binaries.all {
95 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
96 }
97 }
98 appendDebugPathToBinaries(binaries)
99 }
100 "${nativeName}JNIShared"(JniNativeLibrarySpec) {
101 if (project.hasProperty('setBaseName')) {
102 baseName = setBaseName + 'jni'
103 } else {
104 baseName = nativeName + 'jni'
105 }
106
James Kuszmaulcf324122023-01-14 14:07:17 -0800107 if (project.hasProperty('skipJniSymbols')) {
108 checkSkipSymbols = skipJniSymbols
109 }
110
Austin Schuh1e69f942020-11-14 15:06:14 -0800111 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800112 javaCompileTasks << compileJava
113 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
James Kuszmaulcf324122023-01-14 14:07:17 -0800114 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32)
115 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64)
Brian Silverman8fce7482020-01-05 13:18:21 -0800116 sources {
117 cpp {
118 source {
119 srcDirs 'src/main/native/cpp'
James Kuszmaulcf324122023-01-14 14:07:17 -0800120 if (project.hasProperty('generatedSources')) {
121 srcDir generatedSources
122 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800123 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800124 }
125 exportedHeaders {
126 srcDir 'src/main/native/include'
127 if (project.hasProperty('generatedHeaders')) {
128 srcDir generatedHeaders
129 }
130 include '**/*.h'
131 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800132 }
133 }
134 binaries.all {
135 if (it instanceof StaticLibraryBinarySpec) {
136 it.buildable = false
137 return
138 }
139 lib library: "${nativeName}", linkage: 'shared'
140 if (!project.hasProperty('noWpiutil')) {
141 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
142 }
143 if (project.hasProperty('jniSplitSetup')) {
144 jniSplitSetup(it)
145 }
146 }
147 }
148 "${nativeName}JNI"(JniNativeLibrarySpec) {
149 if (project.hasProperty('setBaseName')) {
150 baseName = setBaseName + 'jni'
151 } else {
152 baseName = nativeName + 'jni'
153 }
154
James Kuszmaulcf324122023-01-14 14:07:17 -0800155 if (project.hasProperty('skipJniSymbols')) {
156 checkSkipSymbols = skipJniSymbols
157 }
158
Austin Schuh1e69f942020-11-14 15:06:14 -0800159 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800160 javaCompileTasks << compileJava
161 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
James Kuszmaulcf324122023-01-14 14:07:17 -0800162 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32)
163 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64)
Brian Silverman8fce7482020-01-05 13:18:21 -0800164 sources {
165 cpp {
166 source {
167 srcDirs 'src/main/native/cpp'
James Kuszmaulcf324122023-01-14 14:07:17 -0800168 if (project.hasProperty('generatedSources')) {
169 srcDir generatedSources
170 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800171 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800172 }
173 exportedHeaders {
174 srcDir 'src/main/native/include'
175 if (project.hasProperty('generatedHeaders')) {
176 srcDir generatedHeaders
177 }
178 include '**/*.h'
179 }
180 }
181 }
182 binaries.all {
183 if (it instanceof StaticLibraryBinarySpec) {
184 it.buildable = false
185 return
186 }
187 if (!project.hasProperty('noWpiutil')) {
188 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
189 }
190 if (project.hasProperty('jniSplitSetup')) {
191 jniSplitSetup(it)
192 }
193 }
194 }
195 // By default, a development executable will be generated. This is to help the case of
196 // testing specific functionality of the library.
197 "${nativeName}Dev"(NativeExecutableSpec) {
198 targetBuildTypes 'debug'
199 sources {
200 cpp {
201
202 source {
203 srcDirs 'src/dev/native/cpp'
204 include '**/*.cpp'
205 }
206 exportedHeaders {
207 srcDir 'src/main/native/include'
208 if (project.hasProperty('generatedHeaders')) {
209 srcDir generatedHeaders
210 }
211 }
212 }
213 }
214 binaries.all {
215 lib library: nativeName, linkage: 'shared'
216 lib library: "${nativeName}JNIShared", linkage: 'shared'
217 if (!project.hasProperty('noWpiutil')) {
218 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700219 lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800220 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800221 if (project.hasProperty('exeSplitSetup')) {
222 exeSplitSetup(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800223 }
224 }
225 }
226 }
227 testSuites {
228 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
229 for(NativeComponentSpec c : $.components) {
230 if (c.name == nativeName) {
231 testing c
232 break
233 }
234 }
235 sources {
236 cpp {
237 source {
238 srcDirs 'src/test/native/cpp'
239 include '**/*.cpp'
240 }
241 exportedHeaders {
242 srcDirs 'src/test/native/include', 'src/main/native/cpp'
243 if (project.hasProperty('generatedHeaders')) {
244 srcDir generatedHeaders
245 }
246 }
247 }
248 }
249 }
250 }
251 binaries {
252 withType(GoogleTestTestSuiteBinarySpec) {
253 lib library: nativeName, linkage: 'shared'
254 if (!project.hasProperty('noWpiutil')) {
255 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800256 }
257 if (project.hasProperty('exeSplitSetup')) {
258 exeSplitSetup(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800259 }
260 }
261 }
262 tasks {
263 def c = $.components
264 project.tasks.create('runCpp', Exec) {
265 group = 'WPILib'
266 description = "Run the ${nativeName}Dev executable"
267 def found = false
268 def systemArch = getCurrentArch()
269 c.each {
270 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
271 it.binaries.each {
272 if (!found) {
273 def arch = it.targetPlatform.name
274 if (arch == systemArch) {
275 dependsOn it.tasks.install
276 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
277 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
278 test.dependsOn it.tasks.install
Austin Schuh812d0d12021-11-04 20:16:48 -0700279
280 if (project.hasProperty('buildServer')) {
281 def folderDir = it.tasks.install.installDirectory.get().toString()
282 test.doLast {
283 def folder = file(folderDir)
284 folder.deleteDir()
285 }
286 }
287
Brian Silverman8fce7482020-01-05 13:18:21 -0800288 test.systemProperty 'java.library.path', filePath
289 test.environment 'LD_LIBRARY_PATH', filePath
290 test.workingDir filePath
291 run.dependsOn it.tasks.install
292 run.systemProperty 'java.library.path', filePath
293 run.environment 'LD_LIBRARY_PATH', filePath
294 run.workingDir filePath
295
296 found = true
297 }
298 }
299 }
300 }
301 }
302 }
303 }
304}
305
306apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
307apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
308
309ext.getJniSpecClass = {
310 return JniNativeLibrarySpec
311}
312
313tasks.withType(RunTestExecutable) {
314 args "--gtest_output=xml:test_detail.xml"
315 outputs.dir outputDir
316}
317
318apply from: "${rootDir}/shared/jni/publish.gradle"