Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -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 { |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 19 | if (!project.hasProperty('noWpiutil')) { |
| 20 | compile project(':wpiutil') |
| 21 | devCompile project(':wpiutil') |
| 22 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 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 | if (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 | |
| 47 | model { |
| 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 74 | if (!project.hasProperty('noWpiutil')) { |
| 75 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 76 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 77 | 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 100 | if (!project.hasProperty('noWpiutil')) { |
| 101 | binaries.all { |
| 102 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 103 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 104 | } |
| 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 113 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 114 | enableCheckTask true |
| 115 | javaCompileTasks << compileJava |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 116 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio) |
| 117 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian) |
| 118 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 119 | 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 141 | if (!project.hasProperty('noWpiutil')) { |
| 142 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 143 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 144 | 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 155 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 156 | enableCheckTask true |
| 157 | javaCompileTasks << compileJava |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 158 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio) |
| 159 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.raspbian) |
| 160 | jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.aarch64bionic) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 161 | 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 181 | if (!project.hasProperty('noWpiutil')) { |
| 182 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' |
| 183 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 184 | 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 211 | if (!project.hasProperty('noWpiutil')) { |
| 212 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 213 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 214 | } |
| 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 243 | lib library: nativeName, linkage: 'shared' |
| 244 | if (!project.hasProperty('noWpiutil')) { |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 245 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 246 | } |
| 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 Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame^] | 260 | def arch = it.targetPlatform.name |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 261 | 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 | |
| 284 | ext.getJniSpecClass = { |
| 285 | return JniNativeLibrarySpec |
| 286 | } |
| 287 | |
| 288 | tasks.withType(RunTestExecutable) { |
| 289 | args "--gtest_output=xml:test_detail.xml" |
| 290 | outputs.dir outputDir |
| 291 | } |
| 292 | |
| 293 | apply from: "${rootDir}/shared/jni/publish.gradle" |