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