John Park | 7eb9042 | 2018-01-27 12:04:57 -0800 | [diff] [blame] | 1 | apply plugin: 'cpp' |
| 2 | apply plugin: 'google-test' |
| 3 | apply plugin: 'visual-studio' |
| 4 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 5 | |
| 6 | apply from: '../config.gradle' |
| 7 | |
| 8 | ext.addWpilibCCompilerArguments = { binary-> |
| 9 | binary.tasks.withType(CppCompile) { |
| 10 | binary.cppCompiler.args "-DNAMESPACED_WPILIB" |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | ext.addWpilibCToLinker = { binary-> |
| 15 | binary.lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 16 | } |
| 17 | |
| 18 | def versionClass = """ |
| 19 | /* |
| 20 | * Autogenerated file! Do not manually edit this file. This version is regenerated |
| 21 | * any time the publish task is run, or when this file is deleted. |
| 22 | */ |
| 23 | const char* GetWPILibVersion() { |
| 24 | return "${WPILibVersion.version}"; |
| 25 | } |
| 26 | """.trim() |
| 27 | |
| 28 | def wpilibVersionFile = file('src/main/native/cpp/WPILibVersion.cpp') |
| 29 | |
| 30 | def willPublish = false |
| 31 | gradle.taskGraph.addTaskExecutionGraphListener { graph -> |
| 32 | willPublish = graph.hasTask(publish) |
| 33 | } |
| 34 | |
| 35 | task generateCppVersion() { |
| 36 | description = 'Generates the wpilib version class' |
| 37 | group = 'WPILib' |
| 38 | |
| 39 | // We follow a simple set of checks to determine whether we should generate a new version file: |
| 40 | // 1. If the release type is not development, we generate a new verison file |
| 41 | // 2. If there is no generated version number, we generate a new version file |
| 42 | // 3. If there is a generated build number, and the release type is development, then we will |
| 43 | // only generate if the publish task is run. |
| 44 | doLast { |
| 45 | if (!WPILibVersion.releaseType.toString().equalsIgnoreCase('official') && !willPublish && wpilibVersionFile.exists()) { |
| 46 | return |
| 47 | } |
| 48 | println "Writing version ${WPILibVersion.version} to $wpilibVersionFile" |
| 49 | |
| 50 | if (wpilibVersionFile.exists()) { |
| 51 | wpilibVersionFile.delete() |
| 52 | } |
| 53 | wpilibVersionFile.write(versionClass) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | clean { |
| 58 | delete wpilibVersionFile |
| 59 | } |
| 60 | |
| 61 | model { |
| 62 | dependencyConfigs { |
| 63 | wpiutil(DependencyConfig) { |
| 64 | groupId = 'edu.wpi.first.wpiutil' |
| 65 | artifactId = 'wpiutil-cpp' |
| 66 | headerClassifier = 'headers' |
| 67 | ext = 'zip' |
| 68 | version = '3.+' |
| 69 | sharedConfigs = [ wpilibc: [], |
| 70 | wpilibcTestingBaseTest: [], |
| 71 | wpilibcDev: [] ] |
| 72 | } |
| 73 | ntcore(DependencyConfig) { |
| 74 | groupId = 'edu.wpi.first.ntcore' |
| 75 | artifactId = 'ntcore-cpp' |
| 76 | headerClassifier = 'headers' |
| 77 | ext = 'zip' |
| 78 | version = '4.+' |
| 79 | sharedConfigs = [ wpilibc: [], |
| 80 | wpilibcTestingBaseTest: [], |
| 81 | wpilibcDev: [] ] |
| 82 | } |
| 83 | opencv(DependencyConfig) { |
| 84 | groupId = 'org.opencv' |
| 85 | artifactId = 'opencv-cpp' |
| 86 | headerClassifier = 'headers' |
| 87 | ext = 'zip' |
| 88 | version = '3.2.0' |
| 89 | sharedConfigs = [ wpilibc: [], |
| 90 | wpilibcTestingBaseTest: [], |
| 91 | wpilibcDev: [] ] |
| 92 | } |
| 93 | cscore(DependencyConfig) { |
| 94 | groupId = 'edu.wpi.first.cscore' |
| 95 | artifactId = 'cscore-cpp' |
| 96 | headerClassifier = 'headers' |
| 97 | ext = 'zip' |
| 98 | version = '1.+' |
| 99 | sharedConfigs = [ wpilibc: [], |
| 100 | wpilibcTestingBaseTest: [], |
| 101 | wpilibcDev: [] ] |
| 102 | } |
| 103 | } |
| 104 | exportsConfigs { |
| 105 | wpilibc(ExportsConfig) { |
| 106 | x86ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', |
| 107 | '_CT??_R0?AVbad_cast', |
| 108 | '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', |
| 109 | '_TI5?AVfailure' ] |
| 110 | x64ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', |
| 111 | '_CT??_R0?AVbad_cast', |
| 112 | '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', |
| 113 | '_TI5?AVfailure' ] |
| 114 | } |
| 115 | } |
| 116 | components { |
| 117 | wpilibc(NativeLibrarySpec) { |
| 118 | sources { |
| 119 | cpp { |
| 120 | source { |
| 121 | srcDirs = [ 'src/main/native/cpp' ] |
| 122 | includes = ["**/*.cpp"] |
| 123 | } |
| 124 | exportedHeaders { |
| 125 | srcDirs = ["src/main/native/include"] |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | // The TestingBase library is a workaround for an issue with the GoogleTest plugin. |
| 131 | // The plugin by default will rebuild the entire test source set, which increases |
| 132 | // build time. By testing an empty library, and then just linking the already built component |
| 133 | // into the test, we save the extra build |
| 134 | if (!project.hasProperty('onlyAthena')) { |
| 135 | wpilibcTestingBase(NativeLibrarySpec) { } |
| 136 | } |
| 137 | // By default, a development executable will be generated. This is to help the case of |
| 138 | // testing specific functionality of the library. |
| 139 | if (!project.hasProperty('skipDevExe')) { |
| 140 | wpilibcDev(NativeExecutableSpec) { |
| 141 | binaries.all { |
| 142 | project.addWpilibCToLinker(it) |
| 143 | } |
| 144 | sources { |
| 145 | cpp { |
| 146 | source { |
| 147 | srcDirs 'src/dev/native/cpp' |
| 148 | include '**/*.cpp' |
| 149 | } |
| 150 | exportedHeaders { |
| 151 | srcDirs 'src/dev/native/include' |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | testSuites { |
| 159 | if (!project.hasProperty('onlyAthena')) { |
| 160 | wpilibcTestingBaseTest { |
| 161 | sources { |
| 162 | cpp.source.srcDir 'src/test/native/cpp' |
| 163 | cpp.exportedHeaders.srcDir 'src/test/native/include' |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | binaries { |
| 169 | all { |
| 170 | tasks.withType(CppCompile) { |
| 171 | dependsOn generateCppVersion |
| 172 | } |
| 173 | project(':ni-libraries').addNiLibrariesToLinker(it) |
| 174 | project(':hal').addHalToLinker(it) |
| 175 | project.addWpilibCCompilerArguments(it) |
| 176 | } |
| 177 | withType(GoogleTestTestSuiteBinarySpec) { |
| 178 | if (it.component.testedComponent.name.contains('TestingBase') && !project.hasProperty('onlyAthena')) { |
| 179 | project(':gmock').addGmockToLinker(it) |
| 180 | project.addWpilibCToLinker(it) |
| 181 | } else { |
| 182 | it.buildable = false |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | tasks { |
| 187 | runCpp(Exec) { |
| 188 | def found = false |
| 189 | $.components.each { |
| 190 | if (it in NativeExecutableSpec && it.name == 'wpilibcDev') { |
| 191 | it.binaries.each { |
| 192 | if (!found) { |
| 193 | def arch = it.targetPlatform.architecture.name |
| 194 | if (arch == 'x86-64' || arch == 'x86') { |
| 195 | dependsOn it.tasks.install |
| 196 | commandLine it.tasks.install.runScript |
| 197 | found = true |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | getHeaders(Task) { |
| 205 | def list = [] |
| 206 | $.components.each { |
| 207 | if (it in NativeLibrarySpec && it.name == 'wpilibc') { |
| 208 | it.sources.each { |
| 209 | it.exportedHeaders.srcDirs.each { |
| 210 | list.add(it) |
| 211 | } |
| 212 | } |
| 213 | it.binaries.each { |
| 214 | it.libs.each { |
| 215 | it.includeRoots.each { |
| 216 | list.add(it) |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | list = list.unique(false) |
| 223 | doLast { |
| 224 | list.each { |
| 225 | print "WPIHEADER: " |
| 226 | println it |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | apply from: 'publish.gradle' |