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