1 dnl Use lots of warning flags with with gcc and compatible compilers
3 dnl Note: if you change the following variable, the cache is automatically
4 dnl skipped and all flags rechecked. So there's no need to do anything
5 dnl else. If for any reason you need to force a recheck, just change
6 dnl MAYBE_WARN in an ignorable way (like adding whitespace)
8 MAYBE_WARN="-Wall -Wextra \
9 -Wsign-compare -Werror-implicit-function-declaration \
10 -Wpointer-arith -Wwrite-strings -Wstrict-prototypes \
11 -Wmissing-prototypes -Wmissing-declarations -Wnested-externs \
12 -Wpacked -Wswitch-enum -Wmissing-format-attribute \
13 -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
14 -Wdeclaration-after-statement -Wold-style-definition \
15 -Wno-missing-field-initializers -Wno-unused-parameter \
16 -Wno-attributes -Wno-long-long -Winline"
18 dnl We also abuse the warning-flag facility to enable other compiler
19 dnl options. Namely, the following:
20 MAYBE_WARN="$MAYBE_WARN -fno-strict-aliasing -fno-common"
22 dnl Also to turn various gcc/glibc-specific preprocessor checks
23 MAYBE_WARN="$MAYBE_WARN -Wp,-D_FORTIFY_SOURCE=2"
25 # invalidate cached value if MAYBE_WARN has changed
26 if test "x$cairo_cv_warn_maybe" != "x$MAYBE_WARN"; then
27 unset cairo_cv_warn_cflags
29 AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [
33 # Some warning options are not supported by all versions of
34 # gcc, so test all desired options against the current
37 # Note that there are some order dependencies
38 # here. Specifically, an option that disables a warning will
39 # have no net effect if a later option then enables that
40 # warnings, (perhaps implicitly). So we put some grouped
41 # options (-Wall and -Wextra) up front and the -Wno options
44 for W in $MAYBE_WARN; do
45 CAIRO_CC_TRY_FLAG([$W], [WARN_CFLAGS="$WARN_CFLAGS $W"])
48 cairo_cv_warn_cflags=$WARN_CFLAGS
49 cairo_cv_warn_maybe=$MAYBE_WARN
51 AC_MSG_CHECKING([which warning flags were supported])
53 WARN_CFLAGS="$cairo_cv_warn_cflags"
54 CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
56 # We only wish to enable attribute(warn_unused_result) if we can prevent
57 # gcc from generating thousands of warnings about the misapplication of the
58 # attribute to void functions and variables.
59 AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [
60 cairo_cv_warn_unused_result=""
61 if echo $WARN_CFLAGS | grep -e '-Wno-attributes' >/dev/null; then
62 AC_TRY_COMPILE([__attribute__((__warn_unused_result__))
63 int f (int i) { return i; }], [],
64 [cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
67 AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result],
68 [Define to the value your compiler uses to support the warn-unused-result attribute])
70 dnl check linker flags
71 AC_CACHE_CHECK([how to allow undefined symbols in shared libraries used by test suite], cairo_cv_test_undefined_ldflags,
72 [CAIRO_CC_TRY_LINK_FLAG([-Wl,--allow-shlib-undefined],
73 [cairo_cv_test_undefined_ldflags="-Wl,--allow-shlib-undefined]")])
74 CAIRO_TEST_UNDEFINED_LDFLAGS="$cairo_cv_test_undefined_ldflags"
75 AC_SUBST(CAIRO_TEST_UNDEFINED_LDFLAGS)