blob: eb1aca525138a099d814b73f9d7806ffe4676dd7 [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
Austin Schuh75263e32022-02-22 18:05:32 -080037nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.windowsx64).configure {
38 linker.args.remove('/DEBUG:FULL')
39 cppCompiler.debugArgs.remove('/Zi')
40 cCompiler.debugArgs.remove('/Zi')
41}
42
Brian Silverman8fce7482020-01-05 13:18:21 -080043ext {
44 sharedCvConfigs = examplesMap + templatesMap + [commands: []]
45 staticCvConfigs = [:]
46 useJava = false
47 useCpp = true
48}
49
Austin Schuh812d0d12021-11-04 20:16:48 -070050def simModules = ["halsim_gui"]
51
Brian Silverman8fce7482020-01-05 13:18:21 -080052apply from: "${rootDir}/shared/opencv.gradle"
53
54model {
55 components {
56 commands(NativeLibrarySpec) {
57 binaries.all { binary ->
58 if (binary in StaticLibraryBinarySpec) {
59 binary.buildable = false
60 return
61 }
Brian Silverman8fce7482020-01-05 13:18:21 -080062 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
James Kuszmaulb13e13f2023-11-22 20:44:04 -080063 lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared'
64 lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -080065 lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080066 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080067 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -080068 project(':ntcore').addNtcoreDependency(binary, 'shared')
Brian Silverman8fce7482020-01-05 13:18:21 -080069 lib project: ':cscore', library: 'cscore', linkage: 'shared'
70 project(':hal').addHalDependency(binary, 'shared')
71 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -080072 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080073 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
74 }
75 sources {
76 cpp {
77 source {
78 srcDirs = ['src/main/cpp/commands']
79 include '**/*.cpp'
80 }
81 exportedHeaders {
82 srcDirs 'src/main/cpp/commands'
83 include '**/*.h'
84 }
85 }
86 }
87 }
88
89 examplesMap.each { key, value ->
90 "${key}"(NativeExecutableSpec) {
91 targetBuildTypes 'debug'
92 binaries.all { binary ->
Brian Silverman8fce7482020-01-05 13:18:21 -080093 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
James Kuszmaulb13e13f2023-11-22 20:44:04 -080094 lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared'
95 lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080096 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -080097 lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080098 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -080099 project(':ntcore').addNtcoreDependency(binary, 'shared')
Brian Silverman8fce7482020-01-05 13:18:21 -0800100 lib project: ':cscore', library: 'cscore', linkage: 'shared'
101 project(':hal').addHalDependency(binary, 'shared')
102 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800103 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800104 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800105 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700106 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
107 }
108 if (binary.targetPlatform.name == getCurrentArch()) {
109 simModules.each {
110 lib project: ":simulation:$it", library: it, linkage: 'shared'
111 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800112 }
113 }
114 sources {
115 cpp {
116 source {
117 srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp"
118 include '**/*.cpp'
119 }
120 exportedHeaders {
121 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
122 include '**/*.h'
123 }
124 }
125 }
126 sources {
127 c {
128 source {
129 srcDirs 'src/main/cpp/examples/' + "${key}" + "/c"
130 include '**/*.c'
131 }
132 exportedHeaders {
133 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
134 include '**/*.h'
135 }
136 }
137 }
138 }
139 }
140 templatesMap.each { key, value ->
141 "${key}"(NativeExecutableSpec) {
142 targetBuildTypes 'debug'
143 binaries.all { binary ->
Brian Silverman8fce7482020-01-05 13:18:21 -0800144 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800145 lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared'
146 lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800147 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800148 lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800149 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800150 project(':ntcore').addNtcoreDependency(binary, 'shared')
Brian Silverman8fce7482020-01-05 13:18:21 -0800151 lib project: ':cscore', library: 'cscore', linkage: 'shared'
152 project(':hal').addHalDependency(binary, 'shared')
153 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800154 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800155 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800156 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700157 nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800158 }
159 }
160 sources {
161 cpp {
162 source {
163 srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp"
164 include '**/*.cpp'
165 }
166 exportedHeaders {
167 srcDirs 'src/main/cpp/templates/' + "${key}" + "/include"
168 include '**/*.h'
169 }
170 }
171 }
172 }
173 }
174 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700175 testSuites {
176 examplesMap.each { key, value ->
177 def testFolder = new File("${rootDir}/wpilibcExamples/src/test/cpp/examples/${key}")
178 if (testFolder.exists()) {
179 "${key}Test"(GoogleTestTestSuiteSpec) {
180 for (NativeComponentSpec c : $.components) {
181 if (c.name == key) {
182 testing c
183 break
Brian Silverman8fce7482020-01-05 13:18:21 -0800184 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700185 }
186 sources {
187 cpp {
188 source {
189 srcDirs "src/test/cpp/examples/${key}/cpp"
190 include '**/*.cpp'
191 }
192 exportedHeaders {
193 srcDirs "src/test/cpp/examples/${key}/include"
194 }
195 }
196 c {
197 source {
198 srcDirs "src/test/cpp/examples/${key}/c"
199 include '**/*.c'
200 }
201 exportedHeaders {
202 srcDirs "src/test/cpp/examples/${key}/include"
203 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800204 }
205 }
206 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800207 }
208 }
209 }
Austin Schuh812d0d12021-11-04 20:16:48 -0700210 binaries {
211 withType(GoogleTestTestSuiteBinarySpec) {
212 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800213 lib project: ':romiVendordep', library: 'romiVendordep', linkage: 'shared'
214 lib project: ':xrpVendordep', library: 'xrpVendordep', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700215 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800216 lib project: ':apriltag', library: 'apriltag', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700217 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800218 project(':ntcore').addNtcoreDependency(it, 'shared')
Austin Schuh812d0d12021-11-04 20:16:48 -0700219 lib project: ':cscore', library: 'cscore', linkage: 'shared'
220 project(':hal').addHalDependency(it, 'shared')
221 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
James Kuszmaulcf324122023-01-14 14:07:17 -0800222 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Austin Schuh812d0d12021-11-04 20:16:48 -0700223 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
224 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
225 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
226 }
227 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
228
229 it.cppCompiler.define('RUNNING_FRC_TESTS')
230 it.cCompiler.define('RUNNING_FRC_TESTS')
231 }
232 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800233}
Austin Schuh812d0d12021-11-04 20:16:48 -0700234
Brian Silverman8fce7482020-01-05 13:18:21 -0800235apply from: 'publish.gradle'
236
237model {
238 tasks {
239 def c = $.components
240 project.tasks.register('buildDesktopCpp') { compileTask->
241 def systemArch = getCurrentArch()
242 c.each {
243 if (it in NativeExecutableSpec && it.name) {
244 it.binaries.each {
245 def arch = it.targetPlatform.name
246 if (arch == systemArch && it.buildType.name == 'debug') {
247 compileTask.dependsOn it.tasks.link
248 }
249 }
250 }
251 }
252 }
253 }
254}
255
256ext {
257 templateDirectory = new File("$projectDir/src/main/cpp/templates/")
258 templateFile = new File("$projectDir/src/main/cpp/templates/templates.json")
259 exampleDirectory = new File("$projectDir/src/main/cpp/examples/")
260 exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json")
261 commandDirectory = new File("$projectDir/src/main/cpp/commands/")
262 commandFile = new File("$projectDir/src/main/cpp/commands/commands.json")
263}
264
Austin Schuh812d0d12021-11-04 20:16:48 -0700265model {
266 // Create run tasks for all examples.
267 tasks {
268 // Iterate through the components and check if it is an example.
269 $.components.each { component ->
270 if (examplesMap.containsKey(component.name)) {
271 // Get the appropriate binary and create the run task.
272 component.binaries.each { binary ->
273 if (binary.targetPlatform.name == getCurrentArch() && binary.buildType.name == "debug") {
274 project.tasks.create("run${component.name}", Exec) {
275 // Add simulation modules to HALSIM_EXTENSIONS environment variable.
276 def setupEnv = {
277 String extensions = ""
278 binary.tasks.install.installDirectory.get().getAsFile().eachFileRecurse {
279 def name = it.name
280
281 // If we don't have a shared library, skip.
282 if (!(name.endsWith('.dll') || name.endsWith('.so') || name.endsWith('.dylib')))
283 return
284
285 def file = it
286 simModules.each {
287 if (name.startsWith(it) || name.startsWith("lib$it".toString())) {
288 extensions += file.absolutePath + File.pathSeparator
289 }
290 }
291 }
292
293 if (extensions != '') {
294 environment 'HALSIM_EXTENSIONS', extensions
295 }
296 }
297
298 // Create the task dependency and run the executable.
299 doFirst { setupEnv() }
300 dependsOn binary.tasks.install
301 commandLine binary.tasks.install.runScriptFile.get().asFile.toString()
302
303 group = "application"
304 }
305 }
306 }
307 }
308 }
309 }
310}
311
312
Brian Silverman8fce7482020-01-05 13:18:21 -0800313ext {
314 isCppCommands = true
315}
316apply from: "${rootDir}/shared/examplecheck.gradle"