blob: 3fef7b1768e11282e048b55e56a947949d3de01a [file] [log] [blame]
John Park7eb90422018-01-27 12:04:57 -08001apply plugin: 'cpp'
2apply plugin: 'google-test'
3apply plugin: 'visual-studio'
4apply plugin: 'edu.wpi.first.NativeUtils'
5
6apply from: '../config.gradle'
7
8ext.addHalToLinker = { binary->
9 if (binary.targetPlatform.architecture.name == 'athena') {
10 binary.lib project: ':hal', library: 'halAthena', linkage: 'shared'
11 } else {
12 binary.lib project: ':hal', library: 'halSim', linkage: 'shared'
13 }
14}
15
16model {
17 dependencyConfigs {
18 wpiutil(DependencyConfig) {
19 groupId = 'edu.wpi.first.wpiutil'
20 artifactId = 'wpiutil-cpp'
21 headerClassifier = 'headers'
22 ext = 'zip'
23 version = '3.+'
24 sharedConfigs = [ halAthena: [], halSim: [], halDev: [], halSimTestingBaseTest: [] ]
25 staticConfigs = [ halSimStaticDeps: [] ]
26 }
27 }
28 // Exports config is a utility to enable exporting all symbols in a C++ library on windows to a DLL.
29 // This removes the need for DllExport on a library. However, the gradle C++ builder has a bug
30 // where some extra symbols are added that cannot be resolved at link time. This configuration
31 // lets you specify specific symbols to exlude from exporting.
32 exportsConfigs {
33 halSim(ExportsConfig) {
34 x86ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
35 '_CT??_R0?AVbad_cast',
36 '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
37 '_TI5?AVfailure' ]
38 x64ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure',
39 '_CT??_R0?AVbad_cast',
40 '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure',
41 '_TI5?AVfailure' ]
42 }
43 halSimStaticDeps(ExportsConfig) {
44 x86SymbolFilter = { symbols->
45 def retList = []
46 symbols.each { symbol->
47 if (symbol.startsWith('HAL_')) {
48 retList << symbol
49 }
50 }
51 return retList
52 }
53 x64SymbolFilter = { symbols->
54 def retList = []
55 symbols.each { symbol->
56 if (symbol.startsWith('HAL_')) {
57 retList << symbol
58 }
59 }
60 return retList
61 }
62 }
63 }
64 components {
65 if (!project.hasProperty('skipAthena')) {
66 halAthena(NativeLibrarySpec) {
67 baseName = 'wpiHal'
68 sources {
69 cpp {
70 source {
71 srcDirs = [ 'src/main/native/shared', 'src/main/native/athena' ]
72 includes = ["**/*.cpp"]
73 }
74 exportedHeaders {
75 srcDirs = ["src/main/native/include"]
76 }
77 }
78 }
79 binaries.all { binary->
80 if (binary.targetPlatform.architecture.name != 'athena') {
81 binary.buildable = false
82 }
83 }
84 }
85 }
86 if (!project.hasProperty('onlyAthena')) {
87 halSim(NativeLibrarySpec) {
88 baseName = 'wpiHal'
89 sources {
90 cpp {
91 source {
92 srcDirs = [ 'src/main/native/shared', 'src/main/native/sim' ]
93 includes = ["**/*.cpp"]
94 }
95 exportedHeaders {
96 srcDirs = ["src/main/native/include"]
97 }
98 }
99 }
100 binaries.all { binary ->
101 if (binary.targetPlatform.operatingSystem.linux) {
102 linker.args "-ldl"
103 }
104 }
105 }
106 if (project.hasProperty('buildHalStaticDeps')) {
107 halSimStaticDeps(NativeLibrarySpec) {
108 baseName = 'wpiHal'
109 binaries {
110 withType(StaticLibraryBinarySpec) {
111 buildable = false
112 }
113 }
114 sources {
115 cpp {
116 source {
117 srcDirs = [ 'src/main/native/shared', 'src/main/native/sim' ]
118 includes = ["**/*.cpp"]
119 }
120 exportedHeaders {
121 srcDirs = ["src/main/native/include"]
122 }
123 }
124 }
125 }
126 }
127 }
128 // The TestingBase library is a workaround for an issue with the GoogleTest plugin.
129 // The plugin by default will rebuild the entire test source set, which increases
130 // build time. By testing an empty library, and then just linking the already built component
131 // into the test, we save the extra build
132 halSimTestingBase(NativeLibrarySpec) { }
133 // By default, a development executable will be generated. This is to help the case of
134 // testing specific functionality of the library.
135 if (!project.hasProperty('skipDevExe')) {
136 halDev(NativeExecutableSpec) {
137 binaries.all {
138 project.addHalToLinker(it)
139 }
140 sources {
141 cpp {
142 source {
143 srcDirs 'src/dev/native/cpp'
144 include '**/*.cpp'
145 }
146 exportedHeaders {
147 srcDirs 'src/dev/native/include'
148 }
149 }
150 }
151 }
152 }
153 }
154 testSuites {
155 halSimTestingBaseTest {
156 sources {
157 cpp.source.srcDir 'src/test/native/cpp'
158 cpp.exportedHeaders.srcDir 'src/test/native/include'
159 }
160 }
161 }
162 binaries {
163 all {
164 project(':ni-libraries').addNiLibrariesToLinker(it)
165 }
166 withType(GoogleTestTestSuiteBinarySpec) {
167 if (it.component.testedComponent.name.contains('TestingBase') && !project.hasProperty('onlyAthena')) {
168 project(':gmock').addGmockToLinker(it)
169 project.addHalToLinker(it)
170 } else {
171 it.buildable = false
172 }
173 }
174 }
175 tasks {
176 runCpp(Exec) {
177 def found = false
178 $.components.each {
179 if (it in NativeExecutableSpec && it.name == 'halDev') {
180 it.binaries.each {
181 if (!found) {
182 def arch = it.targetPlatform.architecture.name
183 if (arch == 'x86-64' || arch == 'x86') {
184 dependsOn it.tasks.install
185 commandLine it.tasks.install.runScript
186 found = true
187 }
188 }
189 }
190 }
191 }
192 }
193 getHeaders(Task) {
194 def list = []
195 $.components.each {
196 if (it in NativeLibrarySpec && (it.name == 'halAthena' || it.name == 'halSim')) {
197 it.sources.each {
198 it.exportedHeaders.srcDirs.each {
199 list.add(it)
200 }
201 }
202 it.binaries.each {
203 it.libs.each {
204 it.includeRoots.each {
205 list.add(it)
206 }
207 }
208 }
209 }
210 }
211 list = list.unique(false)
212 doLast {
213 list.each {
214 print "WPIHEADER: "
215 println it
216 }
217 }
218 }
219 }
220}
221
222apply from: 'publish.gradle'