blob: 9f9334ffc02618b09b45dddad5554fffe413e336 [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 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800226 if (project.hasProperty('exeSplitSetup')) {
227 exeSplitSetup(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800228 }
229 }
230 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800231 "${nativeName}TestLib"(NativeLibrarySpec) {
232 sources {
233 cpp {
234 source {
235 srcDirs 'src/testlib/native/cpp'
236 include '**/*.cpp'
237 }
238 exportedHeaders {
239 srcDirs 'src/test/native/include'
240 }
241 }
242 }
243 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800244 }
245 testSuites {
246 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
247 for(NativeComponentSpec c : $.components) {
248 if (c.name == nativeName) {
249 testing c
250 break
251 }
252 }
253 sources {
254 cpp {
255 source {
256 srcDirs 'src/test/native/cpp'
257 include '**/*.cpp'
258 }
259 exportedHeaders {
260 srcDirs 'src/test/native/include', 'src/main/native/cpp'
261 if (project.hasProperty('generatedHeaders')) {
262 srcDir generatedHeaders
263 }
264 }
265 }
266 }
267 }
268 }
269 binaries {
270 withType(GoogleTestTestSuiteBinarySpec) {
271 lib library: nativeName, linkage: 'shared'
272 if (!project.hasProperty('noWpiutil')) {
273 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800274 lib project: ':wpiutil', library: 'wpiutilTestLib', linkage: 'shared'
275 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
276 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
277 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800278 }
279 if (project.hasProperty('exeSplitSetup')) {
280 exeSplitSetup(it)
Brian Silverman8fce7482020-01-05 13:18:21 -0800281 }
282 }
283 }
284 tasks {
285 def c = $.components
286 project.tasks.create('runCpp', Exec) {
287 group = 'WPILib'
288 description = "Run the ${nativeName}Dev executable"
289 def found = false
290 def systemArch = getCurrentArch()
291 c.each {
292 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
293 it.binaries.each {
294 if (!found) {
295 def arch = it.targetPlatform.name
296 if (arch == systemArch) {
297 dependsOn it.tasks.install
298 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
299 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
300 test.dependsOn it.tasks.install
Austin Schuh812d0d12021-11-04 20:16:48 -0700301
302 if (project.hasProperty('buildServer')) {
303 def folderDir = it.tasks.install.installDirectory.get().toString()
304 test.doLast {
305 def folder = file(folderDir)
306 folder.deleteDir()
307 }
308 }
309
Brian Silverman8fce7482020-01-05 13:18:21 -0800310 test.systemProperty 'java.library.path', filePath
311 test.environment 'LD_LIBRARY_PATH', filePath
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800312 test.environment 'DYLD_LIBRARY_PATH', filePath
Brian Silverman8fce7482020-01-05 13:18:21 -0800313 test.workingDir filePath
314 run.dependsOn it.tasks.install
315 run.systemProperty 'java.library.path', filePath
316 run.environment 'LD_LIBRARY_PATH', filePath
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800317 run.environment 'DYLD_LIBRARY_PATH', filePath
Brian Silverman8fce7482020-01-05 13:18:21 -0800318 run.workingDir filePath
319
320 found = true
321 }
322 }
323 }
324 }
325 }
326 }
327 }
328}
329
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800330apply from: "${rootDir}/shared/cppJavaDesktopTestTask.gradle"
Brian Silverman8fce7482020-01-05 13:18:21 -0800331
332ext.getJniSpecClass = {
333 return JniNativeLibrarySpec
334}
335
336tasks.withType(RunTestExecutable) {
337 args "--gtest_output=xml:test_detail.xml"
338 outputs.dir outputDir
339}
340
341apply from: "${rootDir}/shared/jni/publish.gradle"