blob: 975e90ae709ab314aa8d7970a0b1bf93b258ef86 [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
42ext {
43 sharedCvConfigs = examplesMap + templatesMap + [commands: []]
44 staticCvConfigs = [:]
45 useJava = false
46 useCpp = true
47}
48
Austin Schuh812d0d12021-11-04 20:16:48 -070049def simModules = ["halsim_gui"]
50
Brian Silverman8fce7482020-01-05 13:18:21 -080051apply from: "${rootDir}/shared/opencv.gradle"
52
53model {
54 components {
55 commands(NativeLibrarySpec) {
56 binaries.all { binary ->
57 if (binary in StaticLibraryBinarySpec) {
58 binary.buildable = false
59 return
60 }
61 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
62 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
63 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080064 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080065 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
66 lib project: ':cscore', library: 'cscore', linkage: 'shared'
67 project(':hal').addHalDependency(binary, 'shared')
68 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
69 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
70 }
71 sources {
72 cpp {
73 source {
74 srcDirs = ['src/main/cpp/commands']
75 include '**/*.cpp'
76 }
77 exportedHeaders {
78 srcDirs 'src/main/cpp/commands'
79 include '**/*.h'
80 }
81 }
82 }
83 }
84
85 examplesMap.each { key, value ->
86 "${key}"(NativeExecutableSpec) {
87 targetBuildTypes 'debug'
88 binaries.all { binary ->
Brian Silverman8fce7482020-01-05 13:18:21 -080089 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
90 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080091 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080092 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'
Brian Silverman8fce7482020-01-05 13:18:21 -080097 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -070098 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
99 }
100 if (binary.targetPlatform.name == getCurrentArch()) {
101 simModules.each {
102 lib project: ":simulation:$it", library: it, linkage: 'shared'
103 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800104 }
105 }
106 sources {
107 cpp {
108 source {
109 srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp"
110 include '**/*.cpp'
111 }
112 exportedHeaders {
113 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
114 include '**/*.h'
115 }
116 }
117 }
118 sources {
119 c {
120 source {
121 srcDirs 'src/main/cpp/examples/' + "${key}" + "/c"
122 include '**/*.c'
123 }
124 exportedHeaders {
125 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
126 include '**/*.h'
127 }
128 }
129 }
130 }
131 }
132 templatesMap.each { key, value ->
133 "${key}"(NativeExecutableSpec) {
134 targetBuildTypes 'debug'
135 binaries.all { binary ->
Brian Silverman8fce7482020-01-05 13:18:21 -0800136 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
137 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800138 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800139 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
140 lib project: ':cscore', library: 'cscore', linkage: 'shared'
141 project(':hal').addHalDependency(binary, 'shared')
142 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
143 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
144 binary.tasks.withType(CppCompile) {
145 if (!(binary.toolChain in VisualCpp)) {
146 cppCompiler.args "-Wno-error=deprecated-declarations"
147 } else {
148 cppCompiler.args "/wd4996"
149 }
150 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800151 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700152 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800153 }
154 }
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 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700170 testSuites {
171 examplesMap.each { key, value ->
172 def testFolder = new File("${rootDir}/wpilibcExamples/src/test/cpp/examples/${key}")
173 if (testFolder.exists()) {
174 "${key}Test"(GoogleTestTestSuiteSpec) {
175 for (NativeComponentSpec c : $.components) {
176 if (c.name == key) {
177 testing c
178 break
Brian Silverman8fce7482020-01-05 13:18:21 -0800179 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700180 }
181 sources {
182 cpp {
183 source {
184 srcDirs "src/test/cpp/examples/${key}/cpp"
185 include '**/*.cpp'
186 }
187 exportedHeaders {
188 srcDirs "src/test/cpp/examples/${key}/include"
189 }
190 }
191 c {
192 source {
193 srcDirs "src/test/cpp/examples/${key}/c"
194 include '**/*.c'
195 }
196 exportedHeaders {
197 srcDirs "src/test/cpp/examples/${key}/include"
198 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800199 }
200 }
201 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800202 }
203 }
204 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700205 binaries {
206 withType(GoogleTestTestSuiteBinarySpec) {
207 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
208 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
209 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
210 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
211 lib project: ':cscore', library: 'cscore', linkage: 'shared'
212 project(':hal').addHalDependency(it, 'shared')
213 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
214 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
215 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
216 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
217 }
218 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
219
220 it.cppCompiler.define('RUNNING_FRC_TESTS')
221 it.cCompiler.define('RUNNING_FRC_TESTS')
222 }
223 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800224}
Austin Schuh812d0d12021-11-04 20:16:48 -0700225
Brian Silverman8fce7482020-01-05 13:18:21 -0800226apply from: 'publish.gradle'
227
228model {
229 tasks {
230 def c = $.components
231 project.tasks.register('buildDesktopCpp') { compileTask->
232 def systemArch = getCurrentArch()
233 c.each {
234 if (it in NativeExecutableSpec && it.name) {
235 it.binaries.each {
236 def arch = it.targetPlatform.name
237 if (arch == systemArch && it.buildType.name == 'debug') {
238 compileTask.dependsOn it.tasks.link
239 }
240 }
241 }
242 }
243 }
244 }
245}
246
247ext {
248 templateDirectory = new File("$projectDir/src/main/cpp/templates/")
249 templateFile = new File("$projectDir/src/main/cpp/templates/templates.json")
250 exampleDirectory = new File("$projectDir/src/main/cpp/examples/")
251 exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json")
252 commandDirectory = new File("$projectDir/src/main/cpp/commands/")
253 commandFile = new File("$projectDir/src/main/cpp/commands/commands.json")
254}
255
Austin Schuh812d0d12021-11-04 20:16:48 -0700256model {
257 // Create run tasks for all examples.
258 tasks {
259 // Iterate through the components and check if it is an example.
260 $.components.each { component ->
261 if (examplesMap.containsKey(component.name)) {
262 // Get the appropriate binary and create the run task.
263 component.binaries.each { binary ->
264 if (binary.targetPlatform.name == getCurrentArch() && binary.buildType.name == "debug") {
265 project.tasks.create("run${component.name}", Exec) {
266 // Add simulation modules to HALSIM_EXTENSIONS environment variable.
267 def setupEnv = {
268 String extensions = ""
269 binary.tasks.install.installDirectory.get().getAsFile().eachFileRecurse {
270 def name = it.name
271
272 // If we don't have a shared library, skip.
273 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib')))
274 return
275
276 def file = it
277 simModules.each {
278 if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
279 extensions += file.absolutePath + File.pathSeparator
280 }
281 }
282 }
283
284 if (extensions != '') {
285 environment 'HALSIM_EXTENSIONS', extensions
286 }
287 }
288
289 // Create the task dependency and run the executable.
290 doFirst { setupEnv() }
291 dependsOn binary.tasks.install
292 commandLine binary.tasks.install.runScriptFile.get().asFile.toString()
293
294 group = "application"
295 }
296 }
297 }
298 }
299 }
300 }
301}
302
303
Brian Silverman8fce7482020-01-05 13:18:21 -0800304ext {
305 isCppCommands = true
306}
307apply from: "${rootDir}/shared/examplecheck.gradle"