Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/ardupilotwaf/cxx_checks.py
Views: 1798
# Copyright (C) 2016 Intel Corporation. All rights reserved.1#2# This file is free software: you can redistribute it and/or modify it3# under the terms of the GNU General Public License as published by the4# Free Software Foundation, either version 3 of the License, or5# (at your option) any later version.6#7# This file is distributed in the hope that it will be useful, but8# WITHOUT ANY WARRANTY; without even the implied warranty of9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.10# See the GNU General Public License for more details.11#12# You should have received a copy of the GNU General Public License along13# with this program. If not, see <http://www.gnu.org/licenses/>.14"""15WAF Tool that checks cxx parameters, creating the ap_config.h16header file.1718This tool needs compiler_cxx to be loaded, make sure you19load them before this tool.2021Example::22def configure(cfg):23cfg.load('cxx_checks')24"""2526from waflib.Configure import conf2728@conf29def ap_common_checks(cfg):30cfg.check(31compiler='cxx',32fragment='''33#include <cmath>3435int main() {36return std::isfinite(1.0f);37}''',38define_name="HAVE_CMATH_ISFINITE",39msg="Checking for HAVE_CMATH_ISFINITE",40mandatory=False,41)4243cfg.check(44compiler='cxx',45fragment='''46#include <cmath>4748int main() {49return std::isinf(1.0f);50}''',51define_name="HAVE_CMATH_ISINF",52msg="Checking for HAVE_CMATH_ISINF",53mandatory=False,54)5556cfg.check(57compiler='cxx',58fragment='''59#include <cmath>6061int main() {62return std::isnan(1.0f);63}''',64define_name="HAVE_CMATH_ISNAN",65msg="Checking for HAVE_CMATH_ISNAN",66mandatory=False,67)6869# NEED_CMATH_FUNCTION_STD_NAMESPACE checks are needed due to70# new gcc versions being more restrictive.71#72# Here we check if we need to add 'using std::function' to73# the function.74#75# Without these checks, in some cases, gcc points this as76# overloads or function duplication in scope.7778cfg.check(79compiler='cxx',80fragment='''81#include <math.h>82#include <cmath>8384using std::isfinite;8586int main() {87return isfinite((double)1);88}''',89define_name="NEED_CMATH_ISFINITE_STD_NAMESPACE",90msg="Checking for NEED_CMATH_ISFINITE_STD_NAMESPACE",91mandatory=False,92)9394cfg.check(95compiler='cxx',96fragment='''97#include <math.h>98#include <cmath>99100using std::isinf;101102int main() {103return isinf((double)1);104}''',105define_name="NEED_CMATH_ISINF_STD_NAMESPACE",106msg="Checking for NEED_CMATH_ISINF_STD_NAMESPACE",107mandatory=False,108)109110cfg.check(111compiler='cxx',112fragment='''113#include <math.h>114#include <cmath>115116using std::isnan;117118int main() {119return isnan((double)1);120}''',121define_name="NEED_CMATH_ISNAN_STD_NAMESPACE",122msg="Checking for NEED_CMATH_ISNAN_STD_NAMESPACE",123mandatory=False,124)125126cfg.check(header_name='endian.h', mandatory=False)127128cfg.check(header_name='byteswap.h', mandatory=False)129130cfg.check(131compiler='cxx',132fragment='''133#include <string.h>134int main() {135const char *s = "abc";136return memrchr((const void *)s, 0, 3) != NULL;137}''',138define_name="HAVE_MEMRCHR",139msg="Checking for HAVE_MEMRCHR",140mandatory=False,141)142143@conf144def check_librt(cfg, env):145if cfg.env.DEST_OS == 'darwin':146return True147148ret = cfg.check(149compiler='cxx',150fragment='''151#include <time.h>152153int main() {154clock_gettime(CLOCK_REALTIME, NULL);155}''',156msg='Checking for need to link with librt',157okmsg='not necessary',158errmsg='necessary',159mandatory=False,160)161162if ret:163return ret164165ret = cfg.check(compiler='cxx', lib='rt')166if ret:167env.LIB += cfg.env['LIB_RT']168169return ret170171@conf172def check_feenableexcept(cfg):173174cfg.check(175compiler='cxx',176fragment='''177#include <fenv.h>178179int main() {180return feenableexcept(FE_OVERFLOW | FE_DIVBYZERO);181}''',182msg="Checking for feenableexcept",183define_name="HAVE_FEENABLEEXCEPT",184mandatory=False,185)186187@conf188def check_package(cfg, env, libname):189'''use pkg-config to look for an installed library that has a LIBNAME.pc file'''190capsname = libname.upper()191192cfg.env.stash()193194if not cfg.check_cfg(package=libname, mandatory=False, global_define=True,195args=['--libs', '--cflags'], uselib_store=capsname):196# Don't even try to link if check_cfg fails197cfg.env.revert()198return False199200if not cfg.check(compiler='cxx',201fragment='''int main() { return 0; }''',202msg='Checking link with %s' % libname,203mandatory=False,204use=capsname):205cfg.env.revert()206return False207208cfg.env.commit()209210# Add to global environment:211# we always want to use the library for all targets212env.LIB += cfg.env['LIB_%s' % capsname]213env.INCLUDES += cfg.env['INCLUDES_%s' % capsname]214env.CFLAGS += cfg.env['CFLAGS_%s' % capsname]215env.LIBPATH += cfg.env['LIBPATH_%s' % capsname]216217return True218219@conf220def check_lttng(cfg, env):221if not cfg.options.enable_lttng:222cfg.msg("Checking for 'lttng-ust':", 'disabled', color='YELLOW')223return False224if cfg.env.STATIC_LINKING:225# lttng-ust depends on libdl which means it can't be used in a static build226cfg.msg("Checking for 'lttng-ust':", 'disabled for static build', color='YELLOW')227return False228229return check_package(cfg, env, 'lttng-ust')230231@conf232def check_libiio(cfg, env):233if cfg.env.STATIC_LINKING:234# libiio depends on libdl which means it can't be used in a static build235cfg.msg("Checking for 'libiio':", 'disabled for static build', color='YELLOW')236return False237if cfg.options.disable_libiio:238cfg.msg("Checking for 'libiio':", 'disabled', color='YELLOW')239return False240241return check_package(cfg, env, 'libiio')242243@conf244def check_libdl(cfg, env):245if cfg.env.STATIC_LINKING:246# using loadable modules for a static build is not recommended247cfg.msg("Checking for 'libdl':", 'disabled for static build', color='YELLOW')248return False249ret = cfg.check(compiler='cxx', lib='dl', mandatory=False, global_define=True, define_name='HAVE_LIBDL')250if ret:251env.LIB += cfg.env['LIB_DL']252return ret253254@conf255def check_SFML(cfg, env):256if not cfg.options.enable_sfml:257cfg.msg("Checking for SFML graphics:", 'disabled', color='YELLOW')258return False259libs = ['sfml-graphics', 'sfml-window','sfml-system']260for lib in libs:261if not cfg.check(compiler='cxx', lib=lib, mandatory=False,262global_define=True):263cfg.fatal("Missing SFML libraries - please install libsfml-dev")264return False265266# see if we need Graphics.hpp or Graphics.h267if not cfg.check(compiler='cxx',268fragment='''#include <SFML/Graphics.hpp>\nint main() {}''', define_name="HAVE_SFML_GRAPHICS_HPP",269msg="Checking for Graphics.hpp", mandatory=False):270if not cfg.check(compiler='cxx', fragment='''#include <SFML/Graphics.h>\nint main() {}''', define_name="HAVE_SFML_GRAPHICS_H",271msg="Checking for Graphics.h", mandatory=False):272cfg.fatal("Missing SFML headers SFML/Graphics.hpp or SFML/Graphics.h")273return False274env.LIB += libs275return True276277278@conf279def check_SFML_Audio(cfg, env):280if not cfg.options.enable_sfml_audio:281cfg.msg("Checking for SFML audio:", 'disabled', color='YELLOW')282return False283libs = ['sfml-audio']284for lib in libs:285if not cfg.check(compiler='cxx', lib=lib, mandatory=False,286global_define=True):287cfg.fatal("Missing SFML libraries - please install libsfml-dev")288return False289290# see if we need Audio.hpp or Audio.h291if not cfg.check(compiler='cxx',292fragment='''#include <SFML/Audio.hpp>\nint main() {}''', define_name="HAVE_SFML_AUDIO_HPP",293msg="Checking for Audio.hpp", mandatory=False):294if not cfg.check(compiler='cxx', fragment='''#include <SFML/Audio.h>\nint main() {}''', define_name="HAVE_SFML_AUDIO_H",295msg="Checking for Audio.h", mandatory=False):296cfg.fatal("Missing SFML headers SFML/Audio.hpp or SFML/Audio.h")297return False298env.LIB += libs299return True300301302303