From 090f323678da85942f55d6ca18cbff79875b9c34 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Sun, 29 Dec 2024 19:42:43 -0600 Subject: [PATCH] ardupilotwaf: properly configure double precision tasks There might be multiple copies of the flags, so remove all of them. Also pull the setup into a helper function to avoid duplicating the logic. On ChibiOS boards, this fixes SITL (which had issues with position quantization) and affects the SBF GPS driver (which was probably fine before but does change slightly). --- Tools/ardupilotwaf/ap_library.py | 8 +------- Tools/ardupilotwaf/ardupilotwaf.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Tools/ardupilotwaf/ap_library.py b/Tools/ardupilotwaf/ap_library.py index 9d0971c1e8..8d22258e06 100644 --- a/Tools/ardupilotwaf/ap_library.py +++ b/Tools/ardupilotwaf/ap_library.py @@ -275,13 +275,7 @@ def double_precision_check(tasks): double_library = t.env.DOUBLE_PRECISION_LIBRARIES.get(src[0],False) if double_library or src in double_tasks: - t.env.CXXFLAGS = t.env.CXXFLAGS[:] - 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") + t.env.CXXFLAGS = ap.set_double_precision_flags(t.env.CXXFLAGS) def gsoap_library_check(bld, tasks): diff --git a/Tools/ardupilotwaf/ardupilotwaf.py b/Tools/ardupilotwaf/ardupilotwaf.py index c854c8862e..3974c6a466 100644 --- a/Tools/ardupilotwaf/ardupilotwaf.py +++ b/Tools/ardupilotwaf/ardupilotwaf.py @@ -145,6 +145,24 @@ def get_legacy_defines(sketch_name, bld): 'AP_BUILD_TARGET_NAME="' + sketch_name + '"', ] +def set_double_precision_flags(flags): + # set up flags for double precision files: + # * remove all single precision constant flags + # * set define to allow double precision math in AP headers + + flags = flags[:] # copy the list to avoid affecting other builds + + # remove GCC and clang single precision constant flags + for opt in ('-fsingle-precision-constant', '-cl-single-precision-constant'): + while True: # might have multiple copies from different sources + try: + flags.remove(opt) + except ValueError: + break + flags.append("-DALLOW_DOUBLE_MATH_FUNCTIONS") + + return flags + IGNORED_AP_LIBRARIES = [ 'doc', 'AP_Scripting', # this gets explicitly included when it is needed and should otherwise never be globbed in