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