Skip to content

Commit 99a1d57

Browse files
committed
Merge #18750: build: optionally skip external warnings
ba8950e build: optionally skip external warnings (Vasil Dimov) Pull request description: 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. `-isystem /usr/include` bricks GCC's `#include_next`, so we use `-idirafter` instead. This way we don't have to treat `/usr/include` specially. ACKs for top commit: practicalswift: ACK ba8950e: diff looks correct! hebasto: ACK ba8950e, tested on Linux Mint 20 (x86_64). luke-jr: utACK ba8950e Tree-SHA512: 9b54fae8590be6c79f2688a5aca09e0a9067f481dabecdd49bb278c08a62ac2b0cc704c894fbd53240e77ac84da0c7a237845df0a696cfbdb0359e1c8e2e10c9
2 parents 9efa55c + ba8950e commit 99a1d57

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)
@@ -1184,11 +1206,22 @@ else
11841206

11851207
dnl sets $bitcoin_enable_qt, $bitcoin_enable_qt_test, $bitcoin_enable_qt_dbus
11861208
BITCOIN_QT_CONFIGURE([5.5.1])
1209+
1210+
dnl Keep a copy of the original $QT_INCLUDES and use it when invoking qt's moc
1211+
QT_INCLUDES_UNSUPPRESSED=$QT_INCLUDES
1212+
if test x$suppress_external_warnings != xno ; then
1213+
QT_INCLUDES=SUPPRESS_WARNINGS($QT_INCLUDES)
1214+
QT_DBUS_INCLUDES=SUPPRESS_WARNINGS($QT_DBUS_INCLUDES)
1215+
QT_TEST_INCLUDES=SUPPRESS_WARNINGS($QT_TEST_INCLUDES)
1216+
fi
11871217
fi
11881218

11891219
if test x$enable_wallet != xno; then
11901220
dnl Check for libdb_cxx only if wallet enabled
11911221
BITCOIN_FIND_BDB48
1222+
if test x$suppress_external_warnings != xno ; then
1223+
BDB_CPPFLAGS=SUPPRESS_WARNINGS($BDB_CPPFLAGS)
1224+
fi
11921225
fi
11931226

11941227
dnl Check for libminiupnpc (optional)
@@ -1243,6 +1276,10 @@ AX_BOOST_THREAD
12431276
dnl Opt-in to boost-process
12441277
AS_IF([ test x$with_boost_process != x ], [ AX_BOOST_PROCESS ], [ ax_cv_boost_process=no ] )
12451278

1279+
if test x$suppress_external_warnings != xno; then
1280+
BOOST_CPPFLAGS=SUPPRESS_WARNINGS($BOOST_CPPFLAGS)
1281+
fi
1282+
12461283
dnl Boost 1.56 through 1.62 allow using std::atomic instead of its own atomic
12471284
dnl counter implementations. In 1.63 and later the std::atomic approach is default.
12481285
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)