blob: c6c1dfff3cf80b8509d0dae076f44ad1b1481717 [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
James Kuszmaul397f6fe2020-01-04 16:21:52 -08009evaluationDependsOn(':hal')
10
Brian Silverman41cdd3e2019-01-19 19:48:58 -080011apply from: '../shared/config.gradle'
12
13ext.examplesMap = [:]
14ext.templatesMap = [:]
15
16File examplesTree = file("$projectDir/src/main/cpp/examples")
17examplesTree.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}
25File templatesTree = file("$projectDir/src/main/cpp/templates")
26templatesTree.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
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -080035nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
36 cppCompiler.args.remove('-Wno-error=deprecated-declarations')
37 cppCompiler.args.add('-Werror=deprecated-declarations')
38}
Brian Silverman41cdd3e2019-01-19 19:48:58 -080039
40ext {
41 sharedCvConfigs = examplesMap + templatesMap + [commands: []]
42 staticCvConfigs = [:]
43 useJava = false
44 useCpp = true
45}
46
47apply from: "${rootDir}/shared/opencv.gradle"
48
Brian Silverman41cdd3e2019-01-19 19:48:58 -080049model {
50 components {
51 commands(NativeLibrarySpec) {
52 binaries.all { binary ->
53 if (binary in StaticLibraryBinarySpec) {
54 binary.buildable = false
55 return
56 }
James Kuszmaul4b81d302019-12-14 20:53:14 -080057 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
58 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -080059 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
60 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
61 lib project: ':cscore', library: 'cscore', linkage: 'shared'
62 project(':hal').addHalDependency(binary, 'shared')
63 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
64 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
65 }
66 sources {
67 cpp {
68 source {
69 srcDirs = ['src/main/cpp/commands']
70 include '**/*.cpp'
71 }
72 exportedHeaders {
73 srcDirs 'src/main/cpp/commands'
74 include '**/*.h'
75 }
76 }
77 }
78 }
79
80 examplesMap.each { key, value ->
81 "${key}"(NativeExecutableSpec) {
82 targetBuildTypes 'debug'
83 binaries.all { binary ->
James Kuszmaul4b81d302019-12-14 20:53:14 -080084 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
85 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -080086 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
87 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
88 lib project: ':cscore', library: 'cscore', linkage: 'shared'
89 project(':hal').addHalDependency(binary, 'shared')
90 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
91 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -080092 if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) {
Brian Silverman41cdd3e2019-01-19 19:48:58 -080093 lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -080094 lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared'
95 lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared'
96 }
James Kuszmaul4b81d302019-12-14 20:53:14 -080097 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
98 nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
99 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800100 }
101 sources {
102 cpp {
103 source {
104 srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp"
105 include '**/*.cpp'
106 }
107 exportedHeaders {
108 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
109 include '**/*.h'
110 }
111 }
112 }
113 sources {
114 c {
115 source {
116 srcDirs 'src/main/cpp/examples/' + "${key}" + "/c"
117 include '**/*.c'
118 }
119 exportedHeaders {
120 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
121 include '**/*.h'
122 }
123 }
124 }
125 }
126 }
127 templatesMap.each { key, value ->
128 "${key}"(NativeExecutableSpec) {
129 targetBuildTypes 'debug'
130 binaries.all { binary ->
James Kuszmaul4b81d302019-12-14 20:53:14 -0800131 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
132 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800133 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
134 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
135 lib project: ':cscore', library: 'cscore', linkage: 'shared'
136 project(':hal').addHalDependency(binary, 'shared')
137 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
138 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
139 binary.tasks.withType(CppCompile) {
140 if (!(binary.toolChain in VisualCpp)) {
141 cppCompiler.args "-Wno-error=deprecated-declarations"
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800142 } else {
143 cppCompiler.args "/wd4996"
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800144 }
145 }
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800146 if (binary.targetPlatform.name != nativeUtils.wpi.platforms.roborio) {
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800147 lib project: ':simulation:halsim_lowfi', library: 'halsim_lowfi', linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800148 lib project: ':simulation:halsim_print', library: 'halsim_print', linkage: 'shared'
149 lib project: ':simulation:halsim_ds_nt', library: 'halsim_ds_nt', linkage: 'shared'
150 }
James Kuszmaul4b81d302019-12-14 20:53:14 -0800151 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
152 nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
153 }
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800154 }
155 sources {
156 cpp {
157 source {
158 srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp"
159 include '**/*.cpp'
160 }
161 exportedHeaders {
162 srcDirs 'src/main/cpp/templates/' + "${key}" + "/include"
163 include '**/*.h'
164 }
165 }
166 }
167 }
168 }
169 }
170 tasks {
171 def b = $.binaries
172 b.each { binary->
173 if (binary in NativeExecutableBinarySpec) {
174 def installDir = binary.tasks.install.installDirectory.get().toString() + File.separatorChar
175 def runFile = binary.tasks.install.runScriptFile.get().asFile.toString()
176
177 binary.tasks.install.doLast {
178 if (binary.targetPlatform.operatingSystem.isWindows()) {
179 // Windows batch scripts
180 def fileName = binary.component.name + 'LowFi.bat'
181 def file = new File(installDir + fileName)
182 file.withWriter { out ->
183 out.println '@ECHO OFF'
184 out.print 'SET HALSIM_EXTENSIONS='
185 out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";'
186 out.println '"' + new File(installDir + 'lib\\halsim_ds_nt.dll').toString() + '"'
187 out.println runFile + ' %*'
188 }
189
190 fileName = binary.component.name + 'LowFiRealDS.bat'
191 file = new File(installDir + fileName)
192 file.withWriter { out ->
193 out.println '@ECHO OFF'
194 out.print 'SET HALSIM_EXTENSIONS='
195 out.print '"' + new File(installDir + 'lib\\halsim_lowfi.dll').toString() + '";'
196 out.println '"' + new File(installDir + 'lib\\halsim_ds_socket.dll').toString() + '"'
197 out.println runFile + ' %*'
198 }
199 } else {
200 def fileName = binary.component.name + 'LowFi.sh'
201 def file = new File(installDir + fileName)
202
203 file.withWriter { out ->
204 out.print 'export HALSIM_EXTENSIONS='
205 out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '";'
206 out.println '"' + new File(installDir + '/lib/libhalsim_ds_nt.so').toString() + '"'
207 out.println runFile + ' "$@"'
208 }
209
210 fileName = binary.component.name + 'LowFiRealDS.sh'
211 file = new File(installDir + fileName)
212 file.withWriter { out ->
213 out.print 'export HALSIM_EXTENSIONS='
214 out.print '"' + new File(installDir + '/lib/libhalsim_lowfi.so').toString() + '":'
215 out.println '"' + new File(installDir + '/lib/libhalsim_ds_socket.so').toString() + '"'
216 out.println runFile + ' "$@"'
217 }
218 }
219 }
220
221 }
222 }
223 }
224}
225apply from: 'publish.gradle'
226
James Kuszmaul397f6fe2020-01-04 16:21:52 -0800227model {
228 tasks {
229 def c = $.components
230 project.tasks.register('buildDesktopCpp') { compileTask->
231 def systemArch = getCurrentArch()
232 c.each {
233 if (it in NativeExecutableSpec && it.name) {
234 it.binaries.each {
235 def arch = it.targetPlatform.name
236 if (arch == systemArch && it.buildType.name == 'debug') {
237 compileTask.dependsOn it.tasks.link
238 }
239 }
240 }
241 }
242 }
243 }
244}
245
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800246ext {
247 templateDirectory = new File("$projectDir/src/main/cpp/templates/")
248 templateFile = new File("$projectDir/src/main/cpp/templates/templates.json")
249 exampleDirectory = new File("$projectDir/src/main/cpp/examples/")
250 exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json")
251 commandDirectory = new File("$projectDir/src/main/cpp/commands/")
252 commandFile = new File("$projectDir/src/main/cpp/commands/commands.json")
253}
254
James Kuszmaul4b81d302019-12-14 20:53:14 -0800255ext {
256 isCppCommands = true
257}
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800258apply from: "${rootDir}/shared/examplecheck.gradle"