CLI11
C++11 Command Line Interface Parser
Loading...
Searching...
No Matches
Macros.hpp
1// Copyright (c) 2017-2024, 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#endif
22#endif
23#endif
24#elif defined(_MSC_VER) && __cplusplus == 199711L
25// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented)
26// Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer
27#if _MSVC_LANG >= 201402L
28#define CLI11_CPP14
29#if _MSVC_LANG > 201402L && _MSC_VER >= 1910
30#define CLI11_CPP17
31#if _MSVC_LANG > 201703L && _MSC_VER >= 1910
32#define CLI11_CPP20
33#endif
34#endif
35#endif
36#endif
37
38#if defined(CLI11_CPP14)
39#define CLI11_DEPRECATED(reason) [[deprecated(reason)]]
40#elif defined(_MSC_VER)
41#define CLI11_DEPRECATED(reason) __declspec(deprecated(reason))
42#else
43#define CLI11_DEPRECATED(reason) __attribute__((deprecated(reason)))
44#endif
45
46// GCC < 10 doesn't ignore this in unevaluated contexts
47#if !defined(CLI11_CPP17) || \
48 (defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 10 && __GNUC__ > 4)
49#define CLI11_NODISCARD
50#else
51#define CLI11_NODISCARD [[nodiscard]]
52#endif
53
55#ifndef CLI11_USE_STATIC_RTTI
56#if(defined(_HAS_STATIC_RTTI) && _HAS_STATIC_RTTI)
57#define CLI11_USE_STATIC_RTTI 1
58#elif defined(__cpp_rtti)
59#if(defined(_CPPRTTI) && _CPPRTTI == 0)
60#define CLI11_USE_STATIC_RTTI 1
61#else
62#define CLI11_USE_STATIC_RTTI 0
63#endif
64#elif(defined(__GCC_RTTI) && __GXX_RTTI)
65#define CLI11_USE_STATIC_RTTI 0
66#else
67#define CLI11_USE_STATIC_RTTI 1
68#endif
69#endif
70
72#if defined CLI11_CPP17 && defined __has_include && !defined CLI11_HAS_FILESYSTEM
73#if __has_include(<filesystem>)
74// Filesystem cannot be used if targeting macOS < 10.15
75#if defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
76#define CLI11_HAS_FILESYSTEM 0
77#elif defined(__wasi__)
78// As of wasi-sdk-14, filesystem is not implemented
79#define CLI11_HAS_FILESYSTEM 0
80#else
81#include <filesystem>
82#if defined __cpp_lib_filesystem && __cpp_lib_filesystem >= 201703
83#if defined _GLIBCXX_RELEASE && _GLIBCXX_RELEASE >= 9
84#define CLI11_HAS_FILESYSTEM 1
85#elif defined(__GLIBCXX__)
86// if we are using gcc and Version <9 default to no filesystem
87#define CLI11_HAS_FILESYSTEM 0
88#else
89#define CLI11_HAS_FILESYSTEM 1
90#endif
91#else
92#define CLI11_HAS_FILESYSTEM 0
93#endif
94#endif
95#endif
96#endif
97
99#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 5
100#define CLI11_HAS_CODECVT 0
101#else
102#define CLI11_HAS_CODECVT 1
103#include <codecvt>
104#endif
105
107#if defined(__GNUC__) // GCC or clang
108#define CLI11_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
109#define CLI11_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
110
111#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
112
113#elif defined(_MSC_VER)
114#define CLI11_DIAGNOSTIC_PUSH __pragma(warning(push))
115#define CLI11_DIAGNOSTIC_POP __pragma(warning(pop))
116
117#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED __pragma(warning(disable : 4996))
118
119#else
120#define CLI11_DIAGNOSTIC_PUSH
121#define CLI11_DIAGNOSTIC_POP
122
123#define CLI11_DIAGNOSTIC_IGNORE_DEPRECATED
124
125#endif
126
128#ifdef CLI11_COMPILE
129#define CLI11_INLINE
130#else
131#define CLI11_INLINE inline
132#endif
133// [CLI11:macros_hpp:end]