mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-03 07:00:15 +01:00
[build] Refine the -Wno-attribute test to check our use cases.
We don't actually check that -Wno-attribute does what we think it does. On clang it doesn't since it happily seems to recognize but ignore the attribute. This patch factors out a silent version of CAIRO_CC_TRY_FLAG which accepts an optional program argument and actually tests that the compiler doesn't produce any warning messages. It is then used to check that -Wno-attribute doesn't complain when the __warn_unused_result__ attribute is applied to void functions or variables.
This commit is contained in:
parent
c87b366bfe
commit
f081a5ff55
3 changed files with 43 additions and 15 deletions
|
|
@ -75,21 +75,47 @@ AC_DEFUN([CAIRO_CONFIG_COMMANDS],
|
|||
], $3)
|
||||
])
|
||||
|
||||
dnl check compiler flags
|
||||
AC_DEFUN([CAIRO_CC_TRY_FLAG],
|
||||
[dnl
|
||||
AC_MSG_CHECKING([whether $CC supports $1])
|
||||
dnl check compiler flags with a program and no muttering.
|
||||
AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
|
||||
[dnl (flags..., optional program, true-action, false-action)
|
||||
|
||||
_compile_program='$2'
|
||||
if test "x$_compile_program" = "x"; then
|
||||
# AC_LANG_PROGRAM() produces a main() w/o args,
|
||||
# but -Wold-style-definition doesn't like that.
|
||||
# We need _some_ program so that we don't get
|
||||
# warnings about empty compilation units.
|
||||
_compile_program='
|
||||
int main(int c, char **v) {
|
||||
(void)c; (void)v; return 0; }'
|
||||
fi
|
||||
|
||||
_save_cflags="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -Werror $1"
|
||||
AC_COMPILE_IFELSE([ ], [cairo_cc_flag=yes], [cairo_cc_flag=no])
|
||||
CFLAGS="$CFLAGS $1"
|
||||
AC_COMPILE_IFELSE(
|
||||
[$_compile_program],
|
||||
[cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
|
||||
cairo_cc_flag=yes],
|
||||
[cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
|
||||
cairo_cc_flag=no])
|
||||
CFLAGS="$_save_cflags"
|
||||
|
||||
if test "x$cairo_cc_flag" = "xyes"; then
|
||||
ifelse([$2], , :, [$2])
|
||||
else
|
||||
ifelse([$3], , :, [$3])
|
||||
if test "x$cairo_cc_stderr" != "x"; then
|
||||
cairo_cc_flag=no
|
||||
fi
|
||||
|
||||
if test "x$cairo_cc_flag" = "xyes"; then
|
||||
ifelse([$3], , :, [$3])
|
||||
else
|
||||
ifelse([$4], , :, [$4])
|
||||
fi
|
||||
])
|
||||
|
||||
dnl check compiler flags possibly using -Werror if available.
|
||||
AC_DEFUN([CAIRO_CC_TRY_FLAG],
|
||||
[dnl (flags..., optional program, true-action, false-action)
|
||||
AC_MSG_CHECKING([whether $CC supports $1])
|
||||
CAIRO_CC_TRY_FLAG_SILENT([-Werror $1], [$2], [$3], [$4])
|
||||
AC_MSG_RESULT([$cairo_cc_flag])
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ dnl PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/Makefile.gcov, $abs_srcdir)
|
|||
dnl In order to workaround a debian bug in libtool where they strip
|
||||
dnl $dependency_libs from the link line and CFLAGS, we need to pass
|
||||
dnl --coverage via LDFLAGS.
|
||||
CAIRO_CC_TRY_FLAG([--coverage],
|
||||
CAIRO_CC_TRY_FLAG([--coverage],,
|
||||
[
|
||||
CAIRO_CFLAGS="$CAIRO_CFLAGS -O0 --coverage"
|
||||
CAIRO_LDFLAGS="$CAIRO_LDFLAGS -O0 --coverage"
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [
|
|||
# last.
|
||||
|
||||
for W in $MAYBE_WARN; do
|
||||
CAIRO_CC_TRY_FLAG([$W], [WARN_CFLAGS="$WARN_CFLAGS $W"])
|
||||
CAIRO_CC_TRY_FLAG([$W],, [WARN_CFLAGS="$WARN_CFLAGS $W"])
|
||||
done
|
||||
|
||||
cairo_cv_warn_cflags=$WARN_CFLAGS
|
||||
|
|
@ -63,9 +63,11 @@ CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
|
|||
AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [
|
||||
cairo_cv_warn_unused_result=""
|
||||
if echo $WARN_CFLAGS | grep -e '-Wno-attributes' >/dev/null; then
|
||||
AC_TRY_COMPILE([__attribute__((__warn_unused_result__))
|
||||
int f (int i) { return i; }], [],
|
||||
[cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
|
||||
CAIRO_CC_TRY_FLAG_SILENT(
|
||||
[-Wno-attributes],
|
||||
[__attribute__((__warn_unused_result__)) void f (void) {}
|
||||
__attribute__((__warn_unused_result__)) int g;],
|
||||
[cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
|
||||
fi
|
||||
])
|
||||
AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue