summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-04-02 20:50:51 (GMT)
committerBrad King <brad.king@kitware.com>2024-04-04 19:13:17 (GMT)
commitb9d4db7098898dbaf9dd29f0fbcc166af0e5154e (patch)
tree7b886252956a24fbb7aaaf58a2492f3a0fc66226 /Modules
parentae18811f2e1e12de8c2dc9c1168de1859c38dca2 (diff)
downloadCMake-b9d4db7098898dbaf9dd29f0fbcc166af0e5154e.zip
CMake-b9d4db7098898dbaf9dd29f0fbcc166af0e5154e.tar.gz
CMake-b9d4db7098898dbaf9dd29f0fbcc166af0e5154e.tar.bz2
CompilerId: Clarify C and C++ standard level detection
Use named constants. Regularize comparison patterns.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeCCompilerId.c.in17
-rw-r--r--Modules/CMakeCXXCompilerId.cpp.in26
2 files changed, 30 insertions, 13 deletions
diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in
index 82d56cf..759cdf4 100644
--- a/Modules/CMakeCCompilerId.c.in
+++ b/Modules/CMakeCCompilerId.c.in
@@ -39,19 +39,28 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
@CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@
@CMAKE_C_COMPILER_ID_ERROR_FOR_TEST@
+#define C_STD_99 199901L
+#define C_STD_11 201112L
+#define C_STD_17 201710L
+#define C_STD_23 202311L
+
+#ifdef __STDC_VERSION__
+# define C_STD __STDC_VERSION__
+#endif
+
#if !defined(__STDC__) && !defined(__clang__)
# if defined(_MSC_VER) || defined(__ibmxl__) || defined(__IBMC__)
# define C_VERSION "90"
# else
# define C_VERSION
# endif
-#elif __STDC_VERSION__ > 201710L
+#elif C_STD > C_STD_17
# define C_VERSION "23"
-#elif __STDC_VERSION__ >= 201710L
+#elif C_STD > C_STD_11
# define C_VERSION "17"
-#elif __STDC_VERSION__ >= 201000L
+#elif C_STD > C_STD_99
# define C_VERSION "11"
-#elif __STDC_VERSION__ >= 199901L
+#elif C_STD >= C_STD_99
# define C_VERSION "99"
#else
# define C_VERSION "90"
diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in
index 2643326..948209a 100644
--- a/Modules/CMakeCXXCompilerId.cpp.in
+++ b/Modules/CMakeCXXCompilerId.cpp.in
@@ -33,15 +33,23 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
@CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@
@CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST@
-#if defined(__INTEL_COMPILER) && defined(_MSVC_LANG) && _MSVC_LANG < 201403L
+#define CXX_STD_98 199711L
+#define CXX_STD_11 201103L
+#define CXX_STD_14 201402L
+#define CXX_STD_17 201703L
+#define CXX_STD_20 202002L
+#define CXX_STD_23 202302L
+
+#if defined(__INTEL_COMPILER) && defined(_MSVC_LANG) && \
+ _MSVC_LANG <= CXX_STD_14
# if defined(__INTEL_CXX11_MODE__)
# if defined(__cpp_aggregate_nsdmi)
-# define CXX_STD 201402L
+# define CXX_STD CXX_STD_14
# else
-# define CXX_STD 201103L
+# define CXX_STD CXX_STD_11
# endif
# else
-# define CXX_STD 199711L
+# define CXX_STD CXX_STD_98
# endif
#elif defined(_MSC_VER) && defined(_MSVC_LANG)
# define CXX_STD _MSVC_LANG
@@ -50,15 +58,15 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
#endif
const char* info_language_standard_default = "INFO" ":" "standard_default["
-#if CXX_STD > 202002L
+#if CXX_STD > CXX_STD_20
"23"
-#elif CXX_STD > 201703L
+#elif CXX_STD > CXX_STD_17
"20"
-#elif CXX_STD >= 201703L
+#elif CXX_STD > CXX_STD_14
"17"
-#elif CXX_STD >= 201402L
+#elif CXX_STD > CXX_STD_11
"14"
-#elif CXX_STD >= 201103L
+#elif CXX_STD >= CXX_STD_11
"11"
#else
"98"