CLI11
C++11 Command Line Interface Parser
Loading...
Searching...
No Matches
include
CLI
Macros.hpp
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
#ifndef CLI11_HAS_RTTI
127
#if defined(__GXX_RTTI) && __GXX_RTTI == 1
128
// gcc
129
#define CLI11_HAS_RTTI 1
130
#elif defined(_CPPRTTI) && _CPPRTTI == 1
131
// msvc
132
#define CLI11_HAS_RTTI 1
133
#elif defined(__NO_RTTI__) && __NO_RTTI__ == 1
134
// intel
135
#define CLI11_HAS_RTTI 0
136
#elif defined(__has_feature)
137
// clang and other newer compilers
138
#if __has_feature(cxx_rtti)
139
#define CLI11_HAS_RTTI 1
140
#else
141
#define CLI11_HAS_RTTI 0
142
#endif
143
#elif defined(__RTTI) || defined(__INTEL_RTTI__)
144
// more intel and some other compilers
145
#define CLI11_HAS_RTTI 1
146
#else
147
#define CLI11_HAS_RTTI 0
148
#endif
149
#endif
150
152
#if defined(__GNUC__)
// GCC or clang
153
#define CLI11_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
154
#define CLI11_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
155
156
#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
157
158
#elif defined(_MSC_VER)
159
#define CLI11_DIAGNOSTIC_PUSH __pragma(warning(push))
160
#define CLI11_DIAGNOSTIC_POP __pragma(warning(pop))
161
162
#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED __pragma(warning(disable : 4996))
163
164
#else
165
#define CLI11_DIAGNOSTIC_PUSH
166
#define CLI11_DIAGNOSTIC_POP
167
168
#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED
169
170
#endif
171
173
#ifdef CLI11_COMPILE
174
#define CLI11_INLINE
175
#else
176
#define CLI11_INLINE inline
177
#endif
178
// [CLI11:macros_hpp:end]
Generated by
1.12.0