blob: f89780647d0ae6983265118f19b121dc015ded51 [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'
45 include '**/*.cpp'
Austin Schuh1e69f942020-11-14 15:06:14 -080046 exclude '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -080047 }
48 exportedHeaders {
49 srcDir 'src/main/native/include'
50 if (project.hasProperty('generatedHeaders')) {
51 srcDir generatedHeaders
52 }
53 include '**/*.h'
54 }
55 }
56 }
57 binaries.all {
58 if (it instanceof SharedLibraryBinarySpec) {
59 it.buildable = false
60 return
61 }
Austin Schuh812d0d12021-11-04 20:16:48 -070062 it.cppCompiler.define 'WPILIB_EXPORTS'
63 it.cCompiler.define 'WPILIB_EXPORTS'
Brian Silverman8fce7482020-01-05 13:18:21 -080064 if (!project.hasProperty('noWpiutil')) {
65 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
66 }
67 if (project.hasProperty('splitSetup')) {
68 splitSetup(it)
69 }
70 }
71 }
72 "${nativeName}"(NativeLibrarySpec) {
73 if (project.hasProperty('setBaseName')) {
74 baseName = setBaseName
75 }
76 sources {
77 cpp {
78 source {
79 srcDirs "${rootDir}/shared/singlelib"
80 include '**/*.cpp'
81 }
82 exportedHeaders {
83 srcDir 'src/main/native/include'
84 if (project.hasProperty('generatedHeaders')) {
85 srcDir generatedHeaders
86 }
87 }
88 }
89 }
90 if (!project.hasProperty('noWpiutil')) {
91 binaries.all {
92 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
93 }
94 }
95 appendDebugPathToBinaries(binaries)
96 }
97 "${nativeName}JNIShared"(JniNativeLibrarySpec) {
98 if (project.hasProperty('setBaseName')) {
99 baseName = setBaseName + 'jni'
100 } else {
101 baseName = nativeName + 'jni'
102 }
103
Austin Schuh1e69f942020-11-14 15:06:14 -0800104 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800105 javaCompileTasks << compileJava
106 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
107 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
108 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
109 sources {
110 cpp {
111 source {
112 srcDirs 'src/main/native/cpp'
Austin Schuh1e69f942020-11-14 15:06:14 -0800113 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800114 }
115 exportedHeaders {
116 srcDir 'src/main/native/include'
117 if (project.hasProperty('generatedHeaders')) {
118 srcDir generatedHeaders
119 }
120 include '**/*.h'
121 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800122 }
123 }
124 binaries.all {
125 if (it instanceof StaticLibraryBinarySpec) {
126 it.buildable = false
127 return
128 }
129 lib library: "${nativeName}", linkage: 'shared'
130 if (!project.hasProperty('noWpiutil')) {
131 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
132 }
133 if (project.hasProperty('jniSplitSetup')) {
134 jniSplitSetup(it)
135 }
136 }
137 }
138 "${nativeName}JNI"(JniNativeLibrarySpec) {
139 if (project.hasProperty('setBaseName')) {
140 baseName = setBaseName + 'jni'
141 } else {
142 baseName = nativeName + 'jni'
143 }
144
Austin Schuh1e69f942020-11-14 15:06:14 -0800145 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800146 javaCompileTasks << compileJava
147 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
148 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
149 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
150 sources {
151 cpp {
152 source {
153 srcDirs 'src/main/native/cpp'
Austin Schuh1e69f942020-11-14 15:06:14 -0800154 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800155 }
156 exportedHeaders {
157 srcDir 'src/main/native/include'
158 if (project.hasProperty('generatedHeaders')) {
159 srcDir generatedHeaders
160 }
161 include '**/*.h'
162 }
163 }
164 }
165 binaries.all {
166 if (it instanceof StaticLibraryBinarySpec) {
167 it.buildable = false
168 return
169 }
170 if (!project.hasProperty('noWpiutil')) {
171 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
172 }
173 if (project.hasProperty('jniSplitSetup')) {
174 jniSplitSetup(it)
175 }
176 }
177 }
178 // By default, a development executable will be generated. This is to help the case of
179 // testing specific functionality of the library.
180 "${nativeName}Dev"(NativeExecutableSpec) {
181 targetBuildTypes 'debug'
182 sources {
183 cpp {
184
185 source {
186 srcDirs 'src/dev/native/cpp'
187 include '**/*.cpp'
188 }
189 exportedHeaders {
190 srcDir 'src/main/native/include'
191 if (project.hasProperty('generatedHeaders')) {
192 srcDir generatedHeaders
193 }
194 }
195 }
196 }
197 binaries.all {
198 lib library: nativeName, linkage: 'shared'
199 lib library: "${nativeName}JNIShared", linkage: 'shared'
200 if (!project.hasProperty('noWpiutil')) {
201 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700202 lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800203 }
204 if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700205 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800206 }
207 }
208 }
209 }
210 testSuites {
211 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
212 for(NativeComponentSpec c : $.components) {
213 if (c.name == nativeName) {
214 testing c
215 break
216 }
217 }
218 sources {
219 cpp {
220 source {
221 srcDirs 'src/test/native/cpp'
222 include '**/*.cpp'
223 }
224 exportedHeaders {
225 srcDirs 'src/test/native/include', 'src/main/native/cpp'
226 if (project.hasProperty('generatedHeaders')) {
227 srcDir generatedHeaders
228 }
229 }
230 }
231 }
232 }
233 }
234 binaries {
235 withType(GoogleTestTestSuiteBinarySpec) {
236 lib library: nativeName, linkage: 'shared'
237 if (!project.hasProperty('noWpiutil')) {
238 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
239 if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700240 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800241 }
242 }
243 }
244 }
245 tasks {
246 def c = $.components
247 project.tasks.create('runCpp', Exec) {
248 group = 'WPILib'
249 description = "Run the ${nativeName}Dev executable"
250 def found = false
251 def systemArch = getCurrentArch()
252 c.each {
253 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
254 it.binaries.each {
255 if (!found) {
256 def arch = it.targetPlatform.name
257 if (arch == systemArch) {
258 dependsOn it.tasks.install
259 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
260 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
261 test.dependsOn it.tasks.install
Austin Schuh812d0d12021-11-04 20:16:48 -0700262
263 if (project.hasProperty('buildServer')) {
264 def folderDir = it.tasks.install.installDirectory.get().toString()
265 test.doLast {
266 def folder = file(folderDir)
267 folder.deleteDir()
268 }
269 }
270
Brian Silverman8fce7482020-01-05 13:18:21 -0800271 test.systemProperty 'java.library.path', filePath
272 test.environment 'LD_LIBRARY_PATH', filePath
273 test.workingDir filePath
274 run.dependsOn it.tasks.install
275 run.systemProperty 'java.library.path', filePath
276 run.environment 'LD_LIBRARY_PATH', filePath
277 run.workingDir filePath
278
279 found = true
280 }
281 }
282 }
283 }
284 }
285 }
286 }
287}
288
289apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
290apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
291
292ext.getJniSpecClass = {
293 return JniNativeLibrarySpec
294}
295
296tasks.withType(RunTestExecutable) {
297 args "--gtest_output=xml:test_detail.xml"
298 outputs.dir outputDir
299}
300
301apply from: "${rootDir}/shared/jni/publish.gradle"