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
This commit is contained in:
Akos Kiss
2015-11-12 12:24:02 +01:00
parent 140982e900
commit 8006635636
+23 -7
View File
@@ -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