Skip to content

Commit ce5d4b8

Browse files
committed
experimental compiler flags
Signed-off-by: Ian <[email protected]>
1 parent 561ec06 commit ce5d4b8

File tree

1 file changed

+68
-13
lines changed

1 file changed

+68
-13
lines changed

include/ccmath/internal/config/compiler.hpp

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525

2626
/// MSVC
2727
#if defined(_MSC_VER) && !defined(__clang__) && !defined(CCMATH_COMPILER_MSVC)
28-
#define CCMATH_COMPILER_MSVC
29-
#define CCMATH_COMPILER_MSVC_VER _MSC_VER
28+
#define CCMATH_COMPILER_MSVC
29+
#define CCMATH_COMPILER_MSVC_VER _MSC_VER
3030

3131
/// Intel DPC++ Compiler
3232
#elif defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER) && !defined(CCMATH_COMPILER_INTEL)
3333
#define CCMATH_COMPILER_INTEL
3434
#define CCMATH_COMPILER_INTEL_VER __INTEL_LLVM_COMPILER
3535

36-
#ifndef CCMATH_COMPILER_CLANG_BASED
36+
#ifndef CCMATH_COMPILER_CLANG_BASED
3737
#define CCMATH_COMPILER_CLANG_BASED
38-
#endif
38+
#endif
3939

4040
// TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler
4141

@@ -47,14 +47,13 @@
4747
#define CCMATH_COMPILER_CLANG_CL_VER_MINOR __clang_minor__
4848
#define CCMATH_COMPILER_CLANG_CL_VER_PATCH __clang_patchlevel__
4949

50-
#ifndef CCMATH_COMPILER_CLANG_BASED
50+
#ifndef CCMATH_COMPILER_CLANG_BASED
5151
#define CCMATH_COMPILER_CLANG_BASED
52-
#endif
52+
#endif
5353

5454
// TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler
5555

5656

57-
5857
/// Nvidia HPC SDK
5958
#elif defined(__NVCOMPILER) || defined(__NVCOMPILER_LLVM__) && !defined(CCMATH_COMPILER_NVIDIA_HPC)
6059
#define CCMATH_COMPILER_NVIDIA_HPC
@@ -68,9 +67,9 @@
6867

6968
/// Nvidia CUDA
7069
#elif defined(__CUDACC__) && !defined(CCMATH_COMPILER_NVIDIA_CUDA)
71-
#if !defined(CUDA_VERSION)
70+
#if !defined(CUDA_VERSION)
7271
#include <cuda.h> // We need to make sure the version is defined since nvcc doesn't define it
73-
#endif
72+
#endif
7473

7574
#define CCMATH_COMPILER_NVIDIA_CUDA
7675
#define CCMATH_COMPILER_NVIDIA_CUDA_VER (CUDA_VERSION / 1000)
@@ -93,9 +92,9 @@
9392
#define CCMATH_COMPILER_APPLE_CLANG_VER_MINOR __clang_minor__
9493
#define CCMATH_COMPILER_APPLE_CLANG_VER_PATCH __clang_patchlevel__
9594

96-
#ifndef CCMATH_COMPILER_CLANG_BASED
95+
#ifndef CCMATH_COMPILER_CLANG_BASED
9796
#define CCMATH_COMPILER_CLANG_BASED
98-
#endif
97+
#endif
9998

10099
// TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler
101100

@@ -107,9 +106,9 @@
107106
#define CCMATH_COMPILER_CLANG_VER_MINOR __clang_minor__
108107
#define CCMATH_COMPILER_CLANG_VER_PATCH __clang_patchlevel__
109108

110-
#ifndef CCMATH_COMPILER_CLANG_BASED
109+
#ifndef CCMATH_COMPILER_CLANG_BASED
111110
#define CCMATH_COMPILER_CLANG_BASED
112-
#endif
111+
#endif
113112

114113
// TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler
115114

@@ -125,3 +124,59 @@
125124
#else
126125
#define CCMATH_COMPILER_UNKNOWN
127126
#endif
127+
128+
// TODO: Explore this idea further
129+
130+
namespace ccm::internal::platform
131+
{
132+
// NOLINTNEXTLINE
133+
enum class compiler
134+
{
135+
eUnknown,
136+
eGCC,
137+
eClang,
138+
eMSVC,
139+
eClangCL,
140+
eIntel,
141+
eNvidiaHPC
142+
};
143+
144+
template <compiler>
145+
struct native_compiler : std::false_type{};
146+
147+
template <>
148+
struct native_compiler<compiler::eUnknown> : std::false_type
149+
{
150+
};
151+
152+
#ifdef CCMATH_COMPILER_GCC
153+
template <>
154+
struct native_compiler<compiler::eGCC> : std::true_type
155+
{
156+
};
157+
#endif
158+
159+
#ifdef CCMATH_COMPILER_CLANG
160+
template <>
161+
struct native_compiler<compiler::eClang> : std::true_type
162+
{
163+
};
164+
#endif
165+
166+
#ifdef CCMATH_COMPILER_MSVC
167+
template <>
168+
struct native_compiler<compiler::eMSVC> : std::true_type
169+
{
170+
};
171+
#endif
172+
173+
#ifdef CCMATH_COMPILER_CLANG_CL
174+
template <>
175+
struct native_compiler<compiler::eClangCL> : std::true_type
176+
{
177+
};
178+
#endif
179+
180+
181+
182+
} // namespace ccm::internal::platform

0 commit comments

Comments
 (0)