blob: 12279df38fc01484b4f736b17e92c4cb7e40b5b1 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001import org.gradle.language.base.internal.ProjectLayout
2
3apply plugin: 'cpp'
4apply plugin: 'c'
5apply plugin: 'visual-studio'
6apply plugin: 'edu.wpi.first.NativeUtils'
7apply plugin: ExtraTasks
8
9apply from: '../shared/config.gradle'
10
11ext.examplesMap = [:]
12ext.templatesMap = [:]
13
14File examplesTree = file("$projectDir/src/main/cpp/examples")
15examplesTree.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}
23File templatesTree = file("$projectDir/src/main/cpp/templates")
24templatesTree.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 Kuszmaul4f3ad3c2019-12-01 16:35:21 -080033nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
34 cppCompiler.args.remove('-Wno-error=deprecated-declarations')
35 cppCompiler.args.add('-Werror=deprecated-declarations')
36}
Brian Silverman41cdd3e2019-01-19 19:48:58 -080037
38ext {
39 sharedCvConfigs = examplesMap + templatesMap + [commands: []]
40 staticCvConfigs = [:]
41 useJava = false
42 useCpp = true
43}
44
45apply from: "${rootDir}/shared/opencv.gradle"
46
Brian Silverman41cdd3e2019-01-19 19:48:58 -080047model {
48 components {
49 commands(NativeLibrarySpec) {
50 binaries.all { binary ->
51 if (binary in StaticLibraryBinarySpec) {
52 binary.buildable = false
53 return
54 }
James Kuszmaul4b81d302019-12-14 20:53:14 -080055 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
56 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -080057 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 Kuszmaul4b81d302019-12-14 20:53:14 -080082 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
83 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -080084 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 Kuszmaul4f3ad3c2019-12-01 16:35:21 -080090 if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) {
Brian Silverman41cdd3e2019-01-19 19:48:58 -080091 lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -080092 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 Kuszmaul4b81d302019-12-14 20:53:14 -080095 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
96 nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
97 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -080098 }
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 Kuszmaul4b81d302019-12-14 20:53:14 -0800129 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
130 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800131 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 Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800140 } else {
141 cppCompiler.args "/wd4996"
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800142 }
143 }
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800144 if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) {
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800145 lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800146 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 Kuszmaul4b81d302019-12-14 20:53:14 -0800149 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
150 nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
151 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800152 }
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}
223apply from: 'publish.gradle'
224
225ext {
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 Kuszmaul4b81d302019-12-14 20:53:14 -0800234ext {
235 isCppCommands = true
236}
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800237apply from: "${rootDir}/shared/examplecheck.gradle"