From 8006635636f29cdf65e5c1ea6a092c44c9b05f36 Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Thu, 12 Nov 2015 12:24:02 +0100 Subject: [PATCH] Pass -Wno-error to linker in case of LTO builds When linking a release-built command line shell on Linux against default glibc with LTO enabled, a long-open gcc bug causes spurious warning to be emitted around a call to fread. The `-Werror` flag turns this into an error and the build process fails. Unfortunately, there is no way to selectively disable the warning with pragmas or `-Wno-error=xxx` flags. Thus, this patch introduces some helper macros and lists all warnings explicitly with `-Werror=xxx` instead of covering all warnings with the `-Werror` flag. This way, warnings enabled by command line flags do cause errors, but those raised by warning attributes (which cannot be suppressed by any `-Wno-error=xxx` flags) don't. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu --- CMakeLists.txt | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39203a85b6..f5ad2cbfb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,15 +240,31 @@ project (Jerry CXX C ASM) set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -g -gdwarf-4") # Warnings - set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wall -Wextra -pedantic") - set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wformat-nonliteral -Winit-self -Wno-stack-protector") - set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wconversion -Wsign-conversion -Wformat-security") - set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wmissing-declarations -Wno-attributes") - set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wfatal-errors") + macro(append variable value) + set(${variable} "${${variable}} ${value}") + endmacro() + + macro(add_jerry_compile_flags) + foreach(_flag ${ARGV}) + append(COMPILE_FLAGS_JERRY ${_flag}) + endforeach() + endmacro() + + macro(add_jerry_compile_warnings) + foreach(_warning ${ARGV}) + add_jerry_compile_flags(-W${_warning}) + if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + add_jerry_compile_flags(-Werror=${_warning}) + endif() + endforeach() + endmacro() + + add_jerry_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations) + add_jerry_compile_flags(-pedantic -Wno-stack-protector -Wno-attributes -Wfatal-errors) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Werror -Wlogical-op") + add_jerry_compile_warnings(logical-op) else() - set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wno-nested-anon-types") + add_jerry_compile_flags(-Wno-nested-anon-types) endif() # Static build