|
| 1 | +// This source file checks that: |
| 2 | +// 1) Header <cub/${header}> compiles without error. |
| 3 | +// 2) Common macro collisions with platform/system headers are avoided. |
| 4 | + |
| 5 | +// Define CUB_MACRO_CHECK(macro, header), which emits a diagnostic indicating |
| 6 | +// a potential macro collision and halts. |
| 7 | +// |
| 8 | +// Use raw platform checks instead of the CUB_HOST_COMPILER macros since we |
| 9 | +// don't want to #include any headers other than the one being tested. |
| 10 | +// |
| 11 | +// This is only implemented for MSVC/GCC/Clang. |
| 12 | +#if defined(_MSC_VER) // MSVC |
| 13 | + |
| 14 | +// Fake up an error for MSVC |
| 15 | +#define CUB_MACRO_CHECK_IMPL(msg) \ |
| 16 | + /* Print message that looks like an error: */ \ |
| 17 | + __pragma(message(__FILE__ ":" CUB_MACRO_CHECK_IMPL0(__LINE__) \ |
| 18 | + ": error: " #msg)) \ |
| 19 | + /* abort compilation due to static_assert or syntax error: */ \ |
| 20 | + static_assert(false, #msg); |
| 21 | +#define CUB_MACRO_CHECK_IMPL0(x) CUB_MACRO_CHECK_IMPL1(x) |
| 22 | +#define CUB_MACRO_CHECK_IMPL1(x) #x |
| 23 | + |
| 24 | +#elif defined(__clang__) || defined(__GNUC__) |
| 25 | + |
| 26 | +// GCC/clang are easy: |
| 27 | +#define CUB_MACRO_CHECK_IMPL(msg) CUB_MACRO_CHECK_IMPL0(GCC error #msg) |
| 28 | +#define CUB_MACRO_CHECK_IMPL0(expr) _Pragma(#expr) |
| 29 | + |
| 30 | +#endif |
| 31 | + |
| 32 | +// Hacky way to build a string, but it works on all tested platforms. |
| 33 | +#define CUB_MACRO_CHECK(MACRO, HEADER) \ |
| 34 | + CUB_MACRO_CHECK_IMPL(Identifier MACRO should not be used from Thrust \ |
| 35 | + headers due to conflicts with HEADER.) |
| 36 | + |
| 37 | +// complex.h conflicts |
| 38 | +#define I CUB_MACRO_CHECK('I', complex.h) |
| 39 | + |
| 40 | +// windows.h conflicts |
| 41 | +// Disabling for now; we use min/max in many places, but since most |
| 42 | +// projects build with NOMINMAX this doesn't seem to be high priority to fix. |
| 43 | +//#define min(...) CUB_MACRO_CHECK('min', windows.h) |
| 44 | +//#define max(...) CUB_MACRO_CHECK('max', windows.h) |
| 45 | + |
1 | 46 | #include <cub/${header}> |
0 commit comments