blob: 4ee57667d6a21eb182a2886adbd335e9d6cab8c9 [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'
101 }
102 }
103 "${nativeName}"(NativeLibrarySpec) {
104 sources {
105 cpp {
106 source {
107 srcDirs "src/main/native/cppcs"
108 include '**/*.cpp'
109 }
110 exportedHeaders {
111 srcDirs 'src/main/native/include', '../cameraserver/src/main/native/include'
112 }
113 }
114 }
115 binaries.all {
116 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
117 project(':hal').addHalDependency(it, 'shared')
118 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
119
120 if (it instanceof SharedLibraryBinarySpec) {
121 cppCompiler.define 'DYNAMIC_CAMERA_SERVER'
122 if (buildType == buildTypes.debug) {
123 cppCompiler.define 'DYNAMIC_CAMERA_SERVER_DEBUG'
124 }
125 } else {
126 lib project: ':cscore', library: 'cscore', linkage: 'shared'
127 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
128 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
129 }
130
131 }
132 appendDebugPathToBinaries(binaries)
133 }
134 // By default, a development executable will be generated. This is to help the case of
135 // testing specific functionality of the library.
136 "${nativeName}Dev"(NativeExecutableSpec) {
137 targetBuildTypes 'debug'
138 sources {
139 cpp {
140 source {
141 srcDirs 'src/dev/native/cpp'
142 include '**/*.cpp'
143 lib library: 'wpilibc'
144 }
145 exportedHeaders {
146 srcDirs 'src/dev/native/include'
147 }
148 }
149 }
150 binaries.all {
151 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
152 lib project: ':cscore', library: 'cscore', linkage: 'shared'
153 project(':hal').addHalDependency(it, 'shared')
154 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
155 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
156 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
157 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
158 nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
159 }
160 }
161 }
162 }
163 testSuites {
164 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
165 for(NativeComponentSpec c : $.components) {
166 if (c.name == nativeName) {
167 testing c
168 break
169 }
170 }
171 sources {
172 cpp {
173 source {
174 srcDirs 'src/test/native/cpp'
175 include '**/*.cpp'
176 }
177 exportedHeaders {
178 srcDirs 'src/test/native/include', 'src/main/native/cpp'
179 }
180 }
181 c {
182 source {
183 srcDirs 'src/test/native/c'
184 include '**/*.c'
185 }
186 exportedHeaders {
187 srcDirs 'src/test/native/include', 'src/main/native/c'
188 }
189 }
190 }
191 }
192 }
193 binaries {
194 all {
195 tasks.withType(CppCompile) {
196 dependsOn generateCppVersion
197 }
198 }
199 withType(GoogleTestTestSuiteBinarySpec) {
200 lib project: ':ntcore', library: 'ntcore', linkage: 'shared'
201 lib project: ':cscore', library: 'cscore', linkage: 'shared'
202 project(':hal').addHalDependency(it, 'shared')
203 lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
204 lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
205 nativeUtils.useRequiredLibrary(it, 'opencv_shared')
206 lib library: nativeName, linkage: 'shared'
207 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
208 nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
209 }
210 }
211 }
212 tasks {
213 def c = $.components
214 project.tasks.create('runCpp', Exec) {
215 def found = false
216 c.each {
217 if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") {
218 it.binaries.each {
219 if (!found) {
220 def arch = it.targetPlatform.architecture.name
221 if (arch == 'x86-64' || arch == 'x86') {
222 dependsOn it.tasks.install
223
224 found = true
225 }
226 }
227 }
228 }
229 }
230 }
231 }
232}
233
234apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
235
236tasks.withType(RunTestExecutable) {
237 args "--gtest_output=xml:test_detail.xml"
238 outputs.dir outputDir
239}
240
241apply from: 'publish.gradle'
242
243def oldWpilibVersionFile = file('src/main/native/cpp/WPILibVersion.cpp')
244
245clean {
246 delete oldWpilibVersionFile
247}