CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

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