]> xenbits.xensource.com Git - libvirt.git/commitdiff
Correctly detect warning flags with clang
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 13 May 2013 11:45:54 +0000 (12:45 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 14 May 2013 14:00:22 +0000 (15:00 +0100)
Clang will happily claim to support any warning flags
unless the -Werror and -Wunknown-warning-option flags
are set. Thus we need to make sure these are set when
testing for clags.

We must also set the clang specific warning flags
-Wno-unused-command-line-argument to avoid a warning
from the ssp-buffer-size flag when linking .o files.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
m4/virt-compile-warnings.m4

index fbeb3eb5e1c3d14555b6792f62e8215b216952fb..59091a6a526d9a9f68b70b3cf805e4dc2e045f86 100644 (file)
@@ -60,6 +60,18 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     # gcc 4.4.6 complains this is C++ only; gcc 4.7.0 implies this from -Wall
     dontwarn="$dontwarn -Wenum-compare"
 
+    # clang rather horribly ignores unknown warning flags by
+    # default. Thus to get gl_WARN_ADD to reliably detect
+    # flags, we need to set '-Werror -Wunknown-warning-option'
+    # in CFLAGS while probing support
+    WARN_CFLAGS=
+    orig_CFLAGS="$CFLAGS"
+    gl_WARN_ADD([-Wunknown-warning-option])
+    if test -n "$WARN_CFLAGS" ; then
+        WARN_CFLAGS=
+        CFLAGS="-Werror -Wunknown-warning-option $CFLAGS"
+    fi
+
     # gcc 4.2 treats attribute(format) as an implicit attribute(nonnull),
     # which triggers spurious warnings for our usage
     AC_CACHE_CHECK([whether gcc -Wformat allows NULL strings],
@@ -179,12 +191,19 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     dnl -fstack-protector stuff passes gl_WARN_ADD with gcc
     dnl on Mingw32, but fails when actually used
     case $host in
-       *-*-linux*)
+       *-*-linux*|*-*-freebsd*)
        dnl Fedora only uses -fstack-protector, but doesn't seem to
        dnl be great overhead in adding -fstack-protector-all instead
        dnl gl_WARN_ADD([-fstack-protector])
        gl_WARN_ADD([-fstack-protector-all])
        gl_WARN_ADD([--param=ssp-buffer-size=4])
+       dnl Even though it supports it, clang complains about
+       dnl use of --param=ssp-buffer-size=4 unless used with
+       dnl the -c arg. It doesn't like it when used with args
+       dnl that just link together .o files. Unfortunately
+       dnl we can't avoid that with automake, so we must turn
+       dnl off the following clang specific warning
+       gl_WARN_ADD([-Wno-unused-command-line-argument])
        ;;
     esac
     gl_WARN_ADD([-fexceptions])
@@ -222,4 +241,7 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
       AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP], 1,
        [Define to 1 if gcc -Wlogical-op reports false positives on strchr])
     fi
+
+    # Remove stuff we set for clang
+    CFLAGS="$orig_CFLAGS"
 ])