blob: de7c50f49ba5f97688a3ba5c3b5038a35894eb88 [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 {
James Kuszmaulb13e13f2023-11-22 20:44:04 -080044 srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp"
James Kuszmaulcf324122023-01-14 14:07:17 -080045 if (project.hasProperty('generatedSources')) {
46 srcDir generatedSources
47 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -080048 include '**/*.cpp', '**/*.cc'
Austin Schuh1e69f942020-11-14 15:06:14 -080049 exclude '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -080050 }
51 exportedHeaders {
James Kuszmaulb13e13f2023-11-22 20:44:04 -080052 srcDirs 'src/main/native/include', "$buildDir/generated/source/proto/main/cpp"
Brian Silverman8fce7482020-01-05 13:18:21 -080053 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 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -080070 it.tasks.withType(CppCompile) {
71 it.dependsOn generateProto
72 }
Brian Silverman8fce7482020-01-05 13:18:21 -080073 if (project.hasProperty('splitSetup')) {
74 splitSetup(it)
75 }
76 }
77 }
78 "${nativeName}"(NativeLibrarySpec) {
79 if (project.hasProperty('setBaseName')) {
80 baseName = setBaseName
81 }
82 sources {
83 cpp {
84 source {
85 srcDirs "${rootDir}/shared/singlelib"
86 include '**/*.cpp'
87 }
88 exportedHeaders {
89 srcDir 'src/main/native/include'
90 if (project.hasProperty('generatedHeaders')) {
91 srcDir generatedHeaders
92 }
93 }
94 }
95 }
96 if (!project.hasProperty('noWpiutil')) {
97 binaries.all {
98 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
99 }
100 }
101 appendDebugPathToBinaries(binaries)
102 }
103 "${nativeName}JNIShared"(JniNativeLibrarySpec) {
104 if (project.hasProperty('setBaseName')) {
105 baseName = setBaseName + 'jni'
106 } else {
107 baseName = nativeName + 'jni'
108 }
109
James Kuszmaulcf324122023-01-14 14:07:17 -0800110 if (project.hasProperty('skipJniSymbols')) {
111 checkSkipSymbols = skipJniSymbols
112 }
113
Austin Schuh1e69f942020-11-14 15:06:14 -0800114 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800115 javaCompileTasks << compileJava
116 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
James Kuszmaulcf324122023-01-14 14:07:17 -0800117 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32)
118 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64)
Brian Silverman8fce7482020-01-05 13:18:21 -0800119 sources {
120 cpp {
121 source {
122 srcDirs 'src/main/native/cpp'
James Kuszmaulcf324122023-01-14 14:07:17 -0800123 if (project.hasProperty('generatedSources')) {
124 srcDir generatedSources
125 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800126 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800127 }
128 exportedHeaders {
129 srcDir 'src/main/native/include'
130 if (project.hasProperty('generatedHeaders')) {
131 srcDir generatedHeaders
132 }
133 include '**/*.h'
134 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800135 }
136 }
137 binaries.all {
138 if (it instanceof StaticLibraryBinarySpec) {
139 it.buildable = false
140 return
141 }
142 lib library: "${nativeName}", linkage: 'shared'
143 if (!project.hasProperty('noWpiutil')) {
144 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
145 }
146 if (project.hasProperty('jniSplitSetup')) {
147 jniSplitSetup(it)
148 }
149 }
150 }
151 "${nativeName}JNI"(JniNativeLibrarySpec) {
152 if (project.hasProperty('setBaseName')) {
153 baseName = setBaseName + 'jni'
154 } else {
155 baseName = nativeName + 'jni'
156 }
157
James Kuszmaulcf324122023-01-14 14:07:17 -0800158 if (project.hasProperty('skipJniSymbols')) {
159 checkSkipSymbols = skipJniSymbols
160 }
161
Austin Schuh1e69f942020-11-14 15:06:14 -0800162 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800163 javaCompileTasks << compileJava
164 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
James Kuszmaulcf324122023-01-14 14:07:17 -0800165 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32)
166 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64)
Brian Silverman8fce7482020-01-05 13:18:21 -0800167 sources {
168 cpp {
169 source {
170 srcDirs 'src/main/native/cpp'
James Kuszmaulcf324122023-01-14 14:07:17 -0800171 if (project.hasProperty('generatedSources')) {
172 srcDir generatedSources
173 }
Austin Schuh1e69f942020-11-14 15:06:14 -0800174 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800175 }
176 exportedHeaders {
177 srcDir 'src/main/native/include'
178 if (project.hasProperty('generatedHeaders')) {
179 srcDir generatedHeaders
180 }
181 include '**/*.h'
182 }
183 }
184 }
185 binaries.all {
186 if (it instanceof StaticLibraryBinarySpec) {
187 it.buildable = false
188 return
189 }
190 if (!project.hasProperty('noWpiutil')) {
191 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
192 }
193 if (project.hasProperty('jniSplitSetup')) {
194 jniSplitSetup(it)
195 }
196 }
197 }
198 // By default, a development executable will be generated. This is to help the case of
199 // testing specific functionality of the library.
200 "${nativeName}Dev"(NativeExecutableSpec) {
201 targetBuildTypes 'debug'
202 sources {
203 cpp {
Brian Silverman8fce7482020-01-05 13:18:21 -0800204 source {
205 srcDirs 'src/dev/native/cpp'
206 include '**/*.cpp'
207 }
208 exportedHeaders {
209 srcDir 'src/main/native/include'
210 if (project.hasProperty('generatedHeaders')) {
211 srcDir generatedHeaders
212 }
213 }
214 }
215 }
216 binaries.all {
217 lib library: nativeName, linkage: 'shared'
218 lib library: "${nativeName}JNIShared", linkage: 'shared'
219 if (!project.hasProperty('noWpiutil')) {
220 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700221 lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800222 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
223 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
224 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800225 }
Maxwell Henderson80bec322024-01-09 15:48:44 -0800226 it.tasks.withType(CppCompile) {
227 it.dependsOn generateProto
228 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800229 if (project.hasProperty('exeSplitSetup')) {
230 exeSplitSetup(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800231 }
232 }
233 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800234 "${nativeName}TestLib"(NativeLibrarySpec) {
235 sources {
236 cpp {
237 source {
238 srcDirs 'src/testlib/native/cpp'
239 include '**/*.cpp'
240 }
241 exportedHeaders {
242 srcDirs 'src/test/native/include'
243 }
244 }
245 }
246 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800247 }
248 testSuites {
249 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
250 for(NativeComponentSpec c : $.components) {
251 if (c.name == nativeName) {
252 testing c
253 break
254 }
255 }
256 sources {
257 cpp {
258 source {
259 srcDirs 'src/test/native/cpp'
260 include '**/*.cpp'
261 }
262 exportedHeaders {
Maxwell Henderson80bec322024-01-09 15:48:44 -0800263 srcDirs 'src/test/native/include', 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp"
Brian Silverman8fce7482020-01-05 13:18:21 -0800264 if (project.hasProperty('generatedHeaders')) {
265 srcDir generatedHeaders
266 }
267 }
268 }
269 }
270 }
271 }
272 binaries {
273 withType(GoogleTestTestSuiteBinarySpec) {
274 lib library: nativeName, linkage: 'shared'
275 if (!project.hasProperty('noWpiutil')) {
276 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800277 lib project: ':wpiutil', library: 'wpiutilTestLib', linkage: 'shared'
278 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
279 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
280 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800281 }
Maxwell Henderson80bec322024-01-09 15:48:44 -0800282 it.tasks.withType(CppCompile) {
283 it.dependsOn generateProto
284 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800285 if (project.hasProperty('exeSplitSetup')) {
286 exeSplitSetup(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800287 }
288 }
289 }
290 tasks {
291 def c = $.components
292 project.tasks.create('runCpp', Exec) {
293 group = 'WPILib'
294 description = "Run the ${nativeName}Dev executable"
295 def found = false
296 def systemArch = getCurrentArch()
297 c.each {
298 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
299 it.binaries.each {
300 if (!found) {
301 def arch = it.targetPlatform.name
302 if (arch == systemArch) {
303 dependsOn it.tasks.install
304 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
305 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
306 test.dependsOn it.tasks.install
Austin Schuh812d0d12021-11-04 20:16:48 -0700307
308 if (project.hasProperty('buildServer')) {
309 def folderDir = it.tasks.install.installDirectory.get().toString()
310 test.doLast {
311 def folder = file(folderDir)
312 folder.deleteDir()
313 }
314 }
315
Brian Silverman8fce7482020-01-05 13:18:21 -0800316 test.systemProperty 'java.library.path', filePath
317 test.environment 'LD_LIBRARY_PATH', filePath
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800318 test.environment 'DYLD_LIBRARY_PATH', filePath
Brian Silverman8fce7482020-01-05 13:18:21 -0800319 test.workingDir filePath
320 run.dependsOn it.tasks.install
321 run.systemProperty 'java.library.path', filePath
322 run.environment 'LD_LIBRARY_PATH', filePath
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800323 run.environment 'DYLD_LIBRARY_PATH', filePath
Brian Silverman8fce7482020-01-05 13:18:21 -0800324 run.workingDir filePath
325
326 found = true
327 }
328 }
329 }
330 }
331 }
332 }
333 }
334}
335
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800336apply from: "${rootDir}/shared/cppJavaDesktopTestTask.gradle"
Brian Silverman8fce7482020-01-05 13:18:21 -0800337
338ext.getJniSpecClass = {
339 return JniNativeLibrarySpec
340}
341
342tasks.withType(RunTestExecutable) {
343 args "--gtest_output=xml:test_detail.xml"
344 outputs.dir outputDir
345}
346
347apply from: "${rootDir}/shared/jni/publish.gradle"