blob: 35f20d4c48b95beaa4d952215aeec5d6420f07c7 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -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
9evaluationDependsOn(':hal')
10
11apply 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
35nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
36 cppCompiler.args.remove('-Wno-error=deprecated-declarations')
37 cppCompiler.args.add('-Werror=deprecated-declarations')
38}
39
40ext {
41 sharedCvConfigs = examplesMap + templatesMap + [commands: []]
42 staticCvConfigs = [:]
43 useJava = false
44 useCpp = true
45}
46
47apply from: "${rootDir}/shared/opencv.gradle"
48
49model {
50 components {
51 commands(NativeLibrarySpec) {
52 binaries.all { binary ->
53 if (binary in StaticLibraryBinarySpec) {
54 binary.buildable = false
55 return
56 }
57 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
58 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
59 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080060 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080061 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
62 lib project: ':cscore', library: 'cscore', linkage: 'shared'
63 project(':hal').addHalDependency(binary, 'shared')
64 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
65 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
66 }
67 sources {
68 cpp {
69 source {
70 srcDirs = ['src/main/cpp/commands']
71 include '**/*.cpp'
72 }
73 exportedHeaders {
74 srcDirs 'src/main/cpp/commands'
75 include '**/*.h'
76 }
77 }
78 }
79 }
80
81 examplesMap.each { key, value ->
82 "${key}"(NativeExecutableSpec) {
83 targetBuildTypes 'debug'
84 binaries.all { binary ->
85 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
86 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
87 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -080088 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080089 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
90 lib project: ':cscore', library: 'cscore', linkage: 'shared'
91 project(':hal').addHalDependency(binary, 'shared')
92 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
93 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -080094 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
95 nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
96 }
97 }
98 sources {
99 cpp {
100 source {
101 srcDirs 'src/main/cpp/examples/' + "${key}" + "/cpp"
102 include '**/*.cpp'
103 }
104 exportedHeaders {
105 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
106 include '**/*.h'
107 }
108 }
109 }
110 sources {
111 c {
112 source {
113 srcDirs 'src/main/cpp/examples/' + "${key}" + "/c"
114 include '**/*.c'
115 }
116 exportedHeaders {
117 srcDirs 'src/main/cpp/examples/' + "${key}" + "/include"
118 include '**/*.h'
119 }
120 }
121 }
122 }
123 }
124 templatesMap.each { key, value ->
125 "${key}"(NativeExecutableSpec) {
126 targetBuildTypes 'debug'
127 binaries.all { binary ->
128 lib project: ':wpilibOldCommands', library: 'wpilibOldCommands', linkage: 'shared'
129 lib project: ':wpilibNewCommands', library: 'wpilibNewCommands', linkage: 'shared'
130 lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800131 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800132 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"
140 } else {
141 cppCompiler.args "/wd4996"
142 }
143 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800144 if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
145 nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
146 }
147 }
148 sources {
149 cpp {
150 source {
151 srcDirs 'src/main/cpp/templates/' + "${key}" + "/cpp"
152 include '**/*.cpp'
153 }
154 exportedHeaders {
155 srcDirs 'src/main/cpp/templates/' + "${key}" + "/include"
156 include '**/*.h'
157 }
158 }
159 }
160 }
161 }
162 }
163 tasks {
164 def b = $.binaries
165 b.each { binary->
166 if (binary in NativeExecutableBinarySpec) {
167 def installDir = binary.tasks.install.installDirectory.get().toString() + File.separatorChar
168 def runFile = binary.tasks.install.runScriptFile.get().asFile.toString()
169
170 binary.tasks.install.doLast {
171 if (binary.targetPlatform.operatingSystem.isWindows()) {
172 // Windows batch scripts
Austin Schuh1e69f942020-11-14 15:06:14 -0800173 fileName = binary.component.name + 'RealDS.bat'
Brian Silverman8fce7482020-01-05 13:18:21 -0800174 file = new File(installDir + fileName)
175 file.withWriter { out ->
176 out.println '@ECHO OFF'
177 out.print 'SET HALSIM_EXTENSIONS='
Brian Silverman8fce7482020-01-05 13:18:21 -0800178 out.println '"' + new File(installDir + 'lib\\halsim_ds_socket.dll').toString() + '"'
179 out.println runFile + ' %*'
180 }
181 } else {
Austin Schuh1e69f942020-11-14 15:06:14 -0800182 fileName = binary.component.name + 'RealDS.sh'
Brian Silverman8fce7482020-01-05 13:18:21 -0800183 file = new File(installDir + fileName)
184 file.withWriter { out ->
185 out.print 'export HALSIM_EXTENSIONS='
Brian Silverman8fce7482020-01-05 13:18:21 -0800186 out.println '"' + new File(installDir + '/lib/libhalsim_ds_socket.so').toString() + '"'
187 out.println runFile + ' "$@"'
188 }
189 }
190 }
191
192 }
193 }
194 }
195}
196apply from: 'publish.gradle'
197
198model {
199 tasks {
200 def c = $.components
201 project.tasks.register('buildDesktopCpp') { compileTask->
202 def systemArch = getCurrentArch()
203 c.each {
204 if (it in NativeExecutableSpec && it.name) {
205 it.binaries.each {
206 def arch = it.targetPlatform.name
207 if (arch == systemArch && it.buildType.name == 'debug') {
208 compileTask.dependsOn it.tasks.link
209 }
210 }
211 }
212 }
213 }
214 }
215}
216
217ext {
218 templateDirectory = new File("$projectDir/src/main/cpp/templates/")
219 templateFile = new File("$projectDir/src/main/cpp/templates/templates.json")
220 exampleDirectory = new File("$projectDir/src/main/cpp/examples/")
221 exampleFile = new File("$projectDir/src/main/cpp/examples/examples.json")
222 commandDirectory = new File("$projectDir/src/main/cpp/commands/")
223 commandFile = new File("$projectDir/src/main/cpp/commands/commands.json")
224}
225
226ext {
227 isCppCommands = true
228}
229apply from: "${rootDir}/shared/examplecheck.gradle"