blob: c9c2670d07d4aabe279c76966c969f16a8cd35bb [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001apply plugin: 'cpp'
2apply plugin: 'c'
3apply plugin: 'google-test-test-suite'
4apply plugin: 'visual-studio'
5apply plugin: 'edu.wpi.first.NativeUtils'
6apply plugin: SingleNativeBuild
7apply plugin: ExtraTasks
8
9ext {
10 nativeName = 'wpilibc'
11}
12
13apply from: "${rootDir}/shared/config.gradle"
14
15def wpilibVersionFileInput = file("src/generate/WPILibVersion.cpp.in")
16def wpilibVersionFileOutput = file("$buildDir/generated/cpp/WPILibVersion.cpp")
17
18task generateCppVersion() {
19 description = 'Generates the wpilib version class'
20 group = 'WPILib'
21
22 outputs.file wpilibVersionFileOutput
23 inputs.file wpilibVersionFileInput
24
25 if (wpilibVersioning.releaseMode) {
26 outputs.upToDateWhen { false }
27 }
28
29 // We follow a simple set of checks to determine whether we should generate a new version file:
30 // 1. If the release type is not development, we generate a new version file
31 // 2. If there is no generated version number, we generate a new version file
32 // 3. If there is a generated build number, and the release type is development, then we will
33 // only generate if the publish task is run.
34 doLast {
35 def version = wpilibVersioning.version.get()
36 println "Writing version ${version} to $wpilibVersionFileOutput"
37
38 if (wpilibVersionFileOutput.exists()) {
39 wpilibVersionFileOutput.delete()
40 }
41 def read = wpilibVersionFileInput.text.replace('${wpilib_version}', version)
42 wpilibVersionFileOutput.write(read)
43 }
44}
45
46gradle.taskGraph.addTaskExecutionGraphListener { graph ->
47 def willPublish = graph.hasTask(publish)
48 if (willPublish) {
49 generateCppVersion.outputs.upToDateWhen { false }
50 }
51}
52
53project(':').libraryBuild.dependsOn build
54
55ext {
56 staticGtestConfigs = [:]
57}
58
59staticGtestConfigs["${nativeName}Test"] = []
60
61apply from: "${rootDir}/shared/googletest.gradle"
62
Brian Silverman8fce7482020-01-05 13:18:21 -080063nativeUtils.exportsConfigs {
64 wpilibc {
Austin Schuh812d0d12021-11-04 20:16:48 -070065 x86ExcludeSymbols = [
66 '_CT??_R0?AV_System_error',
67 '_CT??_R0?AVexception',
68 '_CT??_R0?AVfailure',
69 '_CT??_R0?AVruntime_error',
70 '_CT??_R0?AVsystem_error',
71 '_CTA5?AVfailure',
72 '_TI5?AVfailure',
73 '_CT??_R0?AVout_of_range',
74 '_CTA3?AVout_of_range',
75 '_TI3?AVout_of_range',
76 '_CT??_R0?AVbad_cast'
77 ]
78 x64ExcludeSymbols = [
79 '_CT??_R0?AV_System_error',
80 '_CT??_R0?AVexception',
81 '_CT??_R0?AVfailure',
82 '_CT??_R0?AVruntime_error',
83 '_CT??_R0?AVsystem_error',
84 '_CTA5?AVfailure',
85 '_TI5?AVfailure',
86 '_CT??_R0?AVout_of_range',
87 '_CTA3?AVout_of_range',
88 '_TI3?AVout_of_range',
89 '_CT??_R0?AVbad_cast'
90 ]
Brian Silverman8fce7482020-01-05 13:18:21 -080091 }
92}
93
94model {
95 components {
96 "${nativeName}Base"(NativeLibrarySpec) {
97 sources {
98 cpp {
99 source {
Austin Schuh812d0d12021-11-04 20:16:48 -0700100 srcDirs = [
101 'src/main/native/cpp',
102 "$buildDir/generated/cpp"
103 ]
Brian Silverman8fce7482020-01-05 13:18:21 -0800104 include '**/*.cpp'
105 }
106 exportedHeaders {
107 srcDirs 'src/main/native/include'
108 }
109 }
110 }
111 binaries.all {
112 if (it instanceof SharedLibraryBinarySpec) {
113 it.buildable = false
114 return
115 }
116 cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
117 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
118 project(':hal').addHalDependency(it, 'shared')
119 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800120 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800121 }
122 }
123 "${nativeName}"(NativeLibrarySpec) {
124 sources {
125 cpp {
126 source {
127 srcDirs "src/main/native/cppcs"
128 include '**/*.cpp'
129 }
130 exportedHeaders {
131 srcDirs 'src/main/native/include', '../cameraserver/src/main/native/include'
132 }
133 }
134 }
135 binaries.all {
136 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
137 project(':hal').addHalDependency(it, 'shared')
138 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800139 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800140
141 if (it instanceof SharedLibraryBinarySpec) {
142 cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
143 if (buildType == buildTypes.debug) {
144 cppCompiler.define 'DYNAMIC_CAMERA_SERVER_DEBUG'
145 }
146 } else {
147 lib project: ':cscore', library: 'cscore', linkage: 'shared'
148 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
149 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
150 }
151
152 }
153 appendDebugPathToBinaries(binaries)
154 }
155 // By default, a development executable will be generated. This is to help the case of
156 // testing specific functionality of the library.
157 "${nativeName}Dev"(NativeExecutableSpec) {
158 targetBuildTypes 'debug'
159 sources {
160 cpp {
161 source {
162 srcDirs 'src/dev/native/cpp'
163 include '**/*.cpp'
164 lib library: 'wpilibc'
165 }
166 exportedHeaders {
167 srcDirs 'src/dev/native/include'
168 }
169 }
170 }
171 binaries.all {
172 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
173 lib project: ':cscore', library: 'cscore', linkage: 'shared'
174 project(':hal').addHalDependency(it, 'shared')
175 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800176 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800177 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
178 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
179 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700180 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800181 }
182 }
183 }
184 }
185 testSuites {
186 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
187 for(NativeComponentSpec c : $.components) {
188 if (c.name == nativeName) {
189 testing c
190 break
191 }
192 }
193 sources {
194 cpp {
195 source {
196 srcDirs 'src/test/native/cpp'
197 include '**/*.cpp'
198 }
199 exportedHeaders {
200 srcDirs 'src/test/native/include', 'src/main/native/cpp'
201 }
202 }
203 c {
204 source {
205 srcDirs 'src/test/native/c'
206 include '**/*.c'
207 }
208 exportedHeaders {
209 srcDirs 'src/test/native/include', 'src/main/native/c'
210 }
211 }
212 }
213 }
214 }
215 binaries {
216 all {
217 tasks.withType(CppCompile) {
218 dependsOn generateCppVersion
219 }
220 }
221 withType(GoogleTestTestSuiteBinarySpec) {
222 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
223 lib project: ':cscore', library: 'cscore', linkage: 'shared'
224 project(':hal').addHalDependency(it, 'shared')
225 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800226 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800227 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
228 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
229 lib library: nativeName, linkage: 'shared'
230 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700231 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800232 }
233 }
234 }
235 tasks {
236 def c = $.components
237 project.tasks.create('runCpp', Exec) {
238 def found = false
239 c.each {
240 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
241 it.binaries.each {
242 if (!found) {
243 def arch = it.targetPlatform.architecture.name
244 if (arch == 'x86-64' || arch == 'x86') {
245 dependsOn it.tasks.install
Austin Schuh812d0d12021-11-04 20:16:48 -0700246 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
Brian Silverman8fce7482020-01-05 13:18:21 -0800247 found = true
248 }
249 }
250 }
251 }
252 }
253 }
254 }
255}
256
257apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
258
259tasks.withType(RunTestExecutable) {
260 args "--gtest_output=xml:test_detail.xml"
261 outputs.dir outputDir
262}
263
264apply from: 'publish.gradle'
265
266def oldWpilibVersionFile = file('src/main/native/cpp/WPILibVersion.cpp')
267
268clean {
269 delete oldWpilibVersionFile
270}