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#if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED)
48# define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
49#elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
50# define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
51#else
52# define Q_AUTOTEST_EXPORT
53#endif
54
55/*
56 The QT_CONFIG macro implements a safe compile time check for features of Qt.
57 Features can be in three states:
58 0 or undefined: This will lead to a compile error when testing for it
59 -1: The feature is not available
60 1: The feature is available
61*/
62#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
63#define QT_REQUIRE_CONFIG(feature) static_assert(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
64
65/* moc compats (signals/slots) */
66#ifndef QT_MOC_COMPAT
67# define QT_MOC_COMPAT
68#else
69# undef QT_MOC_COMPAT
70# define QT_MOC_COMPAT
71#endif
72
73/*
74 Debugging and error handling
75*/
76
77#if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
78# define QT_DEBUG
79#endif
80
81// valid for both C and C++
82#define QT_MANGLE_NAMESPACE0(x) x
83#define QT_MANGLE_NAMESPACE1(a, b) a##_##b
84#define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
85#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
86# define QT_MANGLE_NAMESPACE(name) name
87#else
88# define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
89 QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
90#endif
91
92#ifdef __cplusplus
93
94#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
95
96# define QT_PREPEND_NAMESPACE(name) ::name
97# define QT_USE_NAMESPACE
98# define QT_BEGIN_NAMESPACE
99# define QT_END_NAMESPACE
100# define QT_BEGIN_INCLUDE_NAMESPACE
101# define QT_END_INCLUDE_NAMESPACE
102# define QT_FORWARD_DECLARE_CLASS(name) class name;
103# define QT_FORWARD_DECLARE_STRUCT(name) struct name;
104
105#else /* user namespace */
106
107# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
108# define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
109# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
110# define QT_END_NAMESPACE }
111# define QT_BEGIN_INCLUDE_NAMESPACE }
112# define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
113# define QT_FORWARD_DECLARE_CLASS(name) \
114 QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
115 using QT_PREPEND_NAMESPACE(name);
116
117# define QT_FORWARD_DECLARE_STRUCT(name) \
118 QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
119 using QT_PREPEND_NAMESPACE(name);
120
121namespace QT_NAMESPACE {}
122
123# ifndef QT_BOOTSTRAPPED
124# ifndef QT_NO_USING_NAMESPACE
125 /*
126 This expands to a "using QT_NAMESPACE" also in _header files_.
127 It is the only way the feature can be used without too much
128 pain, but if people _really_ do not want it they can add
129 QT_NO_USING_NAMESPACE to their build configuration.
130 */
131 QT_USE_NAMESPACE
132# endif
133# endif
134
135#endif /* user namespace */
136
137#else /* __cplusplus */
138
139# define QT_BEGIN_NAMESPACE
140# define QT_END_NAMESPACE
141# define QT_USE_NAMESPACE
142# define QT_BEGIN_INCLUDE_NAMESPACE
143# define QT_END_INCLUDE_NAMESPACE
144
145#endif /* __cplusplus */
146
147/* ### Qt 6.9 (or later): remove *_MOC_* macros (moc does not need them since 6.5) */
148#ifndef QT_BEGIN_MOC_NAMESPACE
149# define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
150#endif
151#ifndef QT_END_MOC_NAMESPACE
152# define QT_END_MOC_NAMESPACE
153#endif
154
155#endif /* QTCONFIGMACROS_H */
156

source code of qtbase/src/corelib/global/qtconfigmacros.h