7

I am involved with a software project written in Qt and built with qmake and gcc on Linux. We have to link to a third-party library that is of fairly low quality and spews tons of warnings. I would like to use -W -Wall on our source code, but pass -w to the nasty third-party library to keep the console free of noise and clutter so we can focus on our code quality.

In qmake, is there a way to conditionally add CFLAGS/CXXFLAGS to certain files and libraries?

Kevin Bowling
  • 323
  • 4
  • 11

5 Answers5

7

Jonathan, I think the problem is where your source files are including header files from 3rd party libraries, and you want to switch off the warnings for the latter.

Kevin, i think you can use pragmas to control warnings : gcc diagnostic pragmas

You could add these before and after any #includes for 3rd party libs.

jon hanson
  • 8,722
  • 2
  • 37
  • 61
  • Correct, the warnings come from the third-party headers. I will look into pragmas, but is there a way I can inject them only into the third-party headers, or will I have to edit their headers? – Kevin Bowling Apr 22 '09 at 11:47
  • 1
    You could introduce header wrappers for the third party headers. One brute-force approach would be to put any include for a third party header into a single header, then your app just includes that header where necessary. E.g. if your App uses library Zed then create a zed.h header which includes all Zed headers. Then you can add the pragmas to zed.h. Or just go through your code and surround each #include with pragmas. – jon hanson Apr 22 '09 at 12:03
3

What if you include your library using -isystem.

In the project file e.g.:

QMAKE_CXXFLAGS += -isystem /usr/local/boost_1_44_0
Martin
  • 4,738
  • 4
  • 28
  • 57
0

Kevin,

qmake CONFIG+=debug QMAKE_CXXFLAGS_WARN_ON=-w QMAKE_CFLAGS_WARN_ON=-w

should do (use CONFIG+=release if you wish...)

Pato
  • 9
  • 1
0

Normally, you'd build the third-party library in a separate directory from your own code, so you would have a different makefile for it, so you could put a different set of flags for that compilation.

If you've mixed the third-party library code with your own code, you have set yourself up for a maintenance nightmare.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0

As Martin wrote adding the include directory via

QMAKE_CXXFLAGS += -isystem ...

suppresses warnings just in the respective headers. No need to disable warnings for any source files of your project (or even project-wide) or mess with #pragmas or wrappers files.

Note that if you're using QtCreator you'll still (i.e. additionally) want add the directory to INCLUDEPATH so the indexer picks up the headers.

user686249
  • 669
  • 6
  • 17