Skip to content

Commit ba8950e

Browse files
committed
build: optionally skip external warnings
Add an option to `./configure` to suppress compilation warnings from external headers. The option is off by default (no change in behavior, show warnings from external headers). This option is useful if e.g. Boost or Qt is installed outside of `/usr/include` (warnings from headers in `/usr/include` are already suppressed by default) and those warnings stand in the way of compiling Bitcoin Core with `-Werror[=...]` or they just clutter the build output too much and make our own warnings hard to spot.
1 parent bab4cce commit ba8950e

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

configure.ac

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ AC_ARG_ENABLE([ccache],
190190
[use_ccache=$enableval],
191191
[use_ccache=auto])
192192

193+
dnl Suppress warnings from external headers (e.g. Boost, Qt).
194+
dnl May be useful if warnings from external headers clutter the build output
195+
dnl too much, so that it becomes difficult to spot Bitcoin Core warnings
196+
dnl or if they cause a build failure with --enable-werror.
197+
AC_ARG_ENABLE([suppress-external-warnings],
198+
[AS_HELP_STRING([--enable-suppress-external-warnings],
199+
[Suppress warnings from external headers (default is no)])],
200+
[suppress_external_warnings=$enableval],
201+
[suppress_external_warnings=no])
202+
193203
AC_ARG_ENABLE([lcov],
194204
[AS_HELP_STRING([--enable-lcov],
195205
[enable lcov testing (default is no)])],
@@ -1149,6 +1159,18 @@ AC_SUBST(LEVELDB_CPPFLAGS)
11491159
AC_SUBST(LIBLEVELDB)
11501160
AC_SUBST(LIBMEMENV)
11511161

1162+
dnl SUPPRESSED_CPPFLAGS=SUPPRESS_WARNINGS([$SOME_CPPFLAGS])
1163+
dnl Replace -I with -isystem in $SOME_CPPFLAGS to suppress warnings from
1164+
dnl headers from its include directories and return the result.
1165+
dnl See -isystem documentation:
1166+
dnl https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
1167+
dnl https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-isystem-directory
1168+
dnl Do not change "-I/usr/include" to "-isystem /usr/include" because that
1169+
dnl is not necessary (/usr/include is already a system directory) and because
1170+
dnl it would break GCC's #include_next.
1171+
AC_DEFUN([SUPPRESS_WARNINGS],
1172+
[$(echo $1 |${SED} -E -e 's/(^| )-I/\1-isystem /g' -e 's;-isystem /usr/include([/ ]|$);-I/usr/include\1;g')])
1173+
11521174
dnl enable-fuzz should disable all other targets
11531175
if test "x$enable_fuzz" = "xyes"; then
11541176
AC_MSG_WARN(enable-fuzz will disable all other targets)
@@ -1170,11 +1192,22 @@ else
11701192

11711193
dnl sets $bitcoin_enable_qt, $bitcoin_enable_qt_test, $bitcoin_enable_qt_dbus
11721194
BITCOIN_QT_CONFIGURE([5.5.1])
1195+
1196+
dnl Keep a copy of the original $QT_INCLUDES and use it when invoking qt's moc
1197+
QT_INCLUDES_UNSUPPRESSED=$QT_INCLUDES
1198+
if test x$suppress_external_warnings != xno ; then
1199+
QT_INCLUDES=SUPPRESS_WARNINGS($QT_INCLUDES)
1200+
QT_DBUS_INCLUDES=SUPPRESS_WARNINGS($QT_DBUS_INCLUDES)
1201+
QT_TEST_INCLUDES=SUPPRESS_WARNINGS($QT_TEST_INCLUDES)
1202+
fi
11731203
fi
11741204

11751205
if test x$enable_wallet != xno; then
11761206
dnl Check for libdb_cxx only if wallet enabled
11771207
BITCOIN_FIND_BDB48
1208+
if test x$suppress_external_warnings != xno ; then
1209+
BDB_CPPFLAGS=SUPPRESS_WARNINGS($BDB_CPPFLAGS)
1210+
fi
11781211
fi
11791212

11801213
dnl Check for libminiupnpc (optional)
@@ -1229,6 +1262,10 @@ AX_BOOST_THREAD
12291262
dnl Opt-in to boost-process
12301263
AS_IF([ test x$with_boost_process != x ], [ AX_BOOST_PROCESS ], [ ax_cv_boost_process=no ] )
12311264

1265+
if test x$suppress_external_warnings != xno; then
1266+
BOOST_CPPFLAGS=SUPPRESS_WARNINGS($BOOST_CPPFLAGS)
1267+
fi
1268+
12321269
dnl Boost 1.56 through 1.62 allow using std::atomic instead of its own atomic
12331270
dnl counter implementations. In 1.63 and later the std::atomic approach is default.
12341271
m4_pattern_allow(DBOOST_AC_USE_STD_ATOMIC) dnl otherwise it's treated like a macro

src/Makefile.qt.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ ui_%.h: %.ui
379379
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(UIC) -o $@ $< || (echo "Error creating $@"; false)
380380

381381
%.moc: %.cpp
382-
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(MOC) $(DEFAULT_INCLUDES) $(QT_INCLUDES) $(MOC_DEFS) $< | \
382+
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(MOC) $(DEFAULT_INCLUDES) $(QT_INCLUDES_UNSUPPRESSED) $(MOC_DEFS) $< | \
383383
$(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $@
384384

385385
moc_%.cpp: %.h
386-
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(MOC) $(DEFAULT_INCLUDES) $(QT_INCLUDES) $(MOC_DEFS) $< | \
386+
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(MOC) $(DEFAULT_INCLUDES) $(QT_INCLUDES_UNSUPPRESSED) $(MOC_DEFS) $< | \
387387
$(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $@
388388

389389
%.qm: %.ts

0 commit comments

Comments
 (0)