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 { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 44 | srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp" |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 45 | if (project.hasProperty('generatedSources')) { |
| 46 | srcDir generatedSources |
| 47 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 48 | include '**/*.cpp', '**/*.cc' |
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 { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 52 | srcDirs 'src/main/native/include', "$buildDir/generated/source/proto/main/cpp" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 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 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 70 | it.tasks.withType(CppCompile) { |
| 71 | it.dependsOn generateProto |
| 72 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 73 | 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 110 | if (project.hasProperty('skipJniSymbols')) { |
| 111 | checkSkipSymbols = skipJniSymbols |
| 112 | } |
| 113 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 114 | enableCheckTask !project.hasProperty('skipJniCheck') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 115 | javaCompileTasks << compileJava |
| 116 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 117 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32) |
| 118 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 119 | sources { |
| 120 | cpp { |
| 121 | source { |
| 122 | srcDirs 'src/main/native/cpp' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 123 | if (project.hasProperty('generatedSources')) { |
| 124 | srcDir generatedSources |
| 125 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 126 | include '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 127 | } |
| 128 | exportedHeaders { |
| 129 | srcDir 'src/main/native/include' |
| 130 | if (project.hasProperty('generatedHeaders')) { |
| 131 | srcDir generatedHeaders |
| 132 | } |
| 133 | include '**/*.h' |
| 134 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 135 | } |
| 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 158 | if (project.hasProperty('skipJniSymbols')) { |
| 159 | checkSkipSymbols = skipJniSymbols |
| 160 | } |
| 161 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 162 | enableCheckTask !project.hasProperty('skipJniCheck') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 163 | javaCompileTasks << compileJava |
| 164 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 165 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32) |
| 166 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 167 | sources { |
| 168 | cpp { |
| 169 | source { |
| 170 | srcDirs 'src/main/native/cpp' |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 171 | if (project.hasProperty('generatedSources')) { |
| 172 | srcDir generatedSources |
| 173 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 174 | include '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 175 | } |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 204 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 221 | lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 222 | if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 223 | nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries') |
| 224 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 225 | } |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame^] | 226 | it.tasks.withType(CppCompile) { |
| 227 | it.dependsOn generateProto |
| 228 | } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 229 | if (project.hasProperty('exeSplitSetup')) { |
| 230 | exeSplitSetup(it) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 234 | "${nativeName}TestLib"(NativeLibrarySpec) { |
| 235 | sources { |
| 236 | cpp { |
| 237 | source { |
| 238 | srcDirs 'src/testlib/native/cpp' |
| 239 | include '**/*.cpp' |
| 240 | } |
| 241 | exportedHeaders { |
| 242 | srcDirs 'src/test/native/include' |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 247 | } |
| 248 | testSuites { |
| 249 | "${nativeName}Test"(GoogleTestTestSuiteSpec) { |
| 250 | for(NativeComponentSpec c : $.components) { |
| 251 | if (c.name == nativeName) { |
| 252 | testing c |
| 253 | break |
| 254 | } |
| 255 | } |
| 256 | sources { |
| 257 | cpp { |
| 258 | source { |
| 259 | srcDirs 'src/test/native/cpp' |
| 260 | include '**/*.cpp' |
| 261 | } |
| 262 | exportedHeaders { |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame^] | 263 | srcDirs 'src/test/native/include', 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 264 | if (project.hasProperty('generatedHeaders')) { |
| 265 | srcDir generatedHeaders |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | binaries { |
| 273 | withType(GoogleTestTestSuiteBinarySpec) { |
| 274 | lib library: nativeName, linkage: 'shared' |
| 275 | if (!project.hasProperty('noWpiutil')) { |
| 276 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 277 | lib project: ':wpiutil', library: 'wpiutilTestLib', linkage: 'shared' |
| 278 | if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 279 | nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries') |
| 280 | } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 281 | } |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame^] | 282 | it.tasks.withType(CppCompile) { |
| 283 | it.dependsOn generateProto |
| 284 | } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 285 | if (project.hasProperty('exeSplitSetup')) { |
| 286 | exeSplitSetup(it) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | } |
| 290 | tasks { |
| 291 | def c = $.components |
| 292 | project.tasks.create('runCpp', Exec) { |
| 293 | group = 'WPILib' |
| 294 | description = "Run the ${nativeName}Dev executable" |
| 295 | def found = false |
| 296 | def systemArch = getCurrentArch() |
| 297 | c.each { |
| 298 | if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") { |
| 299 | it.binaries.each { |
| 300 | if (!found) { |
| 301 | def arch = it.targetPlatform.name |
| 302 | if (arch == systemArch) { |
| 303 | dependsOn it.tasks.install |
| 304 | commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| 305 | def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| 306 | test.dependsOn it.tasks.install |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 307 | |
| 308 | if (project.hasProperty('buildServer')) { |
| 309 | def folderDir = it.tasks.install.installDirectory.get().toString() |
| 310 | test.doLast { |
| 311 | def folder = file(folderDir) |
| 312 | folder.deleteDir() |
| 313 | } |
| 314 | } |
| 315 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 316 | test.systemProperty 'java.library.path', filePath |
| 317 | test.environment 'LD_LIBRARY_PATH', filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 318 | test.environment 'DYLD_LIBRARY_PATH', filePath |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 319 | test.workingDir filePath |
| 320 | run.dependsOn it.tasks.install |
| 321 | run.systemProperty 'java.library.path', filePath |
| 322 | run.environment 'LD_LIBRARY_PATH', filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 323 | run.environment 'DYLD_LIBRARY_PATH', filePath |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 324 | run.workingDir filePath |
| 325 | |
| 326 | found = true |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 336 | apply from: "${rootDir}/shared/cppJavaDesktopTestTask.gradle" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 337 | |
| 338 | ext.getJniSpecClass = { |
| 339 | return JniNativeLibrarySpec |
| 340 | } |
| 341 | |
| 342 | tasks.withType(RunTestExecutable) { |
| 343 | args "--gtest_output=xml:test_detail.xml" |
| 344 | outputs.dir outputDir |
| 345 | } |
| 346 | |
| 347 | apply from: "${rootDir}/shared/jni/publish.gradle" |