CLI11  2.5.0
Macros.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2025, University of Cincinnati, developed by Henry Schreiner
2 // under NSF AWARD 1414736 and by the respective contributors.
3 // All rights reserved.
4 //
5 // SPDX-License-Identifier: BSD-3-Clause
6 
7 #pragma once
8 
9 // IWYU pragma: private, include "CLI/CLI.hpp"
10 
11 // [CLI11:macros_hpp:verbatim]
12 
13 // The following version macro is very similar to the one in pybind11
14 #if !(defined(_MSC_VER) && __cplusplus == 199711L) && !defined(__INTEL_COMPILER)
15 #if __cplusplus >= 201402L
16 #define CLI11_CPP14
17 #if __cplusplus >= 201703L
18 #define CLI11_CPP17
19 #if __cplusplus > 201703L
20 #define CLI11_CPP20
21 #if __cplusplus > 202002L
22 #define CLI11_CPP23
23 #if __cplusplus > 202302L
24 #define CLI11_CPP26
25 #endif
26 #endif
27 #endif
28 #endif
29 #endif
30 #elif defined(_MSC_VER) && __cplusplus == 199711L
31 // MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard was fully implemented)
32 // Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer
33 #if _MSVC_LANG >= 201402L
34 #define CLI11_CPP14
35 #if _MSVC_LANG > 201402L && _MSC_VER >= 1910
36 #define CLI11_CPP17
37 #if _MSVC_LANG > 201703L && _MSC_VER >= 1910
38 #define CLI11_CPP20
39 #if _MSVC_LANG > 202002L && _MSC_VER >= 1922
40 #define CLI11_CPP23
41 #endif
42 #endif
43 #endif
44 #endif
45 #endif
46 
47 #if defined(CLI11_CPP14)
48 #define CLI11_DEPRECATED(reason) [[deprecated(reason)]]
49 #elif defined(_MSC_VER)
50 #define CLI11_DEPRECATED(reason) __declspec(deprecated(reason))
51 #else
52 #define CLI11_DEPRECATED(reason) __attribute__((deprecated(reason)))
53 #endif
54 
55 // GCC < 10 doesn't ignore this in unevaluated contexts
56 #if !defined(CLI11_CPP17) || \
57  (defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 10 && __GNUC__ > 4)
58 #define CLI11_NODISCARD
59 #else
60 #define CLI11_NODISCARD [[nodiscard]]
61 #endif
62 
64 #ifndef CLI11_USE_STATIC_RTTI
65 #if (defined(_HAS_STATIC_RTTI) && _HAS_STATIC_RTTI)
66 #define CLI11_USE_STATIC_RTTI 1
67 #elif defined(__cpp_rtti)
68 #if (defined(_CPPRTTI) && _CPPRTTI == 0)
69 #define CLI11_USE_STATIC_RTTI 1
70 #else
71 #define CLI11_USE_STATIC_RTTI 0
72 #endif
73 #elif (defined(__GCC_RTTI) && __GXX_RTTI)
74 #define CLI11_USE_STATIC_RTTI 0
75 #else
76 #define CLI11_USE_STATIC_RTTI 1
77 #endif
78 #endif
79 
81 #if defined CLI11_CPP17 && defined __has_include && !defined CLI11_HAS_FILESYSTEM
82 #if __has_include(<filesystem>)
83 // Filesystem cannot be used if targeting macOS < 10.15
84 #if defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
85 #define CLI11_HAS_FILESYSTEM 0
86 #elif defined(__wasi__)
87 // As of wasi-sdk-14, filesystem is not implemented
88 #define CLI11_HAS_FILESYSTEM 0
89 #else
90 #include <filesystem>
91 #if defined __cpp_lib_filesystem && __cpp_lib_filesystem >= 201703
92 #if defined _GLIBCXX_RELEASE && _GLIBCXX_RELEASE >= 9
93 #define CLI11_HAS_FILESYSTEM 1
94 #elif defined(__GLIBCXX__)
95 // if we are using gcc and Version <9 default to no filesystem
96 #define CLI11_HAS_FILESYSTEM 0
97 #else
98 #define CLI11_HAS_FILESYSTEM 1
99 #endif
100 #else
101 #define CLI11_HAS_FILESYSTEM 0
102 #endif
103 #endif
104 #endif
105 #endif
106 
108 #if !defined(CLI11_CPP26) && !defined(CLI11_HAS_CODECVT)
109 #if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 5
110 #define CLI11_HAS_CODECVT 0
111 #else
112 #define CLI11_HAS_CODECVT 1
113 #include <codecvt>
114 #endif
115 #else
116 #if defined(CLI11_HAS_CODECVT)
117 #if CLI11_HAS_CODECVT > 0
118 #include <codecvt>
119 #endif
120 #else
121 #define CLI11_HAS_CODECVT 0
122 #endif
123 #endif
124 
126 #if defined(__GNUC__) // GCC or clang
127 #define CLI11_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
128 #define CLI11_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
129 
130 #define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
131 
132 #elif defined(_MSC_VER)
133 #define CLI11_DIAGNOSTIC_PUSH __pragma(warning(push))
134 #define CLI11_DIAGNOSTIC_POP __pragma(warning(pop))
135 
136 #define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED __pragma(warning(disable : 4996))
137 
138 #else
139 #define CLI11_DIAGNOSTIC_PUSH
140 #define CLI11_DIAGNOSTIC_POP
141 
142 #define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED
143 
144 #endif
145 
147 #ifdef CLI11_COMPILE
148 #define CLI11_INLINE
149 #else
150 #define CLI11_INLINE inline
151 #endif
152 // [CLI11:macros_hpp:end]