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' |
| 45 | include '**/*.cpp' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 46 | exclude '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 47 | } |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 62 | it.cppCompiler.define 'WPILIB_EXPORTS' |
| 63 | it.cCompiler.define 'WPILIB_EXPORTS' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 64 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 104 | enableCheckTask !project.hasProperty('skipJniCheck') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 105 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 113 | include '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 114 | } |
| 115 | exportedHeaders { |
| 116 | srcDir 'src/main/native/include' |
| 117 | if (project.hasProperty('generatedHeaders')) { |
| 118 | srcDir generatedHeaders |
| 119 | } |
| 120 | include '**/*.h' |
| 121 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 122 | } |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 145 | enableCheckTask !project.hasProperty('skipJniCheck') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 146 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 154 | include '**/jni/**/*.cpp' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 155 | } |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 202 | lib project: ':wpiutil', library: 'wpiutilJNIShared', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 203 | } |
| 204 | if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 205 | nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 206 | } |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 240 | nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 241 | } |
| 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 262 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 271 | 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 | |
| 289 | apply from: "${rootDir}/shared/cppDesktopTestTask.gradle" |
| 290 | apply from: "${rootDir}/shared/javaDesktopTestTask.gradle" |
| 291 | |
| 292 | ext.getJniSpecClass = { |
| 293 | return JniNativeLibrarySpec |
| 294 | } |
| 295 | |
| 296 | tasks.withType(RunTestExecutable) { |
| 297 | args "--gtest_output=xml:test_detail.xml" |
| 298 | outputs.dir outputDir |
| 299 | } |
| 300 | |
| 301 | apply from: "${rootDir}/shared/jni/publish.gradle" |