blob: 7561ed5e53adcdf6a7bcf6e947db0c267792b17d [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001import org.gradle.language.base.internal.ProjectLayout
2
3apply plugin: 'cpp'
4apply plugin: 'c'
Austin Schuh812d0d12021-11-04 20:16:48 -07005apply plugin: 'google-test-test-suite'
Brian Silverman8fce7482020-01-05 13:18:21 -08006apply plugin: 'visual-studio'
7apply plugin: 'edu.wpi.first.NativeUtils'
8apply plugin: ExtraTasks
9
10evaluationDependsOn(':hal')
11
12apply from: '../shared/config.gradle'
Austin Schuh812d0d12021-11-04 20:16:48 -070013apply from: "${rootDir}/shared/googletest.gradle"
Brian Silverman8fce7482020-01-05 13:18:21 -080014
15ext.examplesMap = [:]
16ext.templatesMap = [:]
17
18File examplesTree = file("$projectDir/src/main/cpp/examples")
19examplesTree.list(new FilenameFilter() {
Austin Schuh812d0d12021-11-04 20:16:48 -070020 @Override
21 public boolean accept(File current, String name) {
22 return new File(current, name).isDirectory();
23 }
24 }).each {
25 examplesMap.put(it, [])
26 }
Brian Silverman8fce7482020-01-05 13:18:21 -080027File templatesTree = file("$projectDir/src/main/cpp/templates")
28templatesTree.list(new FilenameFilter() {
Austin Schuh812d0d12021-11-04 20:16:48 -070029 @Override
30 public boolean accept(File current, String name) {
31 return new File(current, name).isDirectory();
32 }
33 }).each {
34 templatesMap.put(it, [])
35 }
Brian Silverman8fce7482020-01-05 13:18:21 -080036
37nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
38 cppCompiler.args.remove('-Wno-error=deprecated-declarations')
39 cppCompiler.args.add('-Werror=deprecated-declarations')
40}
41
Austin Schuh75263e32022-02-22 18:05:32 -080042nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.windowsx64).configure {
43 linker.args.remove('/DEBUG:FULL')
44 cppCompiler.debugArgs.remove('/Zi')
45 cCompiler.debugArgs.remove('/Zi')
46}
47
Brian Silverman8fce7482020-01-05 13:18:21 -080048ext {
49 sharedCvConfigs = examplesMap + templatesMap + [commands: []]
50 staticCvConfigs = [:]
51 useJava = false
52 useCpp = true
53}
54
Austin Schuh812d0d12021-11-04 20:16:48 -070055def simModules = ["halsim_gui"]
56
Brian Silverman8fce7482020-01-05 13:18:21 -080057apply from: "${rootDir}/shared/opencv.gradle"
58
59model {
60 components {
61 commands(NativeLibrarySpec) {
62 binaries.all { binary ->
63 if (binary in StaticLibraryBinarySpec) {
64 binary.buildable = false
65 return
66 }
67 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
68 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
69 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080070 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080071 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 ->
Brian Silverman8fce7482020-01-05 13:18:21 -080095 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
96 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080097 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080098 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
99 lib project: ':cscore', library: 'cscore', linkage: 'shared'
100 project(':hal').addHalDependency(binary, 'shared')
101 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
102 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800103 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700104 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
105 }
106 if (binary.targetPlatform.name == getCurrentArch()) {
107 simModules.each {
108 lib project: ":simulation:$it", library: it, linkage: 'shared'
109 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800110 }
111 }
112 sources {
113 cpp {
114 source {
115 srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp"
116 include '**/*.cpp'
117 }
118 exportedHeaders {
119 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
120 include '**/*.h'
121 }
122 }
123 }
124 sources {
125 c {
126 source {
127 srcDirs 'src/main/cpp/examples/' + "${key}" + "/c"
128 include '**/*.c'
129 }
130 exportedHeaders {
131 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
132 include '**/*.h'
133 }
134 }
135 }
136 }
137 }
138 templatesMap.each { key, value ->
139 "${key}"(NativeExecutableSpec) {
140 targetBuildTypes 'debug'
141 binaries.all { binary ->
Brian Silverman8fce7482020-01-05 13:18:21 -0800142 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
143 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800144 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800145 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
146 lib project: ':cscore', library: 'cscore', linkage: 'shared'
147 project(':hal').addHalDependency(binary, 'shared')
148 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
149 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
150 binary.tasks.withType(CppCompile) {
151 if (!(binary.toolChain in VisualCpp)) {
152 cppCompiler.args "-Wno-error=deprecated-declarations"
153 } else {
154 cppCompiler.args "/wd4996"
155 }
156 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800157 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700158 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800159 }
160 }
161 sources {
162 cpp {
163 source {
164 srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp"
165 include '**/*.cpp'
166 }
167 exportedHeaders {
168 srcDirs 'src/main/cpp/templates/' + "${key}" + "/include"
169 include '**/*.h'
170 }
171 }
172 }
173 }
174 }
175 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700176 testSuites {
177 examplesMap.each { key, value ->
178 def testFolder = new File("${rootDir}/wpilibcExamples/src/test/cpp/examples/${key}")
179 if (testFolder.exists()) {
180 "${key}Test"(GoogleTestTestSuiteSpec) {
181 for (NativeComponentSpec c : $.components) {
182 if (c.name == key) {
183 testing c
184 break
Brian Silverman8fce7482020-01-05 13:18:21 -0800185 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700186 }
187 sources {
188 cpp {
189 source {
190 srcDirs "src/test/cpp/examples/${key}/cpp"
191 include '**/*.cpp'
192 }
193 exportedHeaders {
194 srcDirs "src/test/cpp/examples/${key}/include"
195 }
196 }
197 c {
198 source {
199 srcDirs "src/test/cpp/examples/${key}/c"
200 include '**/*.c'
201 }
202 exportedHeaders {
203 srcDirs "src/test/cpp/examples/${key}/include"
204 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800205 }
206 }
207 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800208 }
209 }
210 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700211 binaries {
212 withType(GoogleTestTestSuiteBinarySpec) {
213 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
214 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
215 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
216 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
217 lib project: ':cscore', library: 'cscore', linkage: 'shared'
218 project(':hal').addHalDependency(it, 'shared')
219 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
220 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
221 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
222 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
223 }
224 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
225
226 it.cppCompiler.define('RUNNING_FRC_TESTS')
227 it.cCompiler.define('RUNNING_FRC_TESTS')
228 }
229 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800230}
Austin Schuh812d0d12021-11-04 20:16:48 -0700231
Brian Silverman8fce7482020-01-05 13:18:21 -0800232apply from: 'publish.gradle'
233
234model {
235 tasks {
236 def c = $.components
237 project.tasks.register('buildDesktopCpp') { compileTask->
238 def systemArch = getCurrentArch()
239 c.each {
240 if (it in NativeExecutableSpec && it.name) {
241 it.binaries.each {
242 def arch = it.targetPlatform.name
243 if (arch == systemArch && it.buildType.name == 'debug') {
244 compileTask.dependsOn it.tasks.link
245 }
246 }
247 }
248 }
249 }
250 }
251}
252
253ext {
254 templateDirectory = new File("$projectDir/src/main/cpp/templates/")
255 templateFile = new File("$projectDir/src/main/cpp/templates/templates.json")
256 exampleDirectory = new File("$projectDir/src/main/cpp/examples/")
257 exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json")
258 commandDirectory = new File("$projectDir/src/main/cpp/commands/")
259 commandFile = new File("$projectDir/src/main/cpp/commands/commands.json")
260}
261
Austin Schuh812d0d12021-11-04 20:16:48 -0700262model {
263 // Create run tasks for all examples.
264 tasks {
265 // Iterate through the components and check if it is an example.
266 $.components.each { component ->
267 if (examplesMap.containsKey(component.name)) {
268 // Get the appropriate binary and create the run task.
269 component.binaries.each { binary ->
270 if (binary.targetPlatform.name == getCurrentArch() && binary.buildType.name == "debug") {
271 project.tasks.create("run${component.name}", Exec) {
272 // Add simulation modules to HALSIM_EXTENSIONS environment variable.
273 def setupEnv = {
274 String extensions = ""
275 binary.tasks.install.installDirectory.get().getAsFile().eachFileRecurse {
276 def name = it.name
277
278 // If we don't have a shared library, skip.
279 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib')))
280 return
281
282 def file = it
283 simModules.each {
284 if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
285 extensions += file.absolutePath + File.pathSeparator
286 }
287 }
288 }
289
290 if (extensions != '') {
291 environment 'HALSIM_EXTENSIONS', extensions
292 }
293 }
294
295 // Create the task dependency and run the executable.
296 doFirst { setupEnv() }
297 dependsOn binary.tasks.install
298 commandLine binary.tasks.install.runScriptFile.get().asFile.toString()
299
300 group = "application"
301 }
302 }
303 }
304 }
305 }
306 }
307}
308
309
Brian Silverman8fce7482020-01-05 13:18:21 -0800310ext {
311 isCppCommands = true
312}
313apply from: "${rootDir}/shared/examplecheck.gradle"