blob: ec85691c926120bfb32d8d718679c27a83c2f257 [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
63apply plugin: DisableBuildingGTest
64
65nativeUtils.exportsConfigs {
66 wpilibc {
67 x86ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
68 '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
69 '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
70 '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
71 x64ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
72 '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
73 '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range',
74 '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast']
75 }
76}
77
78model {
79 components {
80 "${nativeName}Base"(NativeLibrarySpec) {
81 sources {
82 cpp {
83 source {
84 srcDirs = ['src/main/native/cpp', "$buildDir/generated/cpp"]
85 include '**/*.cpp'
86 }
87 exportedHeaders {
88 srcDirs 'src/main/native/include'
89 }
90 }
91 }
92 binaries.all {
93 if (it instanceof SharedLibraryBinarySpec) {
94 it.buildable = false
95 return
96 }
97 cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
98 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
99 project(':hal').addHalDependency(it, 'shared')
100 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800101 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800102 }
103 }
104 "${nativeName}"(NativeLibrarySpec) {
105 sources {
106 cpp {
107 source {
108 srcDirs "src/main/native/cppcs"
109 include '**/*.cpp'
110 }
111 exportedHeaders {
112 srcDirs 'src/main/native/include', '../cameraserver/src/main/native/include'
113 }
114 }
115 }
116 binaries.all {
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 if (it instanceof SharedLibraryBinarySpec) {
123 cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
124 if (buildType == buildTypes.debug) {
125 cppCompiler.define 'DYNAMIC_CAMERA_SERVER_DEBUG'
126 }
127 } else {
128 lib project: ':cscore', library: 'cscore', linkage: 'shared'
129 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
130 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
131 }
132
133 }
134 appendDebugPathToBinaries(binaries)
135 }
136 // By default, a development executable will be generated. This is to help the case of
137 // testing specific functionality of the library.
138 "${nativeName}Dev"(NativeExecutableSpec) {
139 targetBuildTypes 'debug'
140 sources {
141 cpp {
142 source {
143 srcDirs 'src/dev/native/cpp'
144 include '**/*.cpp'
145 lib library: 'wpilibc'
146 }
147 exportedHeaders {
148 srcDirs 'src/dev/native/include'
149 }
150 }
151 }
152 binaries.all {
153 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
154 lib project: ':cscore', library: 'cscore', linkage: 'shared'
155 project(':hal').addHalDependency(it, 'shared')
156 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800157 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800158 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
159 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
160 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
161 nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
162 }
163 }
164 }
165 }
166 testSuites {
167 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
168 for(NativeComponentSpec c : $.components) {
169 if (c.name == nativeName) {
170 testing c
171 break
172 }
173 }
174 sources {
175 cpp {
176 source {
177 srcDirs 'src/test/native/cpp'
178 include '**/*.cpp'
179 }
180 exportedHeaders {
181 srcDirs 'src/test/native/include', 'src/main/native/cpp'
182 }
183 }
184 c {
185 source {
186 srcDirs 'src/test/native/c'
187 include '**/*.c'
188 }
189 exportedHeaders {
190 srcDirs 'src/test/native/include', 'src/main/native/c'
191 }
192 }
193 }
194 }
195 }
196 binaries {
197 all {
198 tasks.withType(CppCompile) {
199 dependsOn generateCppVersion
200 }
201 }
202 withType(GoogleTestTestSuiteBinarySpec) {
203 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
204 lib project: ':cscore', library: 'cscore', linkage: 'shared'
205 project(':hal').addHalDependency(it, 'shared')
206 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
Austin Schuh1e69f942020-11-14 15:06:14 -0800207 lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
Brian Silverman8fce7482020-01-05 13:18:21 -0800208 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
209 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
210 lib library: nativeName, linkage: 'shared'
211 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
212 nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
213 }
214 }
215 }
216 tasks {
217 def c = $.components
218 project.tasks.create('runCpp', Exec) {
219 def found = false
220 c.each {
221 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
222 it.binaries.each {
223 if (!found) {
224 def arch = it.targetPlatform.architecture.name
225 if (arch == 'x86-64' || arch == 'x86') {
226 dependsOn it.tasks.install
227
228 found = true
229 }
230 }
231 }
232 }
233 }
234 }
235 }
236}
237
238apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
239
240tasks.withType(RunTestExecutable) {
241 args "--gtest_output=xml:test_detail.xml"
242 outputs.dir outputDir
243}
244
245apply from: 'publish.gradle'
246
247def oldWpilibVersionFile = file('src/main/native/cpp/WPILibVersion.cpp')
248
249clean {
250 delete oldWpilibVersionFile
251}