1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTCONFIGMACROS_H |
5 | #define QTCONFIGMACROS_H |
6 | |
7 | #if 0 |
8 | # pragma qt_sync_stop_processing |
9 | #endif |
10 | |
11 | #include <QtCore/qtconfiginclude.h> |
12 | |
13 | #include <assert.h> |
14 | |
15 | /* |
16 | The Qt modules' export macros. |
17 | The options are: |
18 | - defined(QT_STATIC): Qt was built or is being built in static mode |
19 | - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode |
20 | If neither was defined, then QT_SHARED is implied. If Qt was compiled in static |
21 | mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied |
22 | for the bootstrapped tools. |
23 | */ |
24 | |
25 | #ifdef QT_BOOTSTRAPPED |
26 | # ifdef QT_SHARED |
27 | # error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build" |
28 | # elif !defined(QT_STATIC) |
29 | # define QT_STATIC |
30 | # endif |
31 | #endif |
32 | |
33 | #if defined(QT_SHARED) || !defined(QT_STATIC) |
34 | # ifdef QT_STATIC |
35 | # error "Both QT_SHARED and QT_STATIC defined, please make up your mind" |
36 | # endif |
37 | # ifndef QT_SHARED |
38 | # define QT_SHARED |
39 | # endif |
40 | #endif |
41 | |
42 | /* |
43 | No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols |
44 | for Qt's internal unit tests. If you want slower loading times and more |
45 | symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL. |
46 | |
47 | \note After adding Q_AUTOTEST_EXPORT to a method, you'll need to wrap any unittests |
48 | that will use that method in "#ifdef QT_BUILD_INTERNAL". |
49 | */ |
50 | #if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED) |
51 | # define Q_AUTOTEST_EXPORT Q_DECL_EXPORT |
52 | #elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED) |
53 | # define Q_AUTOTEST_EXPORT Q_DECL_IMPORT |
54 | #else |
55 | # define Q_AUTOTEST_EXPORT |
56 | #endif |
57 | |
58 | /* |
59 | The QT_CONFIG macro implements a safe compile time check for features of Qt. |
60 | Features can be in three states: |
61 | 0 or undefined: This will lead to a compile error when testing for it |
62 | -1: The feature is not available |
63 | 1: The feature is available |
64 | */ |
65 | #define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1) |
66 | #define QT_REQUIRE_CONFIG(feature) static_assert(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.") |
67 | |
68 | /* moc compats (signals/slots) */ |
69 | #ifndef QT_MOC_COMPAT |
70 | # define QT_MOC_COMPAT |
71 | #else |
72 | # undef QT_MOC_COMPAT |
73 | # define QT_MOC_COMPAT |
74 | #endif |
75 | |
76 | /* |
77 | Debugging and error handling |
78 | */ |
79 | |
80 | #if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG) |
81 | # define QT_DEBUG |
82 | #endif |
83 | |
84 | // valid for both C and C++ |
85 | #define QT_MANGLE_NAMESPACE0(x) x |
86 | #define QT_MANGLE_NAMESPACE1(a, b) a##_##b |
87 | #define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b) |
88 | #if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */ |
89 | # define QT_MANGLE_NAMESPACE(name) name |
90 | #else |
91 | # define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \ |
92 | QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE)) |
93 | #endif |
94 | |
95 | #ifdef __cplusplus |
96 | |
97 | #if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */ |
98 | |
99 | # define QT_PREPEND_NAMESPACE(name) ::name |
100 | # define QT_USE_NAMESPACE |
101 | # define QT_BEGIN_NAMESPACE |
102 | # define QT_END_NAMESPACE |
103 | # define QT_BEGIN_INCLUDE_NAMESPACE |
104 | # define QT_END_INCLUDE_NAMESPACE |
105 | # define QT_FORWARD_DECLARE_CLASS(name) class name; |
106 | # define QT_FORWARD_DECLARE_STRUCT(name) struct name; |
107 | |
108 | #else /* user namespace */ |
109 | |
110 | # define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name |
111 | # define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE; |
112 | # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE { |
113 | # define QT_END_NAMESPACE } |
114 | # define QT_BEGIN_INCLUDE_NAMESPACE } |
115 | # define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE { |
116 | # define QT_FORWARD_DECLARE_CLASS(name) \ |
117 | QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \ |
118 | using QT_PREPEND_NAMESPACE(name); |
119 | |
120 | # define QT_FORWARD_DECLARE_STRUCT(name) \ |
121 | QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \ |
122 | using QT_PREPEND_NAMESPACE(name); |
123 | |
124 | namespace QT_NAMESPACE {} |
125 | |
126 | # ifndef QT_BOOTSTRAPPED |
127 | # ifndef QT_NO_USING_NAMESPACE |
128 | /* |
129 | This expands to a "using QT_NAMESPACE" also in _header files_. |
130 | It is the only way the feature can be used without too much |
131 | pain, but if people _really_ do not want it they can add |
132 | QT_NO_USING_NAMESPACE to their build configuration. |
133 | */ |
134 | QT_USE_NAMESPACE |
135 | # endif |
136 | # endif |
137 | |
138 | #endif /* user namespace */ |
139 | |
140 | #else /* __cplusplus */ |
141 | |
142 | # define QT_BEGIN_NAMESPACE |
143 | # define QT_END_NAMESPACE |
144 | # define QT_USE_NAMESPACE |
145 | # define QT_BEGIN_INCLUDE_NAMESPACE |
146 | # define QT_END_INCLUDE_NAMESPACE |
147 | |
148 | #endif /* __cplusplus */ |
149 | |
150 | /* ### Qt 6.9 (or later): remove *_MOC_* macros (moc does not need them since 6.5) */ |
151 | #ifndef QT_BEGIN_MOC_NAMESPACE |
152 | # define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE |
153 | #endif |
154 | #ifndef QT_END_MOC_NAMESPACE |
155 | # define QT_END_MOC_NAMESPACE |
156 | #endif |
157 | |
158 | #endif /* QTCONFIGMACROS_H */ |
159 | |