From a134dc1abfadd80c6352adaeb4a5885c375609ed Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Thu, 6 Feb 2025 14:47:10 +0100 Subject: [PATCH 1/2] Move to use C++20 as standard. Remove non-functional compiler-flag test. Remove a contraction in an explanatory text so vim will highlight correctly. Always add -Wextra compiler flag. We are now completely warning free. Add configure option --enable-werror to force any warnings to become errors. --- src/Makefile | 1 - src/configure.ac | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Makefile b/src/Makefile index ccf0307836c..63fce450218 100644 --- a/src/Makefile +++ b/src/Makefile @@ -255,7 +255,6 @@ OPT := -Os $(INTEGER_OVERFLOW_FLAGS) DEBUG := $(DEBUG) -g -Wall -D_FORTIFY_SOURCE=2 CFLAGS := $(INCLUDE) $(OPT) $(DEBUG) -DULAPI -std=gnu11 -Werror=implicit-function-declaration $(CFLAGS) $(CPPFLAGS) $(EXTRA_DEBUG) CXXFLAGS := $(INCLUDE) $(OPT) $(DEBUG) -DULAPI -Werror=overloaded-virtual $(CXXFLAGS) $(CPPFLAGS) $(EXTRA_DEBUG) -CXXFLAGS += -std=gnu++20 # In Debian 11, any inclusion of leads to several # diagnostics from included headers about deprecated features. LinuxCNC does # not directly use these deprecated features, but it does use boost::python. diff --git a/src/configure.ac b/src/configure.ac index 8f44a214c3f..8b9e9205fe3 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -39,7 +39,7 @@ m4_include([m4/ax_python.m4]) m4_include([m4/ax_python_devel.m4]) m4_include([m4/ax_boost_base.m4]) m4_include([m4/ax_boost_python.m4]) -AX_CXX_COMPILE_STDCXX(17, , mandatory) +AX_CXX_COMPILE_STDCXX(20, , mandatory) AC_MSG_CHECKING(build toplevel) BUILD_TOPLEVEL="$(cd ..; pwd -P)" @@ -406,14 +406,6 @@ elif ! test `$CC -dumpversion | cut -d '.' -f 1` -gt 2 ; then AC_MSG_ERROR([Compilers older than gcc 3.x are no longer supported]) fi -# Set flags for C and C++ if supported -for commonflag in -Wno-stringop-truncation ; do - if echo "int main() { return 0;}" | $CC -Werror $commonflag -E - > /dev/null; then - CFLAGS="${CFLAGS:+$CFLAGS }$flag" - CXXFLAGS="${CXXFLAGS:+$CXXFLAGS }$flag" - fi -done - AC_MSG_CHECKING([for usability of linux/hidraw.h]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include @@ -1559,7 +1551,7 @@ AC_SUBST([READLINE_LIBS]) # if you don't have nls tools, allow a way out! AC_ARG_ENABLE(nls, - AS_HELP_STRING([--disable-nls], [Don't use NLS.]), + AS_HELP_STRING([--disable-nls], [Do not use NLS.]), USE_NLS=no, USE_NLS=yes) AC_SUBST(USE_NLS) @@ -1670,6 +1662,37 @@ AC_CHECK_HEADERS(X11/Xmu/Xmu.h,[],[AC_MSG_ERROR([Required Xmu header missing. I AC_SUBST([LIBPYTHON]) AC_SUBST([SITEPY]) +# +# Add extra options to CFLAGS and CXXFLAGS +# +add_to_cflags() { + # Add $1 to CFLAGS and CXXFLAGS if not already there + if test -z "$1"; then return; fi + if echo "$CFLAGS" | grep -q -w -v -- "$1"; then + CFLAGS="${CFLAGS:+$CFLAGS }$1" + fi + if echo "$CXXFLAGS" | grep -q -w -v -- "$1"; then + CXXFLAGS="${CXXFLAGS:+$CXXFLAGS }$1" + fi +} + +# Always add -Wextra +add_to_cflags "-Wextra" + +# The last thing before subst-exporting CFLAGS and CXXFLAGS is to add -Werror +# if requested. Doing it earlier causes conf-tests to fail that are supposed to +# succeed when they generate warnings. +AC_ARG_ENABLE(werror, + AS_HELP_STRING( + [--enable-werror], + [Treat all compiler warnings as errors (-Werror).], + ), + [ + case "$enableval" in + (yes) add_to_cflags "-Werror" ;; + esac + ]) + AC_SUBST([CFLAGS]) AC_SUBST([CPPFLAGS]) AC_SUBST([CXXFLAGS]) From 8ba2ee3799e94e5dd23f7dab66ccbc3c1a715a5d Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Thu, 6 Feb 2025 15:07:45 +0100 Subject: [PATCH 2/2] Drop Debian 11/Bullseye from CI because C++20 is now a prerequisite. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f91553c0b6e..08f3372462a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,7 +95,7 @@ jobs: runs-on: ubuntu-24.04 strategy: matrix: - image: ["debian:bullseye", "debian:bookworm", "debian:sid"] + image: ["debian:bookworm", "debian:sid"] container: image: ${{ matrix.image }} # IPC_OWNER is needed for shmget IPC_CREAT @@ -176,7 +176,7 @@ jobs: runs-on: ubuntu-24.04 strategy: matrix: - image: ["debian:bullseye", "debian:bookworm", "debian:sid"] + image: ["debian:bookworm", "debian:sid"] container: image: ${{ matrix.image }} # IPC_OWNER is needed for shmget IPC_CREAT