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 | |
| 33 | |
| 34 | ext { |
| 35 | sharedCvConfigs = examplesMap + templatesMap + [commands: []] |
| 36 | staticCvConfigs = [:] |
| 37 | useJava = false |
| 38 | useCpp = true |
| 39 | } |
| 40 | |
| 41 | apply from: "${rootDir}/shared/opencv.gradle" |
| 42 | |
| 43 | ext { |
| 44 | chipObjectComponents = ['commands'] |
| 45 | netCommComponents = ['commands'] |
| 46 | examplesMap.each { key, value -> |
| 47 | chipObjectComponents << key.toString() |
| 48 | netCommComponents << key.toString() |
| 49 | } |
| 50 | templatesMap.each { key, value -> |
| 51 | chipObjectComponents << key.toString() |
| 52 | netCommComponents << key.toString() |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | apply from: "${rootDir}/shared/nilibraries.gradle" |
| 57 | |
| 58 | model { |
| 59 | components { |
| 60 | commands(NativeLibrarySpec) { |
| 61 | binaries.all { binary -> |
| 62 | if (binary in StaticLibraryBinarySpec) { |
| 63 | binary.buildable = false |
| 64 | return |
| 65 | } |
| 66 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 67 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 68 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 69 | project(':hal').addHalDependency(binary, 'shared') |
| 70 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 71 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 72 | } |
| 73 | sources { |
| 74 | cpp { |
| 75 | source { |
| 76 | srcDirs = ['src/main/cpp/commands'] |
| 77 | include '**/*.cpp' |
| 78 | } |
| 79 | exportedHeaders { |
| 80 | srcDirs 'src/main/cpp/commands' |
| 81 | include '**/*.h' |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | examplesMap.each { key, value -> |
| 88 | "${key}"(NativeExecutableSpec) { |
| 89 | targetBuildTypes 'debug' |
| 90 | binaries.all { binary -> |
| 91 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 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' |
| 97 | if (binary.targetPlatform.architecture.name != 'athena') { |
| 98 | lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared' |
| 99 | lib project: ':simulation:halsim_adx_gyro_accelerometer', library: 'halsim_adx_gyro_accelerometer', linkage: 'shared' |
| 100 | lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared' |
| 101 | lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared' |
| 102 | } |
| 103 | } |
| 104 | sources { |
| 105 | cpp { |
| 106 | source { |
| 107 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp" |
| 108 | include '**/*.cpp' |
| 109 | } |
| 110 | exportedHeaders { |
| 111 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 112 | include '**/*.h' |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | sources { |
| 117 | c { |
| 118 | source { |
| 119 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/c" |
| 120 | include '**/*.c' |
| 121 | } |
| 122 | exportedHeaders { |
| 123 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 124 | include '**/*.h' |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | templatesMap.each { key, value -> |
| 131 | "${key}"(NativeExecutableSpec) { |
| 132 | targetBuildTypes 'debug' |
| 133 | binaries.all { binary -> |
| 134 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 135 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 136 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 137 | project(':hal').addHalDependency(binary, 'shared') |
| 138 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 139 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 140 | binary.tasks.withType(CppCompile) { |
| 141 | if (!(binary.toolChain in VisualCpp)) { |
| 142 | cppCompiler.args "-Wno-error=deprecated-declarations" |
| 143 | } |
| 144 | } |
| 145 | if (binary.targetPlatform.architecture.name != 'athena') { |
| 146 | lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared' |
| 147 | lib project: ':simulation:halsim_adx_gyro_accelerometer', library: 'halsim_adx_gyro_accelerometer', linkage: 'shared' |
| 148 | lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared' |
| 149 | lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared' |
| 150 | } |
| 151 | } |
| 152 | sources { |
| 153 | cpp { |
| 154 | source { |
| 155 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp" |
| 156 | include '**/*.cpp' |
| 157 | } |
| 158 | exportedHeaders { |
| 159 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/include" |
| 160 | include '**/*.h' |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | tasks { |
| 168 | def b = $.binaries |
| 169 | b.each { binary-> |
| 170 | if (binary in NativeExecutableBinarySpec) { |
| 171 | def installDir = binary.tasks.install.installDirectory.get().toString() + File.separatorChar |
| 172 | def runFile = binary.tasks.install.runScriptFile.get().asFile.toString() |
| 173 | |
| 174 | binary.tasks.install.doLast { |
| 175 | if (binary.targetPlatform.operatingSystem.isWindows()) { |
| 176 | // Windows batch scripts |
| 177 | def fileName = binary.component.name + 'LowFi.bat' |
| 178 | def file = new File(installDir + fileName) |
| 179 | file.withWriter { out -> |
| 180 | out.println '@ECHO OFF' |
| 181 | out.print 'SET HALSIM_EXTENSIONS=' |
| 182 | out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";' |
| 183 | out.println '"' + new File(installDir + 'lib\\halsim_ds_nt.dll').toString() + '"' |
| 184 | out.println runFile + ' %*' |
| 185 | } |
| 186 | |
| 187 | fileName = binary.component.name + 'LowFiRealDS.bat' |
| 188 | file = new File(installDir + fileName) |
| 189 | file.withWriter { out -> |
| 190 | out.println '@ECHO OFF' |
| 191 | out.print 'SET HALSIM_EXTENSIONS=' |
| 192 | out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";' |
| 193 | out.println '"' + new File(installDir + 'lib\\halsim_ds_socket.dll').toString() + '"' |
| 194 | out.println runFile + ' %*' |
| 195 | } |
| 196 | } else { |
| 197 | def fileName = binary.component.name + 'LowFi.sh' |
| 198 | def file = new File(installDir + fileName) |
| 199 | |
| 200 | file.withWriter { out -> |
| 201 | out.print 'export HALSIM_EXTENSIONS=' |
| 202 | out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '";' |
| 203 | out.println '"' + new File(installDir + '/lib/libhalsim_ds_nt.so').toString() + '"' |
| 204 | out.println runFile + ' "$@"' |
| 205 | } |
| 206 | |
| 207 | fileName = binary.component.name + 'LowFiRealDS.sh' |
| 208 | file = new File(installDir + fileName) |
| 209 | file.withWriter { out -> |
| 210 | out.print 'export HALSIM_EXTENSIONS=' |
| 211 | out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '":' |
| 212 | out.println '"' + new File(installDir + '/lib/libhalsim_ds_socket.so').toString() + '"' |
| 213 | out.println runFile + ' "$@"' |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | apply from: 'publish.gradle' |
| 223 | |
| 224 | ext { |
| 225 | templateDirectory = new File("$projectDir/src/main/cpp/templates/") |
| 226 | templateFile = new File("$projectDir/src/main/cpp/templates/templates.json") |
| 227 | exampleDirectory = new File("$projectDir/src/main/cpp/examples/") |
| 228 | exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json") |
| 229 | commandDirectory = new File("$projectDir/src/main/cpp/commands/") |
| 230 | commandFile = new File("$projectDir/src/main/cpp/commands/commands.json") |
| 231 | } |
| 232 | |
| 233 | apply from: "${rootDir}/shared/examplecheck.gradle" |