waf: ensure all constants are float not double if not otherwise declared

allow DOUBLE_PRECISION_SOURCES in ap_find_tests()
This commit is contained in:
Andy Piper 2023-06-20 17:17:07 +01:00 committed by Peter Hall
parent 925ac9bc4e
commit 744028e79e
3 changed files with 25 additions and 9 deletions

View File

@ -271,10 +271,12 @@ def double_precision_check(tasks):
src = str(t.inputs[0]).split('/')[-2:]
if src in double_tasks:
single_precision_option='-fsingle-precision-constant'
t.env.CXXFLAGS = t.env.CXXFLAGS[:]
if single_precision_option in t.env.CXXFLAGS:
t.env.CXXFLAGS.remove(single_precision_option)
for opt in ['-fsingle-precision-constant', '-cl-single-precision-constant']:
try:
t.env.CXXFLAGS.remove(opt)
except ValueError:
pass
t.env.CXXFLAGS.append("-DALLOW_DOUBLE_MATH_FUNCTIONS")

View File

@ -303,6 +303,8 @@ def ap_program(bld,
for group in program_groups:
_grouped_programs.setdefault(group, {}).update({tg.name : tg})
return tg
@conf
def ap_example(bld, **kw):
@ -354,7 +356,7 @@ def ap_stlib_target(self):
self.target = '#%s' % os.path.join('lib', self.target)
@conf
def ap_find_tests(bld, use=[]):
def ap_find_tests(bld, use=[], DOUBLE_PRECISION_SOURCES=[]):
if not bld.env.HAS_GTEST:
return
@ -368,7 +370,7 @@ def ap_find_tests(bld, use=[]):
includes = [bld.srcnode.abspath() + '/tests/']
for f in bld.path.ant_glob(incl='*.cpp'):
ap_program(
t = ap_program(
bld,
features=features,
includes=includes,
@ -379,6 +381,16 @@ def ap_find_tests(bld, use=[]):
use_legacy_defines=False,
cxxflags=['-Wno-undef'],
)
filename = os.path.basename(f.abspath())
if filename in DOUBLE_PRECISION_SOURCES:
t.env.CXXFLAGS = t.env.CXXFLAGS[:]
single_precision_option='-fsingle-precision-constant'
if single_precision_option in t.env.CXXFLAGS:
t.env.CXXFLAGS.remove(single_precision_option)
single_precision_option='-cl-single-precision-constant'
if single_precision_option in t.env.CXXFLAGS:
t.env.CXXFLAGS.remove(single_precision_option)
t.env.CXXFLAGS.append("-DALLOW_DOUBLE_MATH_FUNCTIONS")
_versions = []

View File

@ -243,16 +243,20 @@ class Board:
if 'clang' in cfg.env.COMPILER_CC:
env.CFLAGS += [
'-fcolor-diagnostics',
'-Wno-gnu-designator',
'-Wno-inconsistent-missing-override',
'-Wno-mismatched-tags',
'-Wno-gnu-variable-sized-type-not-at-end',
'-Werror=implicit-fallthrough',
'-cl-single-precision-constant',
]
env.CXXFLAGS += [
'-cl-single-precision-constant',
]
else:
env.CFLAGS += [
'-Wno-format-contains-nul',
'-fsingle-precision-constant', # force const vals to be float , not double. so 100.0 means 100.0f
]
if self.cc_version_gte(cfg, 7, 4):
env.CXXFLAGS += [
@ -260,6 +264,7 @@ class Board:
]
env.CXXFLAGS += [
'-fcheck-new',
'-fsingle-precision-constant',
]
if cfg.env.DEBUG:
@ -878,7 +883,6 @@ class esp32(Board):
env.CFLAGS += [
'-fno-inline-functions',
'-mlongcalls',
'-fsingle-precision-constant',
]
env.CFLAGS.remove('-Werror=undef')
@ -894,7 +898,6 @@ class esp32(Board):
'-Wno-sign-compare',
'-fno-inline-functions',
'-mlongcalls',
'-fsingle-precision-constant', # force const vals to be float , not double. so 100.0 means 100.0f
'-fno-threadsafe-statics',
'-DCYGWIN_BUILD']
env.CXXFLAGS.remove('-Werror=undef')
@ -957,7 +960,6 @@ class chibios(Board):
env.CFLAGS += cfg.env.CPU_FLAGS + [
'-Wlogical-op',
'-Wframe-larger-than=1300',
'-fsingle-precision-constant',
'-Wno-attributes',
'-fno-exceptions',
'-Wall',