1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Copyright (C) 2015 Intel Corporation.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #ifndef QGLOBAL_P_H
42 #define QGLOBAL_P_H
43 
44 //
45 //  W A R N I N G
46 //  -------------
47 //
48 // This file is not part of the Qt API.  It exists purely as an
49 // implementation detail.  This header file may change from version to
50 // version without notice, or even be removed.
51 //
52 // We mean it.
53 //
54 
55 #include "qglobal.h"
56 #include "qglobal_p.h"      // include self to avoid syncqt warning - no-op
57 
58 #ifndef QT_BOOTSTRAPPED
59 #include <QtCore/private/qconfig_p.h>
60 #include <QtCore/private/qtcore-config_p.h>
61 #endif
62 
63 #if defined(__cplusplus)
64 #ifdef Q_CC_MINGW
65 #  include <unistd.h> // Define _POSIX_THREAD_SAFE_FUNCTIONS to obtain localtime_r()
66 #endif
67 #include <time.h>
68 
69 QT_BEGIN_NAMESPACE
70 
71 // These behave as if they consult the environment, so need to share its locking:
72 Q_CORE_EXPORT void qTzSet();
73 Q_CORE_EXPORT time_t qMkTime(struct tm *when);
74 
75 QT_END_NAMESPACE
76 
77 #if !__has_builtin(__builtin_available)
78 #include <initializer_list>
79 #include <QtCore/qoperatingsystemversion.h>
80 #include <QtCore/qversionnumber.h>
81 
82 QT_BEGIN_NAMESPACE
83 
84 struct qt_clang_builtin_available_os_version_data {
85     QOperatingSystemVersion::OSType type;
86     const char *version;
87 };
88 
qt_clang_builtin_available(const std::initializer_list<qt_clang_builtin_available_os_version_data> & versions)89 static inline bool qt_clang_builtin_available(
90     const std::initializer_list<qt_clang_builtin_available_os_version_data> &versions)
91 {
92     for (auto it = versions.begin(); it != versions.end(); ++it) {
93         if (QOperatingSystemVersion::currentType() == it->type) {
94             const auto current = QOperatingSystemVersion::current();
95             return QVersionNumber(
96                 current.majorVersion(),
97                 current.minorVersion(),
98                 current.microVersion()) >= QVersionNumber::fromString(
99                     QString::fromLatin1(it->version));
100         }
101     }
102 
103     // Result is true if the platform is not any of the checked ones; this matches behavior of
104     // LLVM __builtin_available and @available constructs
105     return true;
106 }
107 
108 QT_END_NAMESPACE
109 
110 #define QT_AVAILABLE_OS_VER(os, ver) \
111     QT_PREPEND_NAMESPACE(qt_clang_builtin_available_os_version_data){\
112         QT_PREPEND_NAMESPACE(QOperatingSystemVersion)::os, #ver}
113 #define QT_AVAILABLE_CAT(L, R) QT_AVAILABLE_CAT_(L, R)
114 #define QT_AVAILABLE_CAT_(L, R) L ## R
115 #define QT_AVAILABLE_EXPAND(...) QT_AVAILABLE_OS_VER(__VA_ARGS__)
116 #define QT_AVAILABLE_SPLIT(os_ver) QT_AVAILABLE_EXPAND(QT_AVAILABLE_CAT(QT_AVAILABLE_SPLIT_, os_ver))
117 #define QT_AVAILABLE_SPLIT_macOS MacOS,
118 #define QT_AVAILABLE_SPLIT_iOS IOS,
119 #define QT_AVAILABLE_SPLIT_tvOS TvOS,
120 #define QT_AVAILABLE_SPLIT_watchOS WatchOS,
121 #define QT_BUILTIN_AVAILABLE0(e) \
122     QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({})
123 #define QT_BUILTIN_AVAILABLE1(a, e) \
124     QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a)})
125 #define QT_BUILTIN_AVAILABLE2(a, b, e) \
126     QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a), \
127                                                       QT_AVAILABLE_SPLIT(b)})
128 #define QT_BUILTIN_AVAILABLE3(a, b, c, e) \
129     QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a), \
130                                                       QT_AVAILABLE_SPLIT(b), \
131                                                       QT_AVAILABLE_SPLIT(c)})
132 #define QT_BUILTIN_AVAILABLE4(a, b, c, d, e) \
133     QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a), \
134                                                       QT_AVAILABLE_SPLIT(b), \
135                                                       QT_AVAILABLE_SPLIT(c), \
136                                                       QT_AVAILABLE_SPLIT(d)})
137 #define QT_BUILTIN_AVAILABLE_ARG(arg0, arg1, arg2, arg3, arg4, arg5, ...) arg5
138 #define QT_BUILTIN_AVAILABLE_CHOOSER(...) QT_BUILTIN_AVAILABLE_ARG(__VA_ARGS__, \
139     QT_BUILTIN_AVAILABLE4, \
140     QT_BUILTIN_AVAILABLE3, \
141     QT_BUILTIN_AVAILABLE2, \
142     QT_BUILTIN_AVAILABLE1, \
143     QT_BUILTIN_AVAILABLE0, )
144 #define __builtin_available(...) QT_BUILTIN_AVAILABLE_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
145 #endif // !__has_builtin(__builtin_available)
146 #endif // defined(__cplusplus)
147 
148 #endif // QGLOBAL_P_H
149 
150