Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3#ifndef _TIME_SHIELD_CONFIG_HPP_INCLUDED
4#define _TIME_SHIELD_CONFIG_HPP_INCLUDED
5
13
14#include <atomic>
15
16#if defined(_MSVC_LANG)
17# define TIME_SHIELD_CXX_VERSION _MSVC_LANG
18#else
19# define TIME_SHIELD_CXX_VERSION __cplusplus
20#endif
21
22// Check and define macros based on the C++ standard version
23#if TIME_SHIELD_CXX_VERSION >= 201703L
24# define TIME_SHIELD_CPP17
25#elif TIME_SHIELD_CXX_VERSION >= 201402L
26# define TIME_SHIELD_CPP14
27#elif TIME_SHIELD_CXX_VERSION >= 201103L
28# define TIME_SHIELD_CPP11
29#else
30# error "C++11 or newer is required to compile this library."
31#endif
32
33// Configure support for `constexpr` and `if constexpr` based on the C++ standard
34#ifdef TIME_SHIELD_CPP11
35# define TIME_SHIELD_IF_CONSTEXPR
36# define TIME_SHIELD_CONSTEXPR
37#else
38#ifdef TIME_SHIELD_CPP14
39# define TIME_SHIELD_IF_CONSTEXPR
40# define TIME_SHIELD_CONSTEXPR constexpr
41#else
42#ifdef TIME_SHIELD_CPP17
43# define TIME_SHIELD_IF_CONSTEXPR constexpr
44# define TIME_SHIELD_CONSTEXPR constexpr
45#endif
46#endif
47#endif
48
49// Configure nodiscard attribute support while keeping compatibility with C++11 compilers
50#if defined(__has_cpp_attribute)
51# if __has_cpp_attribute(nodiscard) && defined(TIME_SHIELD_CPP17)
52# define TIME_SHIELD_NODISCARD [[nodiscard]]
53# else
54# define TIME_SHIELD_NODISCARD
55# endif
56#else
57# if defined(TIME_SHIELD_CPP17)
58# define TIME_SHIELD_NODISCARD [[nodiscard]]
59# else
60# define TIME_SHIELD_NODISCARD
61# endif
62#endif
63
64// Attribute helpers
65#if defined(TIME_SHIELD_CPP17)
66# define TIME_SHIELD_MAYBE_UNUSED [[maybe_unused]]
67#else
68# define TIME_SHIELD_MAYBE_UNUSED
69#endif
70
71// Configure thread-local storage handling for compilers with partial support
72#if defined(__cpp_thread_local)
73# define TIME_SHIELD_THREAD_LOCAL thread_local
74#elif defined(_MSC_VER)
75# define TIME_SHIELD_THREAD_LOCAL __declspec(thread)
76#elif defined(__GNUC__)
77# define TIME_SHIELD_THREAD_LOCAL __thread
78#else
79# define TIME_SHIELD_THREAD_LOCAL
80#endif
81
82
85#if defined(_WIN32)
86# define TIME_SHIELD_PLATFORM_WINDOWS 1
87#else
88# define TIME_SHIELD_PLATFORM_WINDOWS 0
89#endif
90
91#if defined(__unix__) || defined(__unix) || defined(unix) || \
92 (defined(__APPLE__) && defined(__MACH__))
93# define TIME_SHIELD_PLATFORM_UNIX 1
94#else
95# define TIME_SHIELD_PLATFORM_UNIX 0
96#endif
98
101#if TIME_SHIELD_PLATFORM_WINDOWS
102# define TIME_SHIELD_HAS_WINSOCK 1
103#else
104# define TIME_SHIELD_HAS_WINSOCK 0
105#endif
107
110#ifndef TIME_SHIELD_ENABLE_NTP_CLIENT
111# if TIME_SHIELD_HAS_WINSOCK || TIME_SHIELD_PLATFORM_UNIX
112# define TIME_SHIELD_ENABLE_NTP_CLIENT 1
113# else
114# define TIME_SHIELD_ENABLE_NTP_CLIENT 0
115# endif
116#endif
118
119#endif // _TIME_SHIELD_CONFIG_HPP_INCLUDED