From a11081085b9db8ee40236d47849276db71ba0801 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 24 Jan 2013 11:18:28 -0500 Subject: [PATCH] Handle warning flags better Make --enable-werror work properly on msvc, handle extra warnings flags for msvc in configure.ac instead of hardcoding into make/msvc.mk, separate warnings flags into WFLAGS in autoconf.mk to avoid duplication and to make it easier to override. --- ChangeLog | 9 +++++++ autoconf.mk.in | 5 ++-- config-mingw32 | 2 +- config-mingw64 | 2 +- config-msvc | 2 +- configure.ac | 71 ++++++++++++++++++++++++++++---------------------- make/msvc.mk | 10 ------- 7 files changed, 55 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 308779fd..9a382293 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,15 @@ 2013-01-24 Jay Berkenbilt + * Make --enable-werror work for MSVC, and generally handle warning + options better for that compiler. Warning flags for that compiler + were previous hard-coded into the build with /WX enabled + unconditionally. + + * Split warning flags into WFLAGS in autoconf.mk to make them + easier to override. Before they were repeated in CFLAGS and + CXXFLAGS and were commingled with other compiler flags. + * qpdf --check now does syntactic checks all pages' content streams as well as checking overall document structure. Semantic errors are still not checked, and there are no plans to add diff --git a/autoconf.mk.in b/autoconf.mk.in index 630ba91e..b85faa23 100644 --- a/autoconf.mk.in +++ b/autoconf.mk.in @@ -12,12 +12,13 @@ docdir=@docdir@ htmldir=@htmldir@ pdfdir=@pdfdir CC=@CC@ -CFLAGS=@CFLAGS@ +WFLAGS=@WFLAGS@ +CFLAGS=@CFLAGS@ $(WFLAGS) LDFLAGS=@LDFLAGS@ LIBS=@LIBS@ CPPFLAGS=@CPPFLAGS@ CXX=@CXX@ -CXXFLAGS=@CXXFLAGS@ +CXXFLAGS=@CXXFLAGS@ $(WFLAGS) AR=@AR@ RANLIB=@RANLIB@ DLLTOOL=@DLLTOOL@ diff --git a/config-mingw32 b/config-mingw32 index d128e3f6..1591cdfb 100755 --- a/config-mingw32 +++ b/config-mingw32 @@ -1,5 +1,5 @@ #!/bin/sh -./configure --disable-test-compare-images --enable-external-libs --with-windows-wordsize=32 --with-buildrules=mingw +./configure --disable-test-compare-images --enable-external-libs --enable-werror --with-windows-wordsize=32 --with-buildrules=mingw # As of autoconf 2.69 and gcc 4.6, autoconf's configure fails to # recognize that defining _FILE_OFFSET_BITS works with mingw32. # Append to qpdf-config.h rather than passing CPPFLAGS on the diff --git a/config-mingw64 b/config-mingw64 index 92242fb2..68f304ec 100644 --- a/config-mingw64 +++ b/config-mingw64 @@ -1,5 +1,5 @@ #!/bin/sh -./configure --disable-test-compare-images --enable-external-libs --with-windows-wordsize=64 --with-buildrules=mingw \ +./configure --disable-test-compare-images --enable-external-libs --enable-werror --with-windows-wordsize=64 --with-buildrules=mingw \ CC=x86_64-w64-mingw32-gcc \ CXX=x86_64-w64-mingw32-g++ \ LD=x86_64-w64-mingw32-ld \ diff --git a/config-msvc b/config-msvc index a1bc2cec..db0d9876 100755 --- a/config-msvc +++ b/config-msvc @@ -8,4 +8,4 @@ objdump= if test "$wordsize" = "64"; then objdump=OBJDUMP=x86_64-w64-mingw32-objdump fi -CC=cl CXX="cl -TP -GR" ./configure --disable-test-compare-images --enable-external-libs --with-windows-wordsize=$wordsize --with-buildrules=msvc $objdump +CC=cl CXX="cl -TP -GR" ./configure --disable-test-compare-images --enable-external-libs --enable-werror --with-windows-wordsize=$wordsize --with-buildrules=msvc $objdump diff --git a/configure.ac b/configure.ac index cb95c23e..8b4c444b 100644 --- a/configure.ac +++ b/configure.ac @@ -175,39 +175,48 @@ AC_ARG_WITH(buildrules, [BUILDRULES=libtool]) AC_MSG_RESULT($BUILDRULES) -if test "$BUILDRULES" != "msvc"; then - qpdf_USE_WALL=0 - AC_MSG_CHECKING(for whether $CC supports -Wall) - oCFLAGS=$CFLAGS - CFLAGS="$CFLAGS -Wall" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[int a = 1; int b = a; a = b;]])], - [qpdf_USE_WALL=1],[qpdf_USE_WALL=0]) - if test "$qpdf_USE_WALL" = "1"; then - AC_MSG_RESULT(yes) - CXXFLAGS="$CXXFLAGS -Wall" - else - AC_MSG_RESULT(no) - CFLAGS=$oCFLAGS - fi +AC_SUBST(WFLAGS) +qpdf_USE_EXTRA_WARNINGS=0 +if test "$BUILDRULES" = "msvc"; then + dnl /w14267 makes warning 4267 a level 1 warning. This warning reports + dnl potential issues between size_t, off_t, and non-compatible integer + dnl types. + try_flags="/w14267" +else + try_flags="-Wall" +fi +AC_MSG_CHECKING(for whether $CC supports $try_flags) +oCFLAGS=$CFLAGS +CFLAGS="$CFLAGS $try_flags" +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[int a = 1; int b = a; a = b;]])], + [qpdf_USE_EXTRA_WARNINGS=1],[qpdf_USE_EXTRA_WARNINGS=0]) +CFLAGS=$oCFLAGS +if test "$qpdf_USE_EXTRA_WARNINGS" = "1"; then + AC_MSG_RESULT(yes) + WFLAGS="$try_flags" +else + AC_MSG_RESULT(no) fi -if test "$BUILDRULES" != "msvc"; then - AC_MSG_CHECKING(for whether to use -Werror) - AC_ARG_ENABLE(werror, - AS_HELP_STRING([--enable-werror], - [whether to use werror (default is no)]), - [if test "$enableval" = "yes"; then - qpdf_USE_WERROR=1; - else - qpdf_USE_WERROR=0; - fi], [qpdf_USE_WERROR=0]) - if test "$qpdf_USE_WERROR" = "1"; then - AC_MSG_RESULT(yes) - CFLAGS="$CFLAGS -Werror" - CXXFLAGS="$CXXFLAGS -Werror" - else - AC_MSG_RESULT(no) - fi +if test "$BUILDRULES" = "msvc"; then + try_flags="/WX" +else + try_flags="-Werror" +fi +AC_MSG_CHECKING(for whether to use $try_flags) +AC_ARG_ENABLE(werror, + AS_HELP_STRING([--enable-werror], + [whether to treat warnings as errors (default is no)]), + [if test "$enableval" = "yes"; then + qpdf_USE_WERROR=1; + else + qpdf_USE_WERROR=0; + fi], [qpdf_USE_WERROR=0]) +if test "$qpdf_USE_WERROR" = "1"; then + AC_MSG_RESULT(yes) + WFLAGS="$WFLAGS $try_flags" +else + AC_MSG_RESULT(no) fi AC_SUBST(QPDF_SKIP_TEST_COMPARE_IMAGES) diff --git a/make/msvc.mk b/make/msvc.mk index 5f3f69ad..5e3bb570 100644 --- a/make/msvc.mk +++ b/make/msvc.mk @@ -19,16 +19,6 @@ endef CFLAGS := $(filter-out -g,$(CFLAGS)) CXXFLAGS := $(filter-out -g,$(CXXFLAGS)) -# /WX makes all warnings errors. -CFLAGS += /WX -CXXFLAGS += /WX - -# /w14267 makes warning 4267 a level 1 warning. This warning reports -# potential issues between size_t, off_t, and non-compatible integer -# types. -CFLAGS += /w14267 -CXXFLAGS += /w14267 - clean:: $(RM) *.pdb