I use qmake as a makefile builder and want to stick to it. Further I would like to use "gcc -Wall -Werror -Wundef -Wextra" to get robust code. I'm thinking about "-pedantic" but that's further up the road. My main problem at the moment are the tons of warnings generated by libraries like boost, parts of qt and the like.
At the moment I use pragmas whenever I include warning-generating headers
#pragma GCC diagnostic ignored "-Wall"
#include <QtGui>
...
#include <QWidget>
#pragma GCC diagnostic error "-Wall"
This is far from cute, rather tedious and cumbersome especially as other programm开发者_StackOverflow中文版ers have to do so too. Is there an option using qmake that allows to include qt-libraries as system headers, thus supressing their warnings. For plain makefiles and cmake I knwow -isystem but I cannot find a qmake pendant for this.
Easiest way I found is including directly via QMAKE_CXXFLAGS e.g. for Boost this looks like the following in the project file
QMAKE_CXXFLAGS += -isystem /usr/local/boost_1_44_0
I just added this to my macx-clang/qmake.conf:
QMAKE_CXXFLAGS += $$join(QMAKE_INCDIR_QT, " -isystem", "-isystem")
works nicely now.
Since many settings are hardcoded into spec files, I think you need to create your own. Start with reading mkspecs/linux-g++/qmake.conf or mkspecs/win32-g++/qmake.conf
You will see that by default CONFIG uses warn_on setting. and in mkspecs/common/g++ you have
QMAKE_CFLAGS_WARN_ON += -Wall -W
QMAKE_CFLAGS_WARN_OFF += -w
QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF
so you can change the spec file and make new settings default for every project, or you can set this variables in your project file.
CONFIG += warn_on
QMAKE_CFLAGS_WARN_ON = -Wall -Werror -Wundef -Wextra -pedantic
QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON
qt include path is hardcoded in mkspecs/features/qt.prf as
#handle includes
INCLUDEPATH = $$QMAKE_INCDIR_QT $$INCLUDEPATH #prepending prevents us from picking up "stale" includes
You don't want QMAKE_INCDIR_QT to be a part of INCLUDEPATH since its components are joined with -I. You want to expand it as $$join(QMAKE_INCDIR_QT, " -isystem", "-isystem") somewhere else...
Came up with a workaround: manually changing Makefile.
Add this line to .pro file
system(./suppress_system_warnings.sh)
And then create an executable file suppress_system_warnings.sh
#!/bin/bash
run_in_background() {
pidof qmake > /dev/null
while [ $? -eq 0 ]
do
sleep 0.2
pidof qmake > /dev/null
done
file=Makefile
new_line=$( grep ^INCPATH $file | sed 's:-I\/:-isystem\/:g' | sed 's:-I\$:-isystem\$:' )
line_num=$( grep -n ^INCPATH $file | cut -d':' -f1 )
head -n $(expr $line_num - 1) $file > __tmp
echo $new_line >> __tmp
tail -n +$(expr $line_num + 1) $file >> __tmp
mv __tmp $file
exit 0;
}
run_in_background &
exit 0;
Note that the correct answer to this one is to use the SYSTEM keyword in the include_target() macro:
include_directories(SYSTEM ${QT_INCLUDES})
This works for many libraries, not just Qt which I could use without too much problems. But the Magic++.h is really a horrible piece of work in comparison and I had to have this capability.
You can find more information on this question:
Use -isystem instead of -I with CMake
精彩评论