Blame build/configure.ac.warnings

Packit 324a5c
dnl Use lots of warning flags with with gcc and compatible compilers
Packit 324a5c
Packit 324a5c
dnl Note: if you change the following variable, the cache is automatically
Packit 324a5c
dnl skipped and all flags rechecked.  So there's no need to do anything
Packit 324a5c
dnl else.  If for any reason you need to force a recheck, just change
Packit 324a5c
dnl MAYBE_WARN in an ignorable way (like adding whitespace)
Packit 324a5c
Packit 324a5c
# -Wcast-align generates lots of false positive reports we need to
Packit 324a5c
# cast image data from uint8_t to uin32_t.
Packit 324a5c
Packit 324a5c
# -Wlogical-op causes too much noise from strcmp("literal", str)
Packit 324a5c
Packit 324a5c
MAYBE_WARN="-Wall -Wextra \
Packit 324a5c
-Wmissing-declarations -Werror-implicit-function-declaration \
Packit 324a5c
-Wpointer-arith -Wwrite-strings -Wsign-compare -Wpacked \
Packit 324a5c
-Wswitch-enum -Wmissing-format-attribute -Wvolatile-register-var \
Packit 324a5c
-Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
Packit 324a5c
-Wno-missing-field-initializers -Wno-unused-parameter \
Packit 324a5c
-Wno-attributes -Wno-long-long -Winline"
Packit 324a5c
Packit 324a5c
MAYBE_C_SPECIFIC_WARN="-Wold-style-definition \
Packit 324a5c
-Wdeclaration-after-statement -Wstrict-prototypes \
Packit 324a5c
-Wmissing-prototypes -Wbad-function-cast -Wnested-externs"
Packit 324a5c
Packit 324a5c
# New -Wno options should be added here
Packit 324a5c
# gcc-4.4 and later accept every -Wno- option but may complain later that this
Packit 324a5c
# option is unknow each time another warning happen.
Packit 324a5c
# -Wunused-but-set-variable is too noisy at present
Packit 324a5c
NO_WARN="unused-but-set-variable"
Packit 324a5c
Packit 324a5c
dnl Sun Studio 12 likes to rag at us for abusing enums like
Packit 324a5c
dnl having cairo_status_t variables hold cairo_int_status_t
Packit 324a5c
dnl values.  It's bad, we know.  Now please be quiet.
Packit 324a5c
MAYBE_WARN="$MAYBE_WARN -erroff=E_ENUM_TYPE_MISMATCH_ARG \
Packit 324a5c
			-erroff=E_ENUM_TYPE_MISMATCH_OP"
Packit 324a5c
Packit 324a5c
dnl We also abuse the warning-flag facility to enable other compiler
Packit 324a5c
dnl options.  Namely, the following:
Packit 324a5c
MAYBE_WARN="$MAYBE_WARN -fno-strict-aliasing -fno-common"
Packit 324a5c
Packit 324a5c
dnl Also to turn various gcc/glibc-specific preprocessor checks
Packit 324a5c
MAYBE_WARN="$MAYBE_WARN -Wp,-D_FORTIFY_SOURCE=2"
Packit 324a5c
Packit 324a5c
# invalidate cached value if MAYBE_WARN has changed
Packit 324a5c
if test "x$cairo_cv_warn_maybe" != "x$MAYBE_WARN"; then
Packit 324a5c
	unset cairo_cv_warn_cflags
Packit 324a5c
fi
Packit 324a5c
AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [
Packit 324a5c
	echo
Packit 324a5c
	WARN_CFLAGS=""
Packit 324a5c
Packit 324a5c
	# Some warning options are not supported by all versions of
Packit 324a5c
	# gcc, so test all desired options against the current
Packit 324a5c
	# compiler.
Packit 324a5c
	#
Packit 324a5c
	# Note that there are some order dependencies
Packit 324a5c
	# here. Specifically, an option that disables a warning will
Packit 324a5c
	# have no net effect if a later option then enables that
Packit 324a5c
	# warnings, (perhaps implicitly). So we put some grouped
Packit 324a5c
	# options (-Wall and -Wextra) up front and the -Wno options
Packit 324a5c
	# last.
Packit 324a5c
Packit 324a5c
	for W in $MAYBE_WARN; do
Packit 324a5c
		CAIRO_CC_TRY_FLAG([$W],, [WARN_CFLAGS="$WARN_CFLAGS $W"])
Packit 324a5c
	done
Packit 324a5c
	for W in $NO_WARN; do
Packit 324a5c
		CAIRO_CC_TRY_FLAG([-W$W -Wno-$W],, [WARN_CFLAGS="$WARN_CFLAGS -Wno-$W"])
Packit 324a5c
	done
Packit 324a5c
	cairo_cv_warn_cflags=$WARN_CFLAGS
Packit 324a5c
	cairo_cv_warn_maybe="$MAYBE_WARN $MAYBE_C_SPECIFIC_WARN"
Packit 324a5c
Packit 324a5c
	AC_MSG_CHECKING([which warning flags were supported])
Packit 324a5c
])
Packit 324a5c
WARN_CFLAGS="$cairo_cv_warn_cflags"
Packit 324a5c
CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
Packit 324a5c
Packit 324a5c
# We only wish to enable attribute(warn_unused_result) if we can prevent
Packit 324a5c
# gcc from generating thousands of warnings about the misapplication of the
Packit 324a5c
# attribute to void functions and variables.
Packit 324a5c
AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [
Packit 324a5c
        AC_REQUIRE([AC_PROG_GREP])
Packit 324a5c
	cairo_cv_warn_unused_result=""
Packit 324a5c
	if echo $WARN_CFLAGS | $GREP -e '-Wno-attributes' >/dev/null; then
Packit 324a5c
	    CAIRO_CC_TRY_FLAG_SILENT(
Packit 324a5c
			[-Wno-attributes],
Packit 324a5c
			[__attribute__((__warn_unused_result__)) void f (void) {}
Packit 324a5c
			 __attribute__((__warn_unused_result__)) int g;],
Packit 324a5c
			[cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
Packit 324a5c
	fi
Packit 324a5c
])
Packit 324a5c
AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result],
Packit 324a5c
	  [Define to the value your compiler uses to support the warn-unused-result attribute])
Packit 324a5c
Packit 324a5c
dnl check linker flags
Packit 324a5c
AC_CACHE_CHECK([how to allow undefined symbols in shared libraries used by test suite], cairo_cv_test_undefined_ldflags,
Packit 324a5c
	       [CAIRO_CC_TRY_FLAG_SILENT([-Wl,--allow-shlib-undefined], [],
Packit 324a5c
				  [cairo_cv_test_undefined_ldflags="-Wl,--allow-shlib-undefined]")])
Packit 324a5c
CAIRO_TEST_UNDEFINED_LDFLAGS="$cairo_cv_test_undefined_ldflags"
Packit 324a5c
AC_SUBST(CAIRO_TEST_UNDEFINED_LDFLAGS)