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 { |
| 19 | compile project(':wpiutil') |
| 20 | devCompile project(':wpiutil') |
| 21 | } |
| 22 | |
| 23 | project(':').libraryBuild.dependsOn build |
| 24 | |
| 25 | ext { |
| 26 | staticGtestConfigs = [:] |
| 27 | } |
| 28 | |
| 29 | staticGtestConfigs["${nativeName}Test"] = [] |
| 30 | |
| 31 | apply from: "${rootDir}/shared/googletest.gradle" |
| 32 | |
| 33 | if (project.hasProperty('niLibraries')) { |
| 34 | ext { |
| 35 | chipObjectComponents = ["$nativeName".toString(), "${nativeName}Dev".toString(), "${nativeName}Base".toString(), |
| 36 | "${nativeName}JNI".toString(), "${nativeName}JNIShared".toString(), "${nativeName}Test".toString()] |
| 37 | netCommComponents = ["$nativeName".toString(), "${nativeName}Dev".toString(), "${nativeName}Base".toString(), |
| 38 | "${nativeName}JNI".toString(), "${nativeName}JNIShared".toString(), "${nativeName}Test".toString()] |
| 39 | useNiJava = true |
| 40 | } |
| 41 | |
| 42 | apply from: "${rootDir}/shared/nilibraries.gradle" |
| 43 | } |
| 44 | |
| 45 | model { |
| 46 | components { |
| 47 | "${nativeName}Base"(NativeLibrarySpec) { |
| 48 | if (project.hasProperty('setBaseName')) { |
| 49 | baseName = setBaseName |
| 50 | } |
| 51 | sources { |
| 52 | cpp { |
| 53 | source { |
| 54 | srcDirs 'src/main/native/cpp' |
| 55 | include '**/*.cpp' |
| 56 | exclude '**/jni/*.cpp' |
| 57 | } |
| 58 | exportedHeaders { |
| 59 | srcDir 'src/main/native/include' |
| 60 | if (project.hasProperty('generatedHeaders')) { |
| 61 | srcDir generatedHeaders |
| 62 | } |
| 63 | include '**/*.h' |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | binaries.all { |
| 68 | if (it instanceof SharedLibraryBinarySpec) { |
| 69 | it.buildable = false |
| 70 | return |
| 71 | } |
| 72 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 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 | binaries.all { |
| 97 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 98 | } |
| 99 | appendDebugPathToBinaries(binaries) |
| 100 | } |
| 101 | "${nativeName}JNIShared"(JniNativeLibrarySpec) { |
| 102 | if (project.hasProperty('setBaseName')) { |
| 103 | baseName = setBaseName + 'jni' |
| 104 | } else { |
| 105 | baseName = nativeName + 'jni' |
| 106 | } |
| 107 | enableCheckTask true |
| 108 | javaCompileTasks << compileJava |
| 109 | jniCrossCompileOptions << JniCrossCompileOptions('athena') |
| 110 | jniCrossCompileOptions << JniCrossCompileOptions('raspbian') |
| 111 | sources { |
| 112 | cpp { |
| 113 | source { |
| 114 | srcDirs 'src/main/native/cpp' |
| 115 | include '**/jni/*.cpp' |
| 116 | } |
| 117 | exportedHeaders { |
| 118 | srcDir 'src/main/native/include' |
| 119 | if (project.hasProperty('generatedHeaders')) { |
| 120 | srcDir generatedHeaders |
| 121 | } |
| 122 | include '**/*.h' |
| 123 | } |
| 124 | |
| 125 | } |
| 126 | } |
| 127 | binaries.all { |
| 128 | if (it instanceof StaticLibraryBinarySpec) { |
| 129 | it.buildable = false |
| 130 | return |
| 131 | } |
| 132 | lib library: "${nativeName}", linkage: 'shared' |
| 133 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 134 | if (project.hasProperty('jniSplitSetup')) { |
| 135 | jniSplitSetup(it) |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | "${nativeName}JNI"(JniNativeLibrarySpec) { |
| 140 | if (project.hasProperty('setBaseName')) { |
| 141 | baseName = setBaseName + 'jni' |
| 142 | } else { |
| 143 | baseName = nativeName + 'jni' |
| 144 | } |
| 145 | enableCheckTask true |
| 146 | javaCompileTasks << compileJava |
| 147 | jniCrossCompileOptions << JniCrossCompileOptions('athena') |
| 148 | jniCrossCompileOptions << JniCrossCompileOptions('raspbian') |
| 149 | sources { |
| 150 | cpp { |
| 151 | source { |
| 152 | srcDirs 'src/main/native/cpp' |
| 153 | include '**/jni/*.cpp' |
| 154 | } |
| 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 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' |
| 170 | if (project.hasProperty('jniSplitSetup')) { |
| 171 | jniSplitSetup(it) |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | // By default, a development executable will be generated. This is to help the case of |
| 176 | // testing specific functionality of the library. |
| 177 | "${nativeName}Dev"(NativeExecutableSpec) { |
| 178 | targetBuildTypes 'debug' |
| 179 | sources { |
| 180 | cpp { |
| 181 | |
| 182 | source { |
| 183 | srcDirs 'src/dev/native/cpp' |
| 184 | include '**/*.cpp' |
| 185 | } |
| 186 | exportedHeaders { |
| 187 | srcDir 'src/main/native/include' |
| 188 | if (project.hasProperty('generatedHeaders')) { |
| 189 | srcDir generatedHeaders |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | binaries.all { |
| 195 | lib library: nativeName, linkage: 'shared' |
| 196 | lib library: "${nativeName}JNIShared", linkage: 'shared' |
| 197 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | testSuites { |
| 202 | "${nativeName}Test"(GoogleTestTestSuiteSpec) { |
| 203 | for(NativeComponentSpec c : $.components) { |
| 204 | if (c.name == nativeName) { |
| 205 | testing c |
| 206 | break |
| 207 | } |
| 208 | } |
| 209 | sources { |
| 210 | cpp { |
| 211 | source { |
| 212 | srcDirs 'src/test/native/cpp' |
| 213 | include '**/*.cpp' |
| 214 | } |
| 215 | exportedHeaders { |
| 216 | srcDirs 'src/test/native/include', 'src/main/native/cpp' |
| 217 | if (project.hasProperty('generatedHeaders')) { |
| 218 | srcDir generatedHeaders |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | binaries { |
| 226 | withType(GoogleTestTestSuiteBinarySpec) { |
| 227 | if (!project.hasProperty('onlyAthena') && !project.hasProperty('onlyRaspbian')) { |
| 228 | lib library: nativeName, linkage: 'shared' |
| 229 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 230 | } else { |
| 231 | it.buildable = false |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | tasks { |
| 236 | def c = $.components |
| 237 | project.tasks.create('runCpp', Exec) { |
| 238 | group = 'WPILib' |
| 239 | description = "Run the ${nativeName}Dev executable" |
| 240 | def found = false |
| 241 | def systemArch = getCurrentArch() |
| 242 | c.each { |
| 243 | if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") { |
| 244 | it.binaries.each { |
| 245 | if (!found) { |
| 246 | def arch = it.targetPlatform.architecture.name |
| 247 | if (arch == systemArch) { |
| 248 | dependsOn it.tasks.install |
| 249 | commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| 250 | def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| 251 | test.dependsOn it.tasks.install |
| 252 | test.systemProperty 'java.library.path', filePath |
| 253 | test.environment 'LD_LIBRARY_PATH', filePath |
| 254 | test.workingDir filePath |
| 255 | run.dependsOn it.tasks.install |
| 256 | run.systemProperty 'java.library.path', filePath |
| 257 | run.environment 'LD_LIBRARY_PATH', filePath |
| 258 | run.workingDir filePath |
| 259 | |
| 260 | found = true |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | ext.getJniSpecClass = { |
| 271 | return JniNativeLibrarySpec |
| 272 | } |
| 273 | |
| 274 | tasks.withType(RunTestExecutable) { |
| 275 | args "--gtest_output=xml:test_detail.xml" |
| 276 | outputs.dir outputDir |
| 277 | } |
| 278 | |
| 279 | apply from: "${rootDir}/shared/jni/publish.gradle" |