Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | apply plugin: 'cpp' |
| 2 | apply plugin: 'google-test-test-suite' |
| 3 | apply plugin: 'visual-studio' |
| 4 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 5 | apply plugin: 'edu.wpi.first.GradleJni' |
| 6 | apply plugin: SingleNativeBuild |
| 7 | apply plugin: ExtraTasks |
| 8 | |
| 9 | apply from: "${rootDir}/shared/config.gradle" |
| 10 | |
| 11 | ext { |
| 12 | baseId = nativeName |
| 13 | groupId = "edu.wpi.first.${nativeName}" |
| 14 | } |
| 15 | |
| 16 | apply from: "${rootDir}/shared/java/javacommon.gradle" |
| 17 | |
| 18 | dependencies { |
| 19 | if (!project.hasProperty('noWpiutil')) { |
| 20 | implementation project(':wpiutil') |
| 21 | devImplementation project(':wpiutil') |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | project(':').libraryBuild.dependsOn build |
| 26 | |
| 27 | ext { |
| 28 | staticGtestConfigs = [:] |
| 29 | } |
| 30 | |
| 31 | staticGtestConfigs["${nativeName}Test"] = [] |
| 32 | |
| 33 | apply from: "${rootDir}/shared/googletest.gradle" |
| 34 | |
| 35 | model { |
| 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' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 45 | if (project.hasProperty('generatedSources')) { |
| 46 | srcDir generatedSources |
| 47 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 48 | include '**/*.cpp' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 49 | exclude '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 50 | } |
| 51 | exportedHeaders { |
| 52 | srcDir 'src/main/native/include' |
| 53 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 65 | it.cppCompiler.define 'WPILIB_EXPORTS' |
| 66 | it.cCompiler.define 'WPILIB_EXPORTS' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 67 | if (!project.hasProperty('noWpiutil')) { |
| 68 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 69 | } |
| 70 | if (project.hasProperty('splitSetup')) { |
| 71 | splitSetup(it) |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | "${nativeName}"(NativeLibrarySpec) { |
| 76 | if (project.hasProperty('setBaseName')) { |
| 77 | baseName = setBaseName |
| 78 | } |
| 79 | sources { |
| 80 | cpp { |
| 81 | source { |
| 82 | srcDirs "${rootDir}/shared/singlelib" |
| 83 | include '**/*.cpp' |
| 84 | } |
| 85 | exportedHeaders { |
| 86 | srcDir 'src/main/native/include' |
| 87 | if (project.hasProperty('generatedHeaders')) { |
| 88 | srcDir generatedHeaders |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | if (!project.hasProperty('noWpiutil')) { |
| 94 | binaries.all { |
| 95 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 96 | } |
| 97 | } |
| 98 | appendDebugPathToBinaries(binaries) |
| 99 | } |
| 100 | "${nativeName}JNIShared"(JniNativeLibrarySpec) { |
| 101 | if (project.hasProperty('setBaseName')) { |
| 102 | baseName = setBaseName + 'jni' |
| 103 | } else { |
| 104 | baseName = nativeName + 'jni' |
| 105 | } |
| 106 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 107 | if (project.hasProperty('skipJniSymbols')) { |
| 108 | checkSkipSymbols = skipJniSymbols |
| 109 | } |
| 110 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 111 | enableCheckTask !project.hasProperty('skipJniCheck') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 112 | javaCompileTasks << compileJava |
| 113 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 114 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32) |
| 115 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 116 | sources { |
| 117 | cpp { |
| 118 | source { |
| 119 | srcDirs 'src/main/native/cpp' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 120 | if (project.hasProperty('generatedSources')) { |
| 121 | srcDir generatedSources |
| 122 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 123 | include '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 124 | } |
| 125 | exportedHeaders { |
| 126 | srcDir 'src/main/native/include' |
| 127 | if (project.hasProperty('generatedHeaders')) { |
| 128 | srcDir generatedHeaders |
| 129 | } |
| 130 | include '**/*.h' |
| 131 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | binaries.all { |
| 135 | if (it instanceof StaticLibraryBinarySpec) { |
| 136 | it.buildable = false |
| 137 | return |
| 138 | } |
| 139 | lib library: "${nativeName}", linkage: 'shared' |
| 140 | if (!project.hasProperty('noWpiutil')) { |
| 141 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 142 | } |
| 143 | if (project.hasProperty('jniSplitSetup')) { |
| 144 | jniSplitSetup(it) |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | "${nativeName}JNI"(JniNativeLibrarySpec) { |
| 149 | if (project.hasProperty('setBaseName')) { |
| 150 | baseName = setBaseName + 'jni' |
| 151 | } else { |
| 152 | baseName = nativeName + 'jni' |
| 153 | } |
| 154 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 155 | if (project.hasProperty('skipJniSymbols')) { |
| 156 | checkSkipSymbols = skipJniSymbols |
| 157 | } |
| 158 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 159 | enableCheckTask !project.hasProperty('skipJniCheck') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 160 | javaCompileTasks << compileJava |
| 161 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 162 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32) |
| 163 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 164 | sources { |
| 165 | cpp { |
| 166 | source { |
| 167 | srcDirs 'src/main/native/cpp' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 168 | if (project.hasProperty('generatedSources')) { |
| 169 | srcDir generatedSources |
| 170 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 171 | include '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 172 | } |
| 173 | exportedHeaders { |
| 174 | srcDir 'src/main/native/include' |
| 175 | if (project.hasProperty('generatedHeaders')) { |
| 176 | srcDir generatedHeaders |
| 177 | } |
| 178 | include '**/*.h' |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | binaries.all { |
| 183 | if (it instanceof StaticLibraryBinarySpec) { |
| 184 | it.buildable = false |
| 185 | return |
| 186 | } |
| 187 | if (!project.hasProperty('noWpiutil')) { |
| 188 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' |
| 189 | } |
| 190 | if (project.hasProperty('jniSplitSetup')) { |
| 191 | jniSplitSetup(it) |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | // By default, a development executable will be generated. This is to help the case of |
| 196 | // testing specific functionality of the library. |
| 197 | "${nativeName}Dev"(NativeExecutableSpec) { |
| 198 | targetBuildTypes 'debug' |
| 199 | sources { |
| 200 | cpp { |
| 201 | |
| 202 | source { |
| 203 | srcDirs 'src/dev/native/cpp' |
| 204 | include '**/*.cpp' |
| 205 | } |
| 206 | exportedHeaders { |
| 207 | srcDir 'src/main/native/include' |
| 208 | if (project.hasProperty('generatedHeaders')) { |
| 209 | srcDir generatedHeaders |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | binaries.all { |
| 215 | lib library: nativeName, linkage: 'shared' |
| 216 | lib library: "${nativeName}JNIShared", linkage: 'shared' |
| 217 | if (!project.hasProperty('noWpiutil')) { |
| 218 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 219 | lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 220 | } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 221 | if (project.hasProperty('exeSplitSetup')) { |
| 222 | exeSplitSetup(it) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | testSuites { |
| 228 | "${nativeName}Test"(GoogleTestTestSuiteSpec) { |
| 229 | for(NativeComponentSpec c : $.components) { |
| 230 | if (c.name == nativeName) { |
| 231 | testing c |
| 232 | break |
| 233 | } |
| 234 | } |
| 235 | sources { |
| 236 | cpp { |
| 237 | source { |
| 238 | srcDirs 'src/test/native/cpp' |
| 239 | include '**/*.cpp' |
| 240 | } |
| 241 | exportedHeaders { |
| 242 | srcDirs 'src/test/native/include', 'src/main/native/cpp' |
| 243 | if (project.hasProperty('generatedHeaders')) { |
| 244 | srcDir generatedHeaders |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | binaries { |
| 252 | withType(GoogleTestTestSuiteBinarySpec) { |
| 253 | lib library: nativeName, linkage: 'shared' |
| 254 | if (!project.hasProperty('noWpiutil')) { |
| 255 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 256 | } |
| 257 | if (project.hasProperty('exeSplitSetup')) { |
| 258 | exeSplitSetup(it) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | } |
| 262 | tasks { |
| 263 | def c = $.components |
| 264 | project.tasks.create('runCpp', Exec) { |
| 265 | group = 'WPILib' |
| 266 | description = "Run the ${nativeName}Dev executable" |
| 267 | def found = false |
| 268 | def systemArch = getCurrentArch() |
| 269 | c.each { |
| 270 | if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") { |
| 271 | it.binaries.each { |
| 272 | if (!found) { |
| 273 | def arch = it.targetPlatform.name |
| 274 | if (arch == systemArch) { |
| 275 | dependsOn it.tasks.install |
| 276 | commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| 277 | def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| 278 | test.dependsOn it.tasks.install |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 279 | |
| 280 | if (project.hasProperty('buildServer')) { |
| 281 | def folderDir = it.tasks.install.installDirectory.get().toString() |
| 282 | test.doLast { |
| 283 | def folder = file(folderDir) |
| 284 | folder.deleteDir() |
| 285 | } |
| 286 | } |
| 287 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 288 | test.systemProperty 'java.library.path', filePath |
| 289 | test.environment 'LD_LIBRARY_PATH', filePath |
| 290 | test.workingDir filePath |
| 291 | run.dependsOn it.tasks.install |
| 292 | run.systemProperty 'java.library.path', filePath |
| 293 | run.environment 'LD_LIBRARY_PATH', filePath |
| 294 | run.workingDir filePath |
| 295 | |
| 296 | found = true |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | apply from: "${rootDir}/shared/cppDesktopTestTask.gradle" |
| 307 | apply from: "${rootDir}/shared/javaDesktopTestTask.gradle" |
| 308 | |
| 309 | ext.getJniSpecClass = { |
| 310 | return JniNativeLibrarySpec |
| 311 | } |
| 312 | |
| 313 | tasks.withType(RunTestExecutable) { |
| 314 | args "--gtest_output=xml:test_detail.xml" |
| 315 | outputs.dir outputDir |
| 316 | } |
| 317 | |
| 318 | apply from: "${rootDir}/shared/jni/publish.gradle" |