|
11 | 11 | #ifndef __CCCL_COMPILER_H
|
12 | 12 | #define __CCCL_COMPILER_H
|
13 | 13 |
|
| 14 | +// Utility to compare version numbers. To use: |
| 15 | +// 1) Define a macro that makes a version number from major and minor numbers, e. g.: |
| 16 | +// #define MYPRODUCT_MAKE_VERSION(_MAJOR, _MINOR) (_MAJOR * 100 + _MINOR) |
| 17 | +// 2) Define a macro that you will use to compare versions, e. g.: |
| 18 | +// #define MYPRODUCT(...) _CCCL_VERSION_COMPARE(MYPRODUCT, MYPRODUCT_##__VA_ARGS__) |
| 19 | +// Signatures: |
| 20 | +// MYPRODUCT(_PROD) - is the product _PROD version non-zero? |
| 21 | +// MYPRODUCT(_PROD, _OP, _MAJOR) - compare the product _PROD version to _MAJOR using operator _OP |
| 22 | +// MYPRODUCT(_PROD, _OP, _MAJOR, _MINOR) - compare the product _PROD version to _MAJOR._MINOR using operator _OP |
| 23 | +#define _CCCL_VERSION_COMPARE_1(_PREFIX, _VER) (_VER != 0) |
| 24 | +#define _CCCL_VERSION_COMPARE_3(_PREFIX, _VER, _OP, _MAJOR) _CCCL_VERSION_COMPARE_4(_PREFIX, _VER, _OP, _MAJOR, 0) |
| 25 | +#define _CCCL_VERSION_COMPARE_4(_PREFIX, _VER, _OP, _MAJOR, _MINOR) \ |
| 26 | + (_CCCL_VERSION_COMPARE_1(_PREFIX, _VER) && (_VER _OP _PREFIX##_MAKE_VERSION(_MAJOR, _MINOR))) |
| 27 | +#define _CCCL_VERSION_SELECT_COUNT(_ARG1, _ARG2, _ARG3, _ARG4, _ARG5, ...) _ARG5 |
| 28 | +#define _CCCL_VERSION_SELECT2(_ARGS) _CCCL_VERSION_SELECT_COUNT _ARGS |
| 29 | +// MSVC traditonal preprocessor requires an extra level of indirection |
| 30 | +#define _CCCL_VERSION_SELECT(...) \ |
| 31 | + _CCCL_VERSION_SELECT2( \ |
| 32 | + (__VA_ARGS__, \ |
| 33 | + _CCCL_VERSION_COMPARE_4, \ |
| 34 | + _CCCL_VERSION_COMPARE_3, \ |
| 35 | + _CCCL_VERSION_COMPARE_BAD_ARG_COUNT, \ |
| 36 | + _CCCL_VERSION_COMPARE_1, \ |
| 37 | + _CCCL_VERSION_COMPARE_BAD_ARG_COUNT)) |
| 38 | +#define _CCCL_VERSION_COMPARE(_PREFIX, ...) _CCCL_VERSION_SELECT(__VA_ARGS__)(_PREFIX, __VA_ARGS__) |
| 39 | + |
14 | 40 | #define _CCCL_COMPILER_MAKE_VERSION(_MAJOR, _MINOR) (_MAJOR * 100 + _MINOR)
|
| 41 | +#define _CCCL_COMPILER(...) _CCCL_VERSION_COMPARE(_CCCL_COMPILER, _CCCL_COMPILER_##__VA_ARGS__) |
15 | 42 |
|
16 | 43 | // Determine the host compiler and its version
|
17 | 44 | #if defined(__INTEL_COMPILER)
|
|
39 | 66 | # define _CCCL_COMPILER_NVRTC _CCCL_COMPILER_MAKE_VERSION(__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__)
|
40 | 67 | #endif
|
41 | 68 |
|
42 |
| -#define _CCCL_COMPILER_COMPARE_VERSION_1(_COMP) _COMP |
43 |
| -#define _CCCL_COMPILER_COMPARE_VERSION_3(_COMP, _OP, _MAJOR) _CCCL_COMPILER_COMPARE_VERSION_4(_COMP, _OP, _MAJOR, 0) |
44 |
| -#define _CCCL_COMPILER_COMPARE_VERSION_4(_COMP, _OP, _MAJOR, _MINOR) \ |
45 |
| - (_COMP && (_COMP _OP _CCCL_COMPILER_MAKE_VERSION(_MAJOR, _MINOR))) |
46 |
| - |
47 |
| -#define _CCCL_COMPILER_SELECT_COUNT(_ARG1, _ARG2, _ARG3, _ARG4, _ARG5, ...) _ARG5 |
48 |
| -#define _CCCL_COMPILER_SELECT2(_ARGS) _CCCL_COMPILER_SELECT_COUNT _ARGS |
49 |
| -// MSVC traditonal preprocessor requires an extra level of indirection |
50 |
| -#define _CCCL_COMPILER_SELECT(...) \ |
51 |
| - _CCCL_COMPILER_SELECT2( \ |
52 |
| - (__VA_ARGS__, \ |
53 |
| - _CCCL_COMPILER_COMPARE_VERSION_4, \ |
54 |
| - _CCCL_COMPILER_COMPARE_VERSION_3, \ |
55 |
| - _CCCL_COMPILER_COMPARE_BAD_ARG_COUNT, \ |
56 |
| - _CCCL_COMPILER_COMPARE_VERSION_1, \ |
57 |
| - _CCCL_COMPILER_COMPARE_BAD_ARG_COUNT)) |
58 |
| -#define _CCCL_COMPILER(...) _CCCL_COMPILER_SELECT(_CCCL_COMPILER_##__VA_ARGS__)(_CCCL_COMPILER_##__VA_ARGS__) |
59 |
| - |
60 | 69 | // Determine the cuda compiler
|
61 | 70 | #if defined(__NVCC__)
|
62 | 71 | # define _CCCL_CUDA_COMPILER_NVCC
|
|
0 commit comments