Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | import org.gradle.language.base.internal.ProjectLayout |
| 2 | |
| 3 | apply plugin: 'cpp' |
| 4 | apply plugin: 'c' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 5 | apply plugin: 'google-test-test-suite' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 6 | apply plugin: 'visual-studio' |
| 7 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 8 | apply plugin: ExtraTasks |
| 9 | |
| 10 | evaluationDependsOn(':hal') |
| 11 | |
| 12 | apply from: '../shared/config.gradle' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 13 | apply from: "${rootDir}/shared/googletest.gradle" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 14 | |
| 15 | ext.examplesMap = [:] |
| 16 | ext.templatesMap = [:] |
| 17 | |
| 18 | File examplesTree = file("$projectDir/src/main/cpp/examples") |
| 19 | examplesTree.list(new FilenameFilter() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 20 | @Override |
| 21 | public boolean accept(File current, String name) { |
| 22 | return new File(current, name).isDirectory(); |
| 23 | } |
| 24 | }).each { |
| 25 | examplesMap.put(it, []) |
| 26 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 27 | File templatesTree = file("$projectDir/src/main/cpp/templates") |
| 28 | templatesTree.list(new FilenameFilter() { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 29 | @Override |
| 30 | public boolean accept(File current, String name) { |
| 31 | return new File(current, name).isDirectory(); |
| 32 | } |
| 33 | }).each { |
| 34 | templatesMap.put(it, []) |
| 35 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 36 | |
| 37 | nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure { |
| 38 | cppCompiler.args.remove('-Wno-error=deprecated-declarations') |
| 39 | cppCompiler.args.add('-Werror=deprecated-declarations') |
| 40 | } |
| 41 | |
| 42 | ext { |
| 43 | sharedCvConfigs = examplesMap + templatesMap + [commands: []] |
| 44 | staticCvConfigs = [:] |
| 45 | useJava = false |
| 46 | useCpp = true |
| 47 | } |
| 48 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 49 | def simModules = ["halsim_gui"] |
| 50 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 51 | apply from: "${rootDir}/shared/opencv.gradle" |
| 52 | |
| 53 | model { |
| 54 | components { |
| 55 | commands(NativeLibrarySpec) { |
| 56 | binaries.all { binary -> |
| 57 | if (binary in StaticLibraryBinarySpec) { |
| 58 | binary.buildable = false |
| 59 | return |
| 60 | } |
| 61 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 62 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 63 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 64 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 65 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 66 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 67 | project(':hal').addHalDependency(binary, 'shared') |
| 68 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 69 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 70 | } |
| 71 | sources { |
| 72 | cpp { |
| 73 | source { |
| 74 | srcDirs = ['src/main/cpp/commands'] |
| 75 | include '**/*.cpp' |
| 76 | } |
| 77 | exportedHeaders { |
| 78 | srcDirs 'src/main/cpp/commands' |
| 79 | include '**/*.h' |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | examplesMap.each { key, value -> |
| 86 | "${key}"(NativeExecutableSpec) { |
| 87 | targetBuildTypes 'debug' |
| 88 | binaries.all { binary -> |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 89 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 90 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 91 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 92 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 93 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 94 | project(':hal').addHalDependency(binary, 'shared') |
| 95 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 96 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 97 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 98 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
| 99 | } |
| 100 | if (binary.targetPlatform.name == getCurrentArch()) { |
| 101 | simModules.each { |
| 102 | lib project: ":simulation:$it", library: it, linkage: 'shared' |
| 103 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | sources { |
| 107 | cpp { |
| 108 | source { |
| 109 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp" |
| 110 | include '**/*.cpp' |
| 111 | } |
| 112 | exportedHeaders { |
| 113 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 114 | include '**/*.h' |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | sources { |
| 119 | c { |
| 120 | source { |
| 121 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/c" |
| 122 | include '**/*.c' |
| 123 | } |
| 124 | exportedHeaders { |
| 125 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 126 | include '**/*.h' |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | templatesMap.each { key, value -> |
| 133 | "${key}"(NativeExecutableSpec) { |
| 134 | targetBuildTypes 'debug' |
| 135 | binaries.all { binary -> |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 136 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 137 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 138 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 139 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 140 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 141 | project(':hal').addHalDependency(binary, 'shared') |
| 142 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 143 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 144 | binary.tasks.withType(CppCompile) { |
| 145 | if (!(binary.toolChain in VisualCpp)) { |
| 146 | cppCompiler.args "-Wno-error=deprecated-declarations" |
| 147 | } else { |
| 148 | cppCompiler.args "/wd4996" |
| 149 | } |
| 150 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 151 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 152 | nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries') |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | sources { |
| 156 | cpp { |
| 157 | source { |
| 158 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp" |
| 159 | include '**/*.cpp' |
| 160 | } |
| 161 | exportedHeaders { |
| 162 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/include" |
| 163 | include '**/*.h' |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 170 | testSuites { |
| 171 | examplesMap.each { key, value -> |
| 172 | def testFolder = new File("${rootDir}/wpilibcExamples/src/test/cpp/examples/${key}") |
| 173 | if (testFolder.exists()) { |
| 174 | "${key}Test"(GoogleTestTestSuiteSpec) { |
| 175 | for (NativeComponentSpec c : $.components) { |
| 176 | if (c.name == key) { |
| 177 | testing c |
| 178 | break |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 179 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 180 | } |
| 181 | sources { |
| 182 | cpp { |
| 183 | source { |
| 184 | srcDirs "src/test/cpp/examples/${key}/cpp" |
| 185 | include '**/*.cpp' |
| 186 | } |
| 187 | exportedHeaders { |
| 188 | srcDirs "src/test/cpp/examples/${key}/include" |
| 189 | } |
| 190 | } |
| 191 | c { |
| 192 | source { |
| 193 | srcDirs "src/test/cpp/examples/${key}/c" |
| 194 | include '**/*.c' |
| 195 | } |
| 196 | exportedHeaders { |
| 197 | srcDirs "src/test/cpp/examples/${key}/include" |
| 198 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 205 | binaries { |
| 206 | withType(GoogleTestTestSuiteBinarySpec) { |
| 207 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 208 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 209 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
| 210 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 211 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 212 | project(':hal').addHalDependency(it, 'shared') |
| 213 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 214 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 215 | if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 216 | nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries') |
| 217 | } |
| 218 | nativeUtils.useRequiredLibrary(it, 'opencv_shared') |
| 219 | |
| 220 | it.cppCompiler.define('RUNNING_FRC_TESTS') |
| 221 | it.cCompiler.define('RUNNING_FRC_TESTS') |
| 222 | } |
| 223 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 224 | } |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 225 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 226 | apply from: 'publish.gradle' |
| 227 | |
| 228 | model { |
| 229 | tasks { |
| 230 | def c = $.components |
| 231 | project.tasks.register('buildDesktopCpp') { compileTask-> |
| 232 | def systemArch = getCurrentArch() |
| 233 | c.each { |
| 234 | if (it in NativeExecutableSpec && it.name) { |
| 235 | it.binaries.each { |
| 236 | def arch = it.targetPlatform.name |
| 237 | if (arch == systemArch && it.buildType.name == 'debug') { |
| 238 | compileTask.dependsOn it.tasks.link |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | ext { |
| 248 | templateDirectory = new File("$projectDir/src/main/cpp/templates/") |
| 249 | templateFile = new File("$projectDir/src/main/cpp/templates/templates.json") |
| 250 | exampleDirectory = new File("$projectDir/src/main/cpp/examples/") |
| 251 | exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json") |
| 252 | commandDirectory = new File("$projectDir/src/main/cpp/commands/") |
| 253 | commandFile = new File("$projectDir/src/main/cpp/commands/commands.json") |
| 254 | } |
| 255 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 256 | model { |
| 257 | // Create run tasks for all examples. |
| 258 | tasks { |
| 259 | // Iterate through the components and check if it is an example. |
| 260 | $.components.each { component -> |
| 261 | if (examplesMap.containsKey(component.name)) { |
| 262 | // Get the appropriate binary and create the run task. |
| 263 | component.binaries.each { binary -> |
| 264 | if (binary.targetPlatform.name == getCurrentArch() && binary.buildType.name == "debug") { |
| 265 | project.tasks.create("run${component.name}", Exec) { |
| 266 | // Add simulation modules to HALSIM_EXTENSIONS environment variable. |
| 267 | def setupEnv = { |
| 268 | String extensions = "" |
| 269 | binary.tasks.install.installDirectory.get().getAsFile().eachFileRecurse { |
| 270 | def name = it.name |
| 271 | |
| 272 | // If we don't have a shared library, skip. |
| 273 | if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib'))) |
| 274 | return |
| 275 | |
| 276 | def file = it |
| 277 | simModules.each { |
| 278 | if (name.startsWith(it) || name.startsWith("lib$it".toString())) { |
| 279 | extensions += file.absolutePath + File.pathSeparator |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if (extensions != '') { |
| 285 | environment 'HALSIM_EXTENSIONS', extensions |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Create the task dependency and run the executable. |
| 290 | doFirst { setupEnv() } |
| 291 | dependsOn binary.tasks.install |
| 292 | commandLine binary.tasks.install.runScriptFile.get().asFile.toString() |
| 293 | |
| 294 | group = "application" |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 304 | ext { |
| 305 | isCppCommands = true |
| 306 | } |
| 307 | apply from: "${rootDir}/shared/examplecheck.gradle" |