blob: 369422d4f319591824fa955fde34778e0f282bf8 [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 }
62 if (!project.hasProperty('noWpiutil')) {
63 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
64 }
65 if (project.hasProperty('splitSetup')) {
66 splitSetup(it)
67 }
68 }
69 }
70 "${nativeName}"(NativeLibrarySpec) {
71 if (project.hasProperty('setBaseName')) {
72 baseName = setBaseName
73 }
74 sources {
75 cpp {
76 source {
77 srcDirs "${rootDir}/shared/singlelib"
78 include '**/*.cpp'
79 }
80 exportedHeaders {
81 srcDir 'src/main/native/include'
82 if (project.hasProperty('generatedHeaders')) {
83 srcDir generatedHeaders
84 }
85 }
86 }
87 }
88 if (!project.hasProperty('noWpiutil')) {
89 binaries.all {
90 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
91 }
92 }
93 appendDebugPathToBinaries(binaries)
94 }
95 "${nativeName}JNIShared"(JniNativeLibrarySpec) {
96 if (project.hasProperty('setBaseName')) {
97 baseName = setBaseName + 'jni'
98 } else {
99 baseName = nativeName + 'jni'
100 }
101
Austin Schuh1e69f942020-11-14 15:06:14 -0800102 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800103 javaCompileTasks << compileJava
104 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
105 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
106 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
107 sources {
108 cpp {
109 source {
110 srcDirs 'src/main/native/cpp'
Austin Schuh1e69f942020-11-14 15:06:14 -0800111 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800112 }
113 exportedHeaders {
114 srcDir 'src/main/native/include'
115 if (project.hasProperty('generatedHeaders')) {
116 srcDir generatedHeaders
117 }
118 include '**/*.h'
119 }
120
121 }
122 }
123 binaries.all {
124 if (it instanceof StaticLibraryBinarySpec) {
125 it.buildable = false
126 return
127 }
128 lib library: "${nativeName}", linkage: 'shared'
129 if (!project.hasProperty('noWpiutil')) {
130 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
131 }
132 if (project.hasProperty('jniSplitSetup')) {
133 jniSplitSetup(it)
134 }
135 }
136 }
137 "${nativeName}JNI"(JniNativeLibrarySpec) {
138 if (project.hasProperty('setBaseName')) {
139 baseName = setBaseName + 'jni'
140 } else {
141 baseName = nativeName + 'jni'
142 }
143
Austin Schuh1e69f942020-11-14 15:06:14 -0800144 enableCheckTask !project.hasProperty('skipJniCheck')
Brian Silverman8fce7482020-01-05 13:18:21 -0800145 javaCompileTasks << compileJava
146 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio)
147 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian)
148 jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic)
149 sources {
150 cpp {
151 source {
152 srcDirs 'src/main/native/cpp'
Austin Schuh1e69f942020-11-14 15:06:14 -0800153 include '**/jni/**/*.cpp'
Brian Silverman8fce7482020-01-05 13:18:21 -0800154 }
155 exportedHeaders {
156 srcDir 'src/main/native/include'
157 if (project.hasProperty('generatedHeaders')) {
158 srcDir generatedHeaders
159 }
160 include '**/*.h'
161 }
162 }
163 }
164 binaries.all {
165 if (it instanceof StaticLibraryBinarySpec) {
166 it.buildable = false
167 return
168 }
169 if (!project.hasProperty('noWpiutil')) {
170 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
171 }
172 if (project.hasProperty('jniSplitSetup')) {
173 jniSplitSetup(it)
174 }
175 }
176 }
177 // By default, a development executable will be generated. This is to help the case of
178 // testing specific functionality of the library.
179 "${nativeName}Dev"(NativeExecutableSpec) {
180 targetBuildTypes 'debug'
181 sources {
182 cpp {
183
184 source {
185 srcDirs 'src/dev/native/cpp'
186 include '**/*.cpp'
187 }
188 exportedHeaders {
189 srcDir 'src/main/native/include'
190 if (project.hasProperty('generatedHeaders')) {
191 srcDir generatedHeaders
192 }
193 }
194 }
195 }
196 binaries.all {
197 lib library: nativeName, linkage: 'shared'
198 lib library: "${nativeName}JNIShared", linkage: 'shared'
199 if (!project.hasProperty('noWpiutil')) {
200 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
201 }
202 if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
203 nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
204 }
205 }
206 }
207 }
208 testSuites {
209 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
210 for(NativeComponentSpec c : $.components) {
211 if (c.name == nativeName) {
212 testing c
213 break
214 }
215 }
216 sources {
217 cpp {
218 source {
219 srcDirs 'src/test/native/cpp'
220 include '**/*.cpp'
221 }
222 exportedHeaders {
223 srcDirs 'src/test/native/include', 'src/main/native/cpp'
224 if (project.hasProperty('generatedHeaders')) {
225 srcDir generatedHeaders
226 }
227 }
228 }
229 }
230 }
231 }
232 binaries {
233 withType(GoogleTestTestSuiteBinarySpec) {
234 lib library: nativeName, linkage: 'shared'
235 if (!project.hasProperty('noWpiutil')) {
236 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
237 if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
238 nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
239 }
240 }
241 }
242 }
243 tasks {
244 def c = $.components
245 project.tasks.create('runCpp', Exec) {
246 group = 'WPILib'
247 description = "Run the ${nativeName}Dev executable"
248 def found = false
249 def systemArch = getCurrentArch()
250 c.each {
251 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
252 it.binaries.each {
253 if (!found) {
254 def arch = it.targetPlatform.name
255 if (arch == systemArch) {
256 dependsOn it.tasks.install
257 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
258 def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
259 test.dependsOn it.tasks.install
260 test.systemProperty 'java.library.path', filePath
261 test.environment 'LD_LIBRARY_PATH', filePath
262 test.workingDir filePath
263 run.dependsOn it.tasks.install
264 run.systemProperty 'java.library.path', filePath
265 run.environment 'LD_LIBRARY_PATH', filePath
266 run.workingDir filePath
267
268 found = true
269 }
270 }
271 }
272 }
273 }
274 }
275 }
276}
277
278apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
279apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
280
281ext.getJniSpecClass = {
282 return JniNativeLibrarySpec
283}
284
285tasks.withType(RunTestExecutable) {
286 args "--gtest_output=xml:test_detail.xml"
287 outputs.dir outputDir
288}
289
290apply from: "${rootDir}/shared/jni/publish.gradle"