11

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 programmers 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.

2

5 Answers 5

12

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 
Sign up to request clarification or add additional context in comments.

3 Comments

Seems like it's a known issue: bugreports.qt-project.org/browse/QTBUG-7220
Tomáš Zato provides a clever QtCreator conditional implementation of this that gives you this while compiling without breaking the IDE integration.
@nonsensickle the bug has moved to bugreports.qt.io/browse/QTBUG-62139 (still open)
3

I just added this to my macx-clang/qmake.conf:

QMAKE_CXXFLAGS += $$join(QMAKE_INCDIR_QT, " -isystem", "-isystem")

works nicely now.

Comments

1

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...

Comments

0

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; 

Comments

-4

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

2 Comments

It might be the correct answer if the question were about CMake, but since it's about QMake you might need to check that...
@boycy, Ha! Ha! Good point! That would definitively not help with qmake. My mistake.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.