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' |
| 5 | apply plugin: 'visual-studio' |
| 6 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 7 | apply plugin: ExtraTasks |
| 8 | |
| 9 | evaluationDependsOn(':hal') |
| 10 | |
| 11 | apply from: '../shared/config.gradle' |
| 12 | |
| 13 | ext.examplesMap = [:] |
| 14 | ext.templatesMap = [:] |
| 15 | |
| 16 | File examplesTree = file("$projectDir/src/main/cpp/examples") |
| 17 | examplesTree.list(new FilenameFilter() { |
| 18 | @Override |
| 19 | public boolean accept(File current, String name) { |
| 20 | return new File(current, name).isDirectory(); |
| 21 | } |
| 22 | }).each { |
| 23 | examplesMap.put(it, []) |
| 24 | } |
| 25 | File templatesTree = file("$projectDir/src/main/cpp/templates") |
| 26 | templatesTree.list(new FilenameFilter() { |
| 27 | @Override |
| 28 | public boolean accept(File current, String name) { |
| 29 | return new File(current, name).isDirectory(); |
| 30 | } |
| 31 | }).each { |
| 32 | templatesMap.put(it, []) |
| 33 | } |
| 34 | |
| 35 | nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure { |
| 36 | cppCompiler.args.remove('-Wno-error=deprecated-declarations') |
| 37 | cppCompiler.args.add('-Werror=deprecated-declarations') |
| 38 | } |
| 39 | |
| 40 | ext { |
| 41 | sharedCvConfigs = examplesMap + templatesMap + [commands: []] |
| 42 | staticCvConfigs = [:] |
| 43 | useJava = false |
| 44 | useCpp = true |
| 45 | } |
| 46 | |
| 47 | apply from: "${rootDir}/shared/opencv.gradle" |
| 48 | |
| 49 | model { |
| 50 | components { |
| 51 | commands(NativeLibrarySpec) { |
| 52 | binaries.all { binary -> |
| 53 | if (binary in StaticLibraryBinarySpec) { |
| 54 | binary.buildable = false |
| 55 | return |
| 56 | } |
| 57 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 58 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 59 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 60 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 61 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 62 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 63 | project(':hal').addHalDependency(binary, 'shared') |
| 64 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 65 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 66 | } |
| 67 | sources { |
| 68 | cpp { |
| 69 | source { |
| 70 | srcDirs = ['src/main/cpp/commands'] |
| 71 | include '**/*.cpp' |
| 72 | } |
| 73 | exportedHeaders { |
| 74 | srcDirs 'src/main/cpp/commands' |
| 75 | include '**/*.h' |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | examplesMap.each { key, value -> |
| 82 | "${key}"(NativeExecutableSpec) { |
| 83 | targetBuildTypes 'debug' |
| 84 | binaries.all { binary -> |
| 85 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 86 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 87 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 88 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 89 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 90 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 91 | project(':hal').addHalDependency(binary, 'shared') |
| 92 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 93 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 94 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 95 | nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared') |
| 96 | } |
| 97 | } |
| 98 | sources { |
| 99 | cpp { |
| 100 | source { |
| 101 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp" |
| 102 | include '**/*.cpp' |
| 103 | } |
| 104 | exportedHeaders { |
| 105 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 106 | include '**/*.h' |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | sources { |
| 111 | c { |
| 112 | source { |
| 113 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/c" |
| 114 | include '**/*.c' |
| 115 | } |
| 116 | exportedHeaders { |
| 117 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 118 | include '**/*.h' |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | templatesMap.each { key, value -> |
| 125 | "${key}"(NativeExecutableSpec) { |
| 126 | targetBuildTypes 'debug' |
| 127 | binaries.all { binary -> |
| 128 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 129 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
| 130 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 131 | lib project: ':wpimath', library: 'wpimath', linkage: 'shared' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 132 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 133 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 134 | project(':hal').addHalDependency(binary, 'shared') |
| 135 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 136 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 137 | binary.tasks.withType(CppCompile) { |
| 138 | if (!(binary.toolChain in VisualCpp)) { |
| 139 | cppCompiler.args "-Wno-error=deprecated-declarations" |
| 140 | } else { |
| 141 | cppCompiler.args "/wd4996" |
| 142 | } |
| 143 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 144 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 145 | nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared') |
| 146 | } |
| 147 | } |
| 148 | sources { |
| 149 | cpp { |
| 150 | source { |
| 151 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp" |
| 152 | include '**/*.cpp' |
| 153 | } |
| 154 | exportedHeaders { |
| 155 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/include" |
| 156 | include '**/*.h' |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | tasks { |
| 164 | def b = $.binaries |
| 165 | b.each { binary-> |
| 166 | if (binary in NativeExecutableBinarySpec) { |
| 167 | def installDir = binary.tasks.install.installDirectory.get().toString() + File.separatorChar |
| 168 | def runFile = binary.tasks.install.runScriptFile.get().asFile.toString() |
| 169 | |
| 170 | binary.tasks.install.doLast { |
| 171 | if (binary.targetPlatform.operatingSystem.isWindows()) { |
| 172 | // Windows batch scripts |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 173 | fileName = binary.component.name + 'RealDS.bat' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 174 | file = new File(installDir + fileName) |
| 175 | file.withWriter { out -> |
| 176 | out.println '@ECHO OFF' |
| 177 | out.print 'SET HALSIM_EXTENSIONS=' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 178 | out.println '"' + new File(installDir + 'lib\\halsim_ds_socket.dll').toString() + '"' |
| 179 | out.println runFile + ' %*' |
| 180 | } |
| 181 | } else { |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 182 | fileName = binary.component.name + 'RealDS.sh' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 183 | file = new File(installDir + fileName) |
| 184 | file.withWriter { out -> |
| 185 | out.print 'export HALSIM_EXTENSIONS=' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 186 | out.println '"' + new File(installDir + '/lib/libhalsim_ds_socket.so').toString() + '"' |
| 187 | out.println runFile + ' "$@"' |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | apply from: 'publish.gradle' |
| 197 | |
| 198 | model { |
| 199 | tasks { |
| 200 | def c = $.components |
| 201 | project.tasks.register('buildDesktopCpp') { compileTask-> |
| 202 | def systemArch = getCurrentArch() |
| 203 | c.each { |
| 204 | if (it in NativeExecutableSpec && it.name) { |
| 205 | it.binaries.each { |
| 206 | def arch = it.targetPlatform.name |
| 207 | if (arch == systemArch && it.buildType.name == 'debug') { |
| 208 | compileTask.dependsOn it.tasks.link |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | ext { |
| 218 | templateDirectory = new File("$projectDir/src/main/cpp/templates/") |
| 219 | templateFile = new File("$projectDir/src/main/cpp/templates/templates.json") |
| 220 | exampleDirectory = new File("$projectDir/src/main/cpp/examples/") |
| 221 | exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json") |
| 222 | commandDirectory = new File("$projectDir/src/main/cpp/commands/") |
| 223 | commandFile = new File("$projectDir/src/main/cpp/commands/commands.json") |
| 224 | } |
| 225 | |
| 226 | ext { |
| 227 | isCppCommands = true |
| 228 | } |
| 229 | apply from: "${rootDir}/shared/examplecheck.gradle" |