I want to add a C preprocessor macro to the compilation of any translation unit which includes a header file, using the clang compiler.
In essence I would like to do something similar to suppressing warnings only for specific header includes:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsome-warning-like-unused-variable"
#include <some_header>
#pragma clang diagnostic pop
But instead of this, I would like to have a macro definition added
#define SOME_MACRO_DEFINITION
#include <some_header>
#undef SOME_MACRO_DEFINTION
For context, the compilation error occurs when including boost headers which use std::unary_function
. The Xcode 14.3 workaround suggested is to define this macro: _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION https://developer.apple.com/documentation/xcode-release-notes/xcode-14_3-release-notes
I can enable this macro on a global scope using my build system (by passing -D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
as a flag to the compiler), but really I’d like to only enable it for compiling the source files which include the specific offending boost headers. Unfortunately, I can’t change the build system drastically. Ideally, I only modify the source code.