I'm working on an Objective-C wrapper around a C++ library, whose source I neither control nor modify. The headers I import trigger various compiler warnings, so I've started to do the following:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#pragma clang diagnostic ignored "-Wstrict-prototypes"
#import "dll.hpp"
#pragma clang diagnostic pop
This works great, but to keep it DRY, I'd like to define a macro for each of these imports with the ignored warning pragmas built in (there are only a few headers like this).
This way, in each file I could just make a call like this at the top and I'd have the ignored warnings all in one spot for each header.
ImportDllHpp()
It's not so easy, however, calling #import
from within a #define
. I've gotten pretty close, using this answer to get the pragmas working. But is there a function like _Pragma
for #import
or another way to achieve that?
This is what I have so far:
#define _stringify(a) #a
#define ImportRarHpp() \
_Pragma( _stringify( clang diagnostic push ) ) \
_Pragma( _stringify( clang diagnostic ignored "-Wreserved-id-macro" ) ) \
_Pragma( _stringify( clang diagnostic ignored "-Wstrict-prototypes" ) ) \
#import "dll.hpp"
_Pragma( _stringify( clang diagnostic pop ) )