Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/ardupilotwaf/cxx_checks.py
9814 views
1
# Copyright (C) 2016 Intel Corporation. All rights reserved.
2
#
3
# This file is free software: you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License as published by the
5
# Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This file is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
# See the GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
# flake8: noqa
17
18
"""
19
WAF Tool that checks cxx parameters, creating the ap_config.h
20
header file.
21
22
This tool needs compiler_cxx to be loaded, make sure you
23
load them before this tool.
24
25
Example::
26
def configure(cfg):
27
cfg.load('cxx_checks')
28
"""
29
30
from waflib.Configure import conf
31
32
@conf
33
def ap_common_checks(cfg):
34
cfg.check(
35
compiler='cxx',
36
fragment='''
37
#include <cmath>
38
39
int main() {
40
return std::isfinite(1.0f);
41
}''',
42
define_name="HAVE_CMATH_ISFINITE",
43
msg="Checking for HAVE_CMATH_ISFINITE",
44
mandatory=False,
45
)
46
47
cfg.check(
48
compiler='cxx',
49
fragment='''
50
#include <cmath>
51
52
int main() {
53
return std::isinf(1.0f);
54
}''',
55
define_name="HAVE_CMATH_ISINF",
56
msg="Checking for HAVE_CMATH_ISINF",
57
mandatory=False,
58
)
59
60
cfg.check(
61
compiler='cxx',
62
fragment='''
63
#include <cmath>
64
65
int main() {
66
return std::isnan(1.0f);
67
}''',
68
define_name="HAVE_CMATH_ISNAN",
69
msg="Checking for HAVE_CMATH_ISNAN",
70
mandatory=False,
71
)
72
73
# NEED_CMATH_FUNCTION_STD_NAMESPACE checks are needed due to
74
# new gcc versions being more restrictive.
75
#
76
# Here we check if we need to add 'using std::function' to
77
# the function.
78
#
79
# Without these checks, in some cases, gcc points this as
80
# overloads or function duplication in scope.
81
82
cfg.check(
83
compiler='cxx',
84
fragment='''
85
#include <math.h>
86
#include <cmath>
87
88
using std::isfinite;
89
90
int main() {
91
return isfinite((double)1);
92
}''',
93
define_name="NEED_CMATH_ISFINITE_STD_NAMESPACE",
94
msg="Checking for NEED_CMATH_ISFINITE_STD_NAMESPACE",
95
mandatory=False,
96
)
97
98
cfg.check(
99
compiler='cxx',
100
fragment='''
101
#include <math.h>
102
#include <cmath>
103
104
using std::isinf;
105
106
int main() {
107
return isinf((double)1);
108
}''',
109
define_name="NEED_CMATH_ISINF_STD_NAMESPACE",
110
msg="Checking for NEED_CMATH_ISINF_STD_NAMESPACE",
111
mandatory=False,
112
)
113
114
cfg.check(
115
compiler='cxx',
116
fragment='''
117
#include <math.h>
118
#include <cmath>
119
120
using std::isnan;
121
122
int main() {
123
return isnan((double)1);
124
}''',
125
define_name="NEED_CMATH_ISNAN_STD_NAMESPACE",
126
msg="Checking for NEED_CMATH_ISNAN_STD_NAMESPACE",
127
mandatory=False,
128
)
129
130
cfg.check(header_name='endian.h', mandatory=False)
131
132
cfg.check(header_name='byteswap.h', mandatory=False)
133
134
cfg.check(
135
compiler='cxx',
136
fragment='''
137
#include <string.h>
138
int main() {
139
const char *s = "abc";
140
return memrchr((const void *)s, 0, 3) != NULL;
141
}''',
142
define_name="HAVE_MEMRCHR",
143
msg="Checking for HAVE_MEMRCHR",
144
mandatory=False,
145
)
146
147
@conf
148
def check_librt(cfg, env):
149
if cfg.env.DEST_OS == 'darwin':
150
return True
151
152
ret = cfg.check(
153
compiler='cxx',
154
fragment='''
155
#include <time.h>
156
157
int main() {
158
clock_gettime(CLOCK_REALTIME, NULL);
159
}''',
160
msg='Checking for need to link with librt',
161
okmsg='not necessary',
162
errmsg='necessary',
163
mandatory=False,
164
)
165
166
if ret:
167
return ret
168
169
ret = cfg.check(compiler='cxx', lib='rt')
170
if ret:
171
env.LIB += cfg.env['LIB_RT']
172
173
return ret
174
175
@conf
176
def check_feenableexcept(cfg):
177
178
cfg.check(
179
compiler='cxx',
180
fragment='''
181
#include <fenv.h>
182
183
int main() {
184
return feenableexcept(FE_OVERFLOW | FE_DIVBYZERO);
185
}''',
186
msg="Checking for feenableexcept",
187
define_name="HAVE_FEENABLEEXCEPT",
188
mandatory=False,
189
)
190
191
@conf
192
def check_package(cfg, env, libname):
193
'''use pkg-config to look for an installed library that has a LIBNAME.pc file'''
194
capsname = libname.upper()
195
196
cfg.env.stash()
197
198
if not cfg.check_cfg(package=libname, mandatory=False, global_define=True,
199
args=['--libs', '--cflags'], uselib_store=capsname):
200
# Don't even try to link if check_cfg fails
201
cfg.env.revert()
202
return False
203
204
if not cfg.check(compiler='cxx',
205
fragment='''int main() { return 0; }''',
206
msg='Checking link with %s' % libname,
207
mandatory=False,
208
use=capsname):
209
cfg.env.revert()
210
return False
211
212
cfg.env.commit()
213
214
# Add to global environment:
215
# we always want to use the library for all targets
216
env.LIB += cfg.env['LIB_%s' % capsname]
217
env.INCLUDES += cfg.env['INCLUDES_%s' % capsname]
218
env.CFLAGS += cfg.env['CFLAGS_%s' % capsname]
219
env.LIBPATH += cfg.env['LIBPATH_%s' % capsname]
220
221
return True
222
223
@conf
224
def check_lttng(cfg, env):
225
if not cfg.options.enable_lttng:
226
cfg.msg("Checking for 'lttng-ust':", 'disabled', color='YELLOW')
227
return False
228
if cfg.env.STATIC_LINKING:
229
# lttng-ust depends on libdl which means it can't be used in a static build
230
cfg.msg("Checking for 'lttng-ust':", 'disabled for static build', color='YELLOW')
231
return False
232
233
return check_package(cfg, env, 'lttng-ust')
234
235
@conf
236
def check_libiio(cfg, env):
237
if cfg.env.STATIC_LINKING:
238
# libiio depends on libdl which means it can't be used in a static build
239
cfg.msg("Checking for 'libiio':", 'disabled for static build', color='YELLOW')
240
return False
241
if cfg.options.disable_libiio:
242
cfg.msg("Checking for 'libiio':", 'disabled', color='YELLOW')
243
return False
244
245
return check_package(cfg, env, 'libiio')
246
247
@conf
248
def check_libdl(cfg, env):
249
if cfg.env.STATIC_LINKING:
250
# using loadable modules for a static build is not recommended
251
cfg.msg("Checking for 'libdl':", 'disabled for static build', color='YELLOW')
252
return False
253
ret = cfg.check(compiler='cxx', lib='dl', mandatory=False, global_define=True, define_name='HAVE_LIBDL')
254
if ret:
255
env.LIB += cfg.env['LIB_DL']
256
return ret
257
258
@conf
259
def check_SFML(cfg, env):
260
if not cfg.options.enable_sfml:
261
cfg.msg("Checking for SFML graphics:", 'disabled', color='YELLOW')
262
return False
263
libs = ['sfml-graphics', 'sfml-window','sfml-system']
264
for lib in libs:
265
if not cfg.check(compiler='cxx', lib=lib, mandatory=False,
266
global_define=True):
267
cfg.fatal("Missing SFML libraries - please install libsfml-dev")
268
return False
269
270
# see if we need Graphics.hpp or Graphics.h
271
if not cfg.check(compiler='cxx',
272
fragment='''#include <SFML/Graphics.hpp>\nint main() {}''', define_name="HAVE_SFML_GRAPHICS_HPP",
273
msg="Checking for Graphics.hpp", mandatory=False):
274
if not cfg.check(compiler='cxx', fragment='''#include <SFML/Graphics.h>\nint main() {}''', define_name="HAVE_SFML_GRAPHICS_H",
275
msg="Checking for Graphics.h", mandatory=False):
276
cfg.fatal("Missing SFML headers SFML/Graphics.hpp or SFML/Graphics.h")
277
return False
278
env.LIB += libs
279
return True
280
281
282
@conf
283
def check_SFML_Audio(cfg, env):
284
if not cfg.options.enable_sfml_audio:
285
cfg.msg("Checking for SFML audio:", 'disabled', color='YELLOW')
286
return False
287
libs = ['sfml-audio']
288
for lib in libs:
289
if not cfg.check(compiler='cxx', lib=lib, mandatory=False,
290
global_define=True):
291
cfg.fatal("Missing SFML libraries - please install libsfml-dev")
292
return False
293
294
# see if we need Audio.hpp or Audio.h
295
if not cfg.check(compiler='cxx',
296
fragment='''#include <SFML/Audio.hpp>\nint main() {}''', define_name="HAVE_SFML_AUDIO_HPP",
297
msg="Checking for Audio.hpp", mandatory=False):
298
if not cfg.check(compiler='cxx', fragment='''#include <SFML/Audio.h>\nint main() {}''', define_name="HAVE_SFML_AUDIO_H",
299
msg="Checking for Audio.h", mandatory=False):
300
cfg.fatal("Missing SFML headers SFML/Audio.hpp or SFML/Audio.h")
301
return False
302
env.LIB += libs
303
return True
304
305
306