There is a QMake variable called QMAKE_CXXFLAGS_WARN_ON
which is included into CXXFLAGS
whenever CONFIG
contains warn_on
.
So my project files all include a common.pri
which contains:
CONFIG += warn_on
dirty_build: CONFIG += noopt
!dirty_build: WARNINGS += -Werror
# Turn on warnings, except for code that is Qt-generated
WARNINGS += -Wextra
WARNINGS += -Wunknown-pragmas -Wundef
WARNINGS += -Wold-style-cast
WARNINGS += -Wdisabled-optimization -Wstrict-overflow=4
WARNINGS += -Weffc++ -Wuseless-cast
WARNINGS += -Winit-self -Wpointer-arith
WARNINGS += -Wlogical-op
WARNINGS += -Wunsafe-loop-optimizations -Wno-error=unsafe-loop-optimizations
QMAKE_CXXFLAGS_WARN_ON += $(and $(filter-out moc_% qrc_%, $@),$${WARNINGS})
The filter-out
exists to disable the warnings for Qt-generated meta-object and resource files.
I also have
# Override the C and C++ targets to selectively replace -I with -isystem for include paths
QMAKE_RUN_CC = $(CC) -o $obj -c $(CFLAGS) $(subst -I/usr/include,-isystem /usr/include,$(INCPATH)) $src
QMAKE_RUN_CC_IMP = $(CC) -o $@ -c $(CFLAGS) $(subst -I/usr/include,-isystem /usr/include,$(INCPATH)) $<
QMAKE_RUN_CXX = $(CXX) -o $obj -c $(CXXFLAGS) $(subst -I/usr/include,-isystem /usr/include,$(INCPATH)) $src
QMAKE_RUN_CXX_IMP = $(CXX) -o $@ -c $(CXXFLAGS) $(subst -I/usr/include,-isystem /usr/include,$(INCPATH)) $<
That allows me to enable -Weffc++
and others without incurring lots of messages from installed header files.