I’m working on a project that uses lots of external libraries. Now, I like my projects to compile with the highest warning level available, which on MSVC is /W4. I’m also using -Wall on GCC for this project, which needs to be cross-platform.
With /W4, I’m hitting a problem: I’m often including the headers of the other libraries, and those headers were not written to conform to /W4 (that is, they throw lots of warnings). There’s nothing I can do about them so I’d rather not see them. They just end up as noise.
Currently I’m doing this to temporarily lower the warning level:
#if defined(_MSC_VER)
# pragma warning( push, 3 )
#endif
#include <SomeExternalHeader.h>
#if defined(_MSC_VER)
# pragma warning( pop )
#endif
Including these six lines for every (different) group of external headers I want to include across the various files is getting tiresome. Can I somehow #define a macro that I can then use for these external headers? I’d like something like the following:
INCLUDE_EXTERNAL_HEADER(<SomeExternalHeader.h>)
This would then wrap the #include with the required lines. Is this possible? My gut instinct tells me that wouldn’t work because it would require running the preprocessor twice.
What would be the best way to deal with this problem?
I’m not aware of a single line solution like the one you want but MSVC does have a
__pragmakeyword that you can use inside a preprocessor macro.So you can do something like this:
P.S.: I’ve never used the
__pragmaform so I don’t know for sure whether thepragmadirective syntax above is correct.