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#if defined(_MSVC_LANG)
15# define TIME_SHIELD_CXX_VERSION _MSVC_LANG
16#else
17# define TIME_SHIELD_CXX_VERSION __cplusplus
18#endif
19
20// Check and define macros based on the C++ standard version
21#if TIME_SHIELD_CXX_VERSION >= 201703L
22# define TIME_SHIELD_CPP17
23#elif TIME_SHIELD_CXX_VERSION >= 201402L
24# define TIME_SHIELD_CPP14
25#elif TIME_SHIELD_CXX_VERSION >= 201103L
26# define TIME_SHIELD_CPP11
27#else
28# error "C++11 or newer is required to compile this library."
29#endif
30
31// Configure support for `constexpr` and `if constexpr` based on the C++ standard
32#ifdef TIME_SHIELD_CPP11
33# define TIME_SHIELD_IF_CONSTEXPR
34# define TIME_SHIELD_CONSTEXPR
35#else
36#ifdef TIME_SHIELD_CPP14
37# define TIME_SHIELD_IF_CONSTEXPR
38# define TIME_SHIELD_CONSTEXPR constexpr
39#else
40#ifdef TIME_SHIELD_CPP17
41# define TIME_SHIELD_IF_CONSTEXPR constexpr
42# define TIME_SHIELD_CONSTEXPR constexpr
43#endif
44#endif
45#endif
46
47// Configure nodiscard attribute support while keeping compatibility with C++11 compilers
48#if defined(__has_cpp_attribute)
49# if __has_cpp_attribute(nodiscard)
50# define TIME_SHIELD_NODISCARD [[nodiscard]]
51# else
52# define TIME_SHIELD_NODISCARD
53# endif
54#else
55# if defined(TIME_SHIELD_CPP17)
56# define TIME_SHIELD_NODISCARD [[nodiscard]]
57# else
58# define TIME_SHIELD_NODISCARD
59# endif
60#endif
61
64#if defined(_WIN32)
65# define TIME_SHIELD_PLATFORM_WINDOWS 1
66#else
67# define TIME_SHIELD_PLATFORM_WINDOWS 0
68#endif
69
70#if defined(__unix__) || defined(__unix) || defined(unix) || \
71 (defined(__APPLE__) && defined(__MACH__))
72# define TIME_SHIELD_PLATFORM_UNIX 1
73#else
74# define TIME_SHIELD_PLATFORM_UNIX 0
75#endif
77
80#if TIME_SHIELD_PLATFORM_WINDOWS
81# define TIME_SHIELD_HAS_WINSOCK 1
82#else
83# define TIME_SHIELD_HAS_WINSOCK 0
84#endif
86
89#ifndef TIME_SHIELD_ENABLE_NTP_CLIENT
90# if TIME_SHIELD_HAS_WINSOCK
91# define TIME_SHIELD_ENABLE_NTP_CLIENT 1
92# else
93# define TIME_SHIELD_ENABLE_NTP_CLIENT 0
94# endif
95#endif
97
98#endif // _TIME_SHIELD_CONFIG_HPP_INCLUDED