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 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 47 | model { |
| 48 | components { |
| 49 | commands(NativeLibrarySpec) { |
| 50 | binaries.all { binary -> |
| 51 | if (binary in StaticLibraryBinarySpec) { |
| 52 | binary.buildable = false |
| 53 | return |
| 54 | } |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame^] | 55 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 56 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 57 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 58 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 59 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 60 | project(':hal').addHalDependency(binary, 'shared') |
| 61 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 62 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 63 | } |
| 64 | sources { |
| 65 | cpp { |
| 66 | source { |
| 67 | srcDirs = ['src/main/cpp/commands'] |
| 68 | include '**/*.cpp' |
| 69 | } |
| 70 | exportedHeaders { |
| 71 | srcDirs 'src/main/cpp/commands' |
| 72 | include '**/*.h' |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | examplesMap.each { key, value -> |
| 79 | "${key}"(NativeExecutableSpec) { |
| 80 | targetBuildTypes 'debug' |
| 81 | binaries.all { binary -> |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame^] | 82 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 83 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 84 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 85 | lib project: ':ntcore', library: 'ntcore', linkage: 'shared' |
| 86 | lib project: ':cscore', library: 'cscore', linkage: 'shared' |
| 87 | project(':hal').addHalDependency(binary, 'shared') |
| 88 | lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared' |
| 89 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 90 | if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) { |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 91 | lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared' |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 92 | lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared' |
| 93 | lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared' |
| 94 | } |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame^] | 95 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 96 | nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared') |
| 97 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 98 | } |
| 99 | sources { |
| 100 | cpp { |
| 101 | source { |
| 102 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp" |
| 103 | include '**/*.cpp' |
| 104 | } |
| 105 | exportedHeaders { |
| 106 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 107 | include '**/*.h' |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | sources { |
| 112 | c { |
| 113 | source { |
| 114 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/c" |
| 115 | include '**/*.c' |
| 116 | } |
| 117 | exportedHeaders { |
| 118 | srcDirs 'src/main/cpp/examples/' + "${key}" + "/include" |
| 119 | include '**/*.h' |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | templatesMap.each { key, value -> |
| 126 | "${key}"(NativeExecutableSpec) { |
| 127 | targetBuildTypes 'debug' |
| 128 | binaries.all { binary -> |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame^] | 129 | lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared' |
| 130 | lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared' |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 131 | lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared' |
| 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" |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 140 | } else { |
| 141 | cppCompiler.args "/wd4996" |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 142 | } |
| 143 | } |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 144 | if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) { |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 145 | lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared' |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 146 | lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared' |
| 147 | lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared' |
| 148 | } |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame^] | 149 | if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 150 | nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared') |
| 151 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 152 | } |
| 153 | sources { |
| 154 | cpp { |
| 155 | source { |
| 156 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp" |
| 157 | include '**/*.cpp' |
| 158 | } |
| 159 | exportedHeaders { |
| 160 | srcDirs 'src/main/cpp/templates/' + "${key}" + "/include" |
| 161 | include '**/*.h' |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | tasks { |
| 169 | def b = $.binaries |
| 170 | b.each { binary-> |
| 171 | if (binary in NativeExecutableBinarySpec) { |
| 172 | def installDir = binary.tasks.install.installDirectory.get().toString() + File.separatorChar |
| 173 | def runFile = binary.tasks.install.runScriptFile.get().asFile.toString() |
| 174 | |
| 175 | binary.tasks.install.doLast { |
| 176 | if (binary.targetPlatform.operatingSystem.isWindows()) { |
| 177 | // Windows batch scripts |
| 178 | def fileName = binary.component.name + 'LowFi.bat' |
| 179 | def file = new File(installDir + fileName) |
| 180 | file.withWriter { out -> |
| 181 | out.println '@ECHO OFF' |
| 182 | out.print 'SET HALSIM_EXTENSIONS=' |
| 183 | out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";' |
| 184 | out.println '"' + new File(installDir + 'lib\\halsim_ds_nt.dll').toString() + '"' |
| 185 | out.println runFile + ' %*' |
| 186 | } |
| 187 | |
| 188 | fileName = binary.component.name + 'LowFiRealDS.bat' |
| 189 | file = new File(installDir + fileName) |
| 190 | file.withWriter { out -> |
| 191 | out.println '@ECHO OFF' |
| 192 | out.print 'SET HALSIM_EXTENSIONS=' |
| 193 | out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";' |
| 194 | out.println '"' + new File(installDir + 'lib\\halsim_ds_socket.dll').toString() + '"' |
| 195 | out.println runFile + ' %*' |
| 196 | } |
| 197 | } else { |
| 198 | def fileName = binary.component.name + 'LowFi.sh' |
| 199 | def file = new File(installDir + fileName) |
| 200 | |
| 201 | file.withWriter { out -> |
| 202 | out.print 'export HALSIM_EXTENSIONS=' |
| 203 | out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '";' |
| 204 | out.println '"' + new File(installDir + '/lib/libhalsim_ds_nt.so').toString() + '"' |
| 205 | out.println runFile + ' "$@"' |
| 206 | } |
| 207 | |
| 208 | fileName = binary.component.name + 'LowFiRealDS.sh' |
| 209 | file = new File(installDir + fileName) |
| 210 | file.withWriter { out -> |
| 211 | out.print 'export HALSIM_EXTENSIONS=' |
| 212 | out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '":' |
| 213 | out.println '"' + new File(installDir + '/lib/libhalsim_ds_socket.so').toString() + '"' |
| 214 | out.println runFile + ' "$@"' |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | apply from: 'publish.gradle' |
| 224 | |
| 225 | ext { |
| 226 | templateDirectory = new File("$projectDir/src/main/cpp/templates/") |
| 227 | templateFile = new File("$projectDir/src/main/cpp/templates/templates.json") |
| 228 | exampleDirectory = new File("$projectDir/src/main/cpp/examples/") |
| 229 | exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json") |
| 230 | commandDirectory = new File("$projectDir/src/main/cpp/commands/") |
| 231 | commandFile = new File("$projectDir/src/main/cpp/commands/commands.json") |
| 232 | } |
| 233 | |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame^] | 234 | ext { |
| 235 | isCppCommands = true |
| 236 | } |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 237 | apply from: "${rootDir}/shared/examplecheck.gradle" |