From f8c0691313baf144522d87d5a67cdf5f9f551558 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Fri, 24 Jul 2020 19:33:55 -0700 Subject: [PATCH] GNU Make option to turn warnings into errors Add `WARN_ERROR` (with default of `FALSE`) to the GNU Make system to turn warnings into errors for GCC and Clang. Add `WARN_ERROR` to the 2d and 3d CIs using GNU Make. --- .github/workflows/linux.yml | 4 ++-- Docs/sphinx_documentation/source/BuildingAMReX.rst | 3 ++- Tools/GNUMake/Make.defs | 6 ++++++ Tools/GNUMake/comps/gnu.mak | 5 +++++ Tools/GNUMake/comps/llvm.mak | 5 +++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 05c068d4b13..55a6afea1b5 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -205,7 +205,7 @@ jobs: - name: Build & Install run: | ./configure --dim 2 --with-fortran no --comp llvm --with-mpi no - make -j2 WARN_ALL=TRUE + make -j2 WARN_ALL=TRUE WARN_ERROR=TRUE make install # Build 3D libamrex with configure @@ -219,5 +219,5 @@ jobs: - name: Build & Install run: | ./configure --dim 3 --enable-eb yes --enable-xsdk-defaults yes - make -j2 WARN_ALL=TRUE + make -j2 WARN_ALL=TRUE WARN_ERROR=TRUE make install diff --git a/Docs/sphinx_documentation/source/BuildingAMReX.rst b/Docs/sphinx_documentation/source/BuildingAMReX.rst index 32cd90fe7c2..7b3bc469112 100644 --- a/Docs/sphinx_documentation/source/BuildingAMReX.rst +++ b/Docs/sphinx_documentation/source/BuildingAMReX.rst @@ -112,7 +112,8 @@ If enabled, the library path at link time will be saved as a When disabled, dynamic library paths could be provided via ``export LD_LIBRARY_PATH`` hints at runtime. -For GCC and Clang, the variable ``WARN_ALL`` controls the compiler's warning options. +For GCC and Clang, the variable ``WARN_ALL`` controls the compiler's warning options. There is +also a make variable ``WARN_ERROR`` (with default of ``FALSE``) to turn warnings into errors. After defining these make variables, a number of files, ``Make.defs, Make.package`` and ``Make.rules``, are included in the GNUmakefile. AMReX-based diff --git a/Tools/GNUMake/Make.defs b/Tools/GNUMake/Make.defs index 26e6f9461d2..5b4e89d1dff 100644 --- a/Tools/GNUMake/Make.defs +++ b/Tools/GNUMake/Make.defs @@ -304,6 +304,12 @@ else endif endif +ifdef WARN_ERROR + WARN_ERROR := $(strip $(WARN_ERROR)) +else + WARN_ERROR := FALSE +endif + ifdef USE_GPU_PRAGMA USE_GPU_PRAGMA := $(strip $(USE_GPU_PRAGMA)) GPU_PRAGMA_NO_HOST_VERSION ?= FALSE diff --git a/Tools/GNUMake/comps/gnu.mak b/Tools/GNUMake/comps/gnu.mak index 08ea1bc4e0c..e609463d6b7 100644 --- a/Tools/GNUMake/comps/gnu.mak +++ b/Tools/GNUMake/comps/gnu.mak @@ -113,6 +113,11 @@ ifeq ($(WARN_ALL),TRUE) CFLAGS += $(warning_flags) endif +ifeq ($(WARN_ERROR),TRUE) + CXXFLAGS += -Werror + CFLAGS += -Werror +endif + ifeq ($(USE_GPROF),TRUE) CXXFLAGS += -pg CFLAGS += -pg diff --git a/Tools/GNUMake/comps/llvm.mak b/Tools/GNUMake/comps/llvm.mak index b8ad8cc3e90..74429485819 100644 --- a/Tools/GNUMake/comps/llvm.mak +++ b/Tools/GNUMake/comps/llvm.mak @@ -55,6 +55,11 @@ ifeq ($(WARN_ALL),TRUE) CFLAGS += $(warning_flags) endif +ifeq ($(WARN_ERROR),TRUE) + CXXFLAGS += -Werror + CFLAGS += -Werror +endif + ######################################################################## ifdef CXXSTD