Skip to content

Commit 8006635

Browse files
committed
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 [email protected]
1 parent 140982e commit 8006635

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

CMakeLists.txt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,31 @@ project (Jerry CXX C ASM)
240240
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -g -gdwarf-4")
241241

242242
# Warnings
243-
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wall -Wextra -pedantic")
244-
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wformat-nonliteral -Winit-self -Wno-stack-protector")
245-
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wconversion -Wsign-conversion -Wformat-security")
246-
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wmissing-declarations -Wno-attributes")
247-
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wfatal-errors")
243+
macro(append variable value)
244+
set(${variable} "${${variable}} ${value}")
245+
endmacro()
246+
247+
macro(add_jerry_compile_flags)
248+
foreach(_flag ${ARGV})
249+
append(COMPILE_FLAGS_JERRY ${_flag})
250+
endforeach()
251+
endmacro()
252+
253+
macro(add_jerry_compile_warnings)
254+
foreach(_warning ${ARGV})
255+
add_jerry_compile_flags(-W${_warning})
256+
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
257+
add_jerry_compile_flags(-Werror=${_warning})
258+
endif()
259+
endforeach()
260+
endmacro()
261+
262+
add_jerry_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations)
263+
add_jerry_compile_flags(-pedantic -Wno-stack-protector -Wno-attributes -Wfatal-errors)
248264
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
249-
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Werror -Wlogical-op")
265+
add_jerry_compile_warnings(logical-op)
250266
else()
251-
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -Wno-nested-anon-types")
267+
add_jerry_compile_flags(-Wno-nested-anon-types)
252268
endif()
253269

254270
# Static build

0 commit comments

Comments
 (0)