blob: 507ec445adf14aa96cf55d610e24506b342cc089 [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 x64ExcludeSymbols = [
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 ]
Brian Silverman8fce7482020-01-05 13:18:21 -080078 }
79}
80
81model {
82 components {
83 "${nativeName}Base"(NativeLibrarySpec) {
84 sources {
85 cpp {
86 source {
Austin Schuh812d0d12021-11-04 20:16:48 -070087 srcDirs = [
James Kuszmaulcf324122023-01-14 14:07:17 -080088 'src/main/native/cpp'
Austin Schuh812d0d12021-11-04 20:16:48 -070089 ]
Brian Silverman8fce7482020-01-05 13:18:21 -080090 include '**/*.cpp'
91 }
92 exportedHeaders {
93 srcDirs 'src/main/native/include'
94 }
95 }
96 }
97 binaries.all {
98 if (it instanceof SharedLibraryBinarySpec) {
99 it.buildable = false
100 return
101 }
James Kuszmaulcf324122023-01-14 14:07:17 -0800102
103 it.sources {
104 versionSources(CppSourceSet) {
105 source {
106 srcDirs = [
107 "${rootDir}/shared/singlelib",
108 "$buildDir/generated/cpp"
109 ]
110 include '**/*.cpp'
111 }
112 exportedHeaders {
113 srcDirs 'src/main/native/include'
114 }
115 }
116 }
117
Brian Silverman8fce7482020-01-05 13:18:21 -0800118 cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
James Kuszmaulcf324122023-01-14 14:07:17 -0800119 project(':ntcore').addNtcoreDependency(it, 'shared')
Brian Silverman8fce7482020-01-05 13:18:21 -0800120 project(':hal').addHalDependency(it, 'shared')
James Kuszmaulcf324122023-01-14 14:07:17 -0800121 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800122 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800123 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800124 }
125 }
126 "${nativeName}"(NativeLibrarySpec) {
127 sources {
128 cpp {
129 source {
130 srcDirs "src/main/native/cppcs"
131 include '**/*.cpp'
132 }
133 exportedHeaders {
134 srcDirs 'src/main/native/include', '../cameraserver/src/main/native/include'
135 }
136 }
137 }
138 binaries.all {
James Kuszmaulcf324122023-01-14 14:07:17 -0800139 project(':ntcore').addNtcoreDependency(it, 'shared')
Brian Silverman8fce7482020-01-05 13:18:21 -0800140 project(':hal').addHalDependency(it, 'shared')
James Kuszmaulcf324122023-01-14 14:07:17 -0800141 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800142 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800143 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800144
145 if (it instanceof SharedLibraryBinarySpec) {
146 cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
147 if (buildType == buildTypes.debug) {
148 cppCompiler.define 'DYNAMIC_CAMERA_SERVER_DEBUG'
149 }
150 } else {
151 lib project: ':cscore', library: 'cscore', linkage: 'shared'
152 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
153 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
154 }
Brian Silverman8fce7482020-01-05 13:18:21 -0800155 }
156 appendDebugPathToBinaries(binaries)
157 }
158 // By default, a development executable will be generated. This is to help the case of
159 // testing specific functionality of the library.
160 "${nativeName}Dev"(NativeExecutableSpec) {
161 targetBuildTypes 'debug'
162 sources {
163 cpp {
164 source {
165 srcDirs 'src/dev/native/cpp'
166 include '**/*.cpp'
167 lib library: 'wpilibc'
168 }
169 exportedHeaders {
170 srcDirs 'src/dev/native/include'
171 }
172 }
173 }
174 binaries.all {
James Kuszmaulcf324122023-01-14 14:07:17 -0800175 project(':ntcore').addNtcoreDependency(it, 'shared')
Brian Silverman8fce7482020-01-05 13:18:21 -0800176 lib project: ':cscore', library: 'cscore', linkage: 'shared'
177 project(':hal').addHalDependency(it, 'shared')
James Kuszmaulcf324122023-01-14 14:07:17 -0800178 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800179 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800180 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800181 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
182 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
183 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700184 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800185 }
186 }
187 }
188 }
189 testSuites {
190 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
191 for(NativeComponentSpec c : $.components) {
192 if (c.name == nativeName) {
193 testing c
194 break
195 }
196 }
197 sources {
198 cpp {
199 source {
200 srcDirs 'src/test/native/cpp'
201 include '**/*.cpp'
202 }
203 exportedHeaders {
204 srcDirs 'src/test/native/include', 'src/main/native/cpp'
205 }
206 }
207 c {
208 source {
209 srcDirs 'src/test/native/c'
210 include '**/*.c'
211 }
212 exportedHeaders {
213 srcDirs 'src/test/native/include', 'src/main/native/c'
214 }
215 }
216 }
217 }
218 }
219 binaries {
220 all {
221 tasks.withType(CppCompile) {
222 dependsOn generateCppVersion
223 }
224 }
225 withType(GoogleTestTestSuiteBinarySpec) {
James Kuszmaulcf324122023-01-14 14:07:17 -0800226 project(':ntcore').addNtcoreDependency(it, 'shared')
Brian Silverman8fce7482020-01-05 13:18:21 -0800227 lib project: ':cscore', library: 'cscore', linkage: 'shared'
228 project(':hal').addHalDependency(it, 'shared')
James Kuszmaulcf324122023-01-14 14:07:17 -0800229 lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800230 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800231 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800232 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
233 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
234 lib library: nativeName, linkage: 'shared'
235 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700236 nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
Brian Silverman8fce7482020-01-05 13:18:21 -0800237 }
238 }
239 }
240 tasks {
241 def c = $.components
242 project.tasks.create('runCpp', Exec) {
243 def found = false
244 c.each {
245 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
246 it.binaries.each {
247 if (!found) {
248 def arch = it.targetPlatform.architecture.name
249 if (arch == 'x86-64' || arch == 'x86') {
250 dependsOn it.tasks.install
Austin Schuh812d0d12021-11-04 20:16:48 -0700251 commandLine it.tasks.install.runScriptFile.get().asFile.toString()
Brian Silverman8fce7482020-01-05 13:18:21 -0800252 found = true
253 }
254 }
255 }
256 }
257 }
258 }
259 }
260}
261
262apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
263
264tasks.withType(RunTestExecutable) {
265 args "--gtest_output=xml:test_detail.xml"
266 outputs.dir outputDir
267}
268
269apply from: 'publish.gradle'
270
271def oldWpilibVersionFile = file('src/main/native/cpp/WPILibVersion.cpp')
272
273clean {
274 delete oldWpilibVersionFile
275}