Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtconfigmacros.h
Go to the documentation of this file.
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#include <QtCore/qtversionchecks.h>
13
14#include <assert.h>
15
16/*
17 The Qt modules' export macros.
18 The options are:
19 - defined(QT_STATIC): Qt was built or is being built in static mode
20 - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
21 If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
22 mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
23 for the bootstrapped tools.
24*/
25
26#ifdef QT_BOOTSTRAPPED
27# ifdef QT_SHARED
28# error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
29# elif !defined(QT_STATIC)
30# define QT_STATIC
31# endif
32#endif
33
34#if defined(QT_SHARED) || !defined(QT_STATIC)
35# ifdef QT_STATIC
36# error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
37# endif
38# ifndef QT_SHARED
39# define QT_SHARED
40# endif
41#endif
42
43/*
44 No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
45 for Qt's internal unit tests. If you want slower loading times and more
46 symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
47
48 \note After adding Q_AUTOTEST_EXPORT to a method, you'll need to wrap any unittests
49 that will use that method in "#ifdef QT_BUILD_INTERNAL".
50*/
51#if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED)
52# define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
53#elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
54# define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
55#else
56# define Q_AUTOTEST_EXPORT
57#endif
58
59/*
60 The QT_CONFIG macro implements a safe compile time check for features of Qt.
61 Features can be in three states:
62 0 or undefined: This will lead to a compile error when testing for it
63 -1: The feature is not available
64 1: The feature is available
65*/
66#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
67#define QT_REQUIRE_CONFIG(feature) static_assert(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
68
69/* moc compats (signals/slots) */
70#ifndef QT_MOC_COMPAT
71# define QT_MOC_COMPAT
72#else
73# undef QT_MOC_COMPAT
74# define QT_MOC_COMPAT
75#endif
76
77/*
78 Debugging and error handling
79*/
80
81#if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
82# define QT_DEBUG
83#endif
84
85// valid for both C and C++
86#define QT_MANGLE_NAMESPACE0(x) x
87#define QT_MANGLE_NAMESPACE1(a, b) a##_##b
88#define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
89#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
90# define QT_MANGLE_NAMESPACE(name) name
91#else
92# define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
93 QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
94#endif
95
96#ifdef __cplusplus
97
98#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
99
100# define QT_PREPEND_NAMESPACE(name) ::name
101# define QT_USE_NAMESPACE
102# define QT_BEGIN_NAMESPACE
103# define QT_END_NAMESPACE
104# define QT_BEGIN_INCLUDE_NAMESPACE
105# define QT_END_INCLUDE_NAMESPACE
106# define QT_FORWARD_DECLARE_CLASS(name) class name;
107# define QT_FORWARD_DECLARE_STRUCT(name) struct name;
108
109#elif defined(QT_INLINE_NAMESPACE) /* user inline namespace FIXME in Qt 7: Default */
110
111# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
112# define QT_USE_NAMESPACE
113# define QT_BEGIN_NAMESPACE inline namespace QT_NAMESPACE {
114# define QT_END_NAMESPACE }
115# define QT_BEGIN_INCLUDE_NAMESPACE }
116# define QT_END_INCLUDE_NAMESPACE inline namespace QT_NAMESPACE {
117# define QT_FORWARD_DECLARE_CLASS(name) \
118QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE
119
120# define QT_FORWARD_DECLARE_STRUCT(name) \
121QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE
122
123inline namespace QT_NAMESPACE {}
124
125#else /* user namespace */
126
127# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
128# define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
129# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
130# define QT_END_NAMESPACE }
131# define QT_BEGIN_INCLUDE_NAMESPACE }
132# define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
133# define QT_FORWARD_DECLARE_CLASS(name) \
134 QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
135 using QT_PREPEND_NAMESPACE(name);
136
137# define QT_FORWARD_DECLARE_STRUCT(name) \
138 QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
139 using QT_PREPEND_NAMESPACE(name);
140
141namespace QT_NAMESPACE {}
142
143# ifndef QT_BOOTSTRAPPED
144# ifndef QT_NO_USING_NAMESPACE
145 /*
146 This expands to a "using QT_NAMESPACE" also in _header files_.
147 It is the only way the feature can be used without too much
148 pain, but if people _really_ do not want it they can add
149 QT_NO_USING_NAMESPACE to their build configuration.
150 */
152# endif
153# endif
154
155#endif /* user namespace */
156
157#else /* __cplusplus */
158
159# define QT_BEGIN_NAMESPACE
160# define QT_END_NAMESPACE
161# define QT_USE_NAMESPACE
162# define QT_BEGIN_INCLUDE_NAMESPACE
163# define QT_END_INCLUDE_NAMESPACE
164
165#endif /* __cplusplus */
166
167/* ### Qt 6.9 (or later): remove *_MOC_* macros (moc does not need them since 6.5) */
168#ifndef QT_BEGIN_MOC_NAMESPACE
169# define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
170#endif
171#ifndef QT_END_MOC_NAMESPACE
172# define QT_END_MOC_NAMESPACE
173#endif
174
175/*
176 Strict mode
177*/
178#ifdef QT_ENABLE_STRICT_MODE_UP_TO
179#ifndef QT_DISABLE_DEPRECATED_UP_TO
180# define QT_DISABLE_DEPRECATED_UP_TO QT_ENABLE_STRICT_MODE_UP_TO
181#endif
182
183#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 0, 0)
184# define QT_NO_FOREACH
185# define QT_NO_CAST_FROM_ASCII
186# define QT_NO_CAST_TO_ASCII
187# define QT_NO_CAST_FROM_BYTEARRAY
188# define QT_NO_URL_CAST_FROM_STRING
189# define QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
190# define QT_NO_JAVA_STYLE_ITERATORS
191#endif // 6.0.0
192
193#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 6, 0)
194# define QT_NO_QEXCHANGE
195#endif // 6.6.0
196
197#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 7, 0)
198# define QT_NO_CONTEXTLESS_CONNECT
199#endif // 6.7.0
200
201#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 8, 0)
202# define QT_NO_QASCONST
203# if !defined(QT_USE_NODISCARD_FILE_OPEN) && !defined(QT_NO_USE_NODISCARD_FILE_OPEN)
204# define QT_USE_NODISCARD_FILE_OPEN
205# endif
206#endif // 6.8.0
207#endif // QT_ENABLE_STRICT_MODE_UP_TO
208
209#endif /* QTCONFIGMACROS_H */