blob: 35f4cf2d06fc0036c862c51619758a009cd16569 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -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 {
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -080019 if (!project.hasProperty('noWpiutil')) {
20 compile project(':wpiutil')
21 devCompile project(':wpiutil')
22 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -080023}
24
25project(':').libraryBuild.dependsOn build
26
27ext {
28 staticGtestConfigs = [:]
29}
30
31staticGtestConfigs["${nativeName}Test"] = []
32
33apply from: "${rootDir}/shared/googletest.gradle"
34
35if (project.hasProperty('niLibraries')) {
36 ext {
37 chipObjectComponents = ["$nativeName".toString(), "${nativeName}Dev".toString(), "${nativeName}Base".toString(),
38 "${nativeName}JNI".toString(), "${nativeName}JNIShared".toString(), "${nativeName}Test".toString()]
39 netCommComponents = ["$nativeName".toString(), "${nativeName}Dev".toString(), "${nativeName}Base".toString(),
40 "${nativeName}JNI".toString(), "${nativeName}JNIShared".toString(), "${nativeName}Test".toString()]
41 useNiJava = true
42 }
43
44 apply from: "${rootDir}/shared/nilibraries.gradle"
45}
46
47model {
48 components {
49 "${nativeName}Base"(NativeLibrarySpec) {
50 if (project.hasProperty('setBaseName')) {
51 baseName = setBaseName
52 }
53 sources {
54 cpp {
55 source {
56 srcDirs 'src/main/native/cpp'
57 include '**/*.cpp'
58 exclude '**/jni/*.cpp'
59 }
60 exportedHeaders {
61 srcDir 'src/main/native/include'
62 if (project.hasProperty('generatedHeaders')) {
63 srcDir generatedHeaders
64 }
65 include '**/*.h'
66 }
67 }
68 }
69 binaries.all {
70 if (it instanceof SharedLibraryBinarySpec) {
71 it.buildable = false
72 return
73 }
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -080074 if (!project.hasProperty('noWpiutil')) {
75 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
76 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -080077 if (project.hasProperty('splitSetup')) {
78 splitSetup(it)
79 }
80 }
81 }
82 "${nativeName}"(NativeLibrarySpec) {
83 if (project.hasProperty('setBaseName')) {
84 baseName = setBaseName
85 }
86 sources {
87 cpp {
88 source {
89 srcDirs "${rootDir}/shared/singlelib"
90 include '**/*.cpp'
91 }
92 exportedHeaders {
93 srcDir 'src/main/native/include'
94 if (project.hasProperty('generatedHeaders')) {
95 srcDir generatedHeaders
96 }
97 }
98 }
99 }
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800100 if (!project.hasProperty('noWpiutil')) {
101 binaries.all {
102 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
103 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800104 }
105 appendDebugPathToBinaries(binaries)
106 }
107 "${nativeName}JNIShared"(JniNativeLibrarySpec) {
108 if (project.hasProperty('setBaseName')) {
109 baseName = setBaseName + 'jni'
110 } else {
111 baseName = nativeName + 'jni'
112 }
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800113
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800114 enableCheckTask true
115 javaCompileTasks << compileJava
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800116 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
117 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
118 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800119 sources {
120 cpp {
121 source {
122 srcDirs 'src/main/native/cpp'
123 include '**/jni/*.cpp'
124 }
125 exportedHeaders {
126 srcDir 'src/main/native/include'
127 if (project.hasProperty('generatedHeaders')) {
128 srcDir generatedHeaders
129 }
130 include '**/*.h'
131 }
132
133 }
134 }
135 binaries.all {
136 if (it instanceof StaticLibraryBinarySpec) {
137 it.buildable = false
138 return
139 }
140 lib library: "${nativeName}", linkage: 'shared'
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800141 if (!project.hasProperty('noWpiutil')) {
142 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
143 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800144 if (project.hasProperty('jniSplitSetup')) {
145 jniSplitSetup(it)
146 }
147 }
148 }
149 "${nativeName}JNI"(JniNativeLibrarySpec) {
150 if (project.hasProperty('setBaseName')) {
151 baseName = setBaseName + 'jni'
152 } else {
153 baseName = nativeName + 'jni'
154 }
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800155
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800156 enableCheckTask true
157 javaCompileTasks << compileJava
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800158 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
159 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
160 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800161 sources {
162 cpp {
163 source {
164 srcDirs 'src/main/native/cpp'
165 include '**/jni/*.cpp'
166 }
167 exportedHeaders {
168 srcDir 'src/main/native/include'
169 if (project.hasProperty('generatedHeaders')) {
170 srcDir generatedHeaders
171 }
172 include '**/*.h'
173 }
174 }
175 }
176 binaries.all {
177 if (it instanceof StaticLibraryBinarySpec) {
178 it.buildable = false
179 return
180 }
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800181 if (!project.hasProperty('noWpiutil')) {
182 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
183 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800184 if (project.hasProperty('jniSplitSetup')) {
185 jniSplitSetup(it)
186 }
187 }
188 }
189 // By default, a development executable will be generated. This is to help the case of
190 // testing specific functionality of the library.
191 "${nativeName}Dev"(NativeExecutableSpec) {
192 targetBuildTypes 'debug'
193 sources {
194 cpp {
195
196 source {
197 srcDirs 'src/dev/native/cpp'
198 include '**/*.cpp'
199 }
200 exportedHeaders {
201 srcDir 'src/main/native/include'
202 if (project.hasProperty('generatedHeaders')) {
203 srcDir generatedHeaders
204 }
205 }
206 }
207 }
208 binaries.all {
209 lib library: nativeName, linkage: 'shared'
210 lib library: "${nativeName}JNIShared", linkage: 'shared'
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800211 if (!project.hasProperty('noWpiutil')) {
212 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
213 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800214 }
215 }
216 }
217 testSuites {
218 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
219 for(NativeComponentSpec c : $.components) {
220 if (c.name == nativeName) {
221 testing c
222 break
223 }
224 }
225 sources {
226 cpp {
227 source {
228 srcDirs 'src/test/native/cpp'
229 include '**/*.cpp'
230 }
231 exportedHeaders {
232 srcDirs 'src/test/native/include', 'src/main/native/cpp'
233 if (project.hasProperty('generatedHeaders')) {
234 srcDir generatedHeaders
235 }
236 }
237 }
238 }
239 }
240 }
241 binaries {
242 withType(GoogleTestTestSuiteBinarySpec) {
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800243 lib library: nativeName, linkage: 'shared'
244 if (!project.hasProperty('noWpiutil')) {
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800245 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800246 }
247 }
248 }
249 tasks {
250 def c = $.components
251 project.tasks.create('runCpp', Exec) {
252 group = 'WPILib'
253 description = "Run the ${nativeName}Dev executable"
254 def found = false
255 def systemArch = getCurrentArch()
256 c.each {
257 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
258 it.binaries.each {
259 if (!found) {
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800260 def arch = it.targetPlatform.name
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800261 if (arch == systemArch) {
262 dependsOn it.tasks.install
263 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
264 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
265 test.dependsOn it.tasks.install
266 test.systemProperty 'java.library.path', filePath
267 test.environment 'LD_LIBRARY_PATH', filePath
268 test.workingDir filePath
269 run.dependsOn it.tasks.install
270 run.systemProperty 'java.library.path', filePath
271 run.environment 'LD_LIBRARY_PATH', filePath
272 run.workingDir filePath
273
274 found = true
275 }
276 }
277 }
278 }
279 }
280 }
281 }
282}
283
284ext.getJniSpecClass = {
285 return JniNativeLibrarySpec
286}
287
288tasks.withType(RunTestExecutable) {
289 args "--gtest_output=xml:test_detail.xml"
290 outputs.dir outputDir
291}
292
293apply from: "${rootDir}/shared/jni/publish.gradle"