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/*
8 The Qt modules' export macros.
9 The options are:
10 - defined(QT_STATIC): Qt was built or is being built in static mode
11 - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
12 If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
13 mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
14 for the bootstrapped tools.
15*/
16
17#ifdef QT_BOOTSTRAPPED
18# ifdef QT_SHARED
19# error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
20# elif !defined(QT_STATIC)
21# define QT_STATIC
22# endif
23#endif
24
25#if defined(QT_SHARED) || !defined(QT_STATIC)
26# ifdef QT_STATIC
27# error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
28# endif
29# ifndef QT_SHARED
30# define QT_SHARED
31# endif
32#endif
33
34/*
35 The QT_CONFIG macro implements a safe compile time check for features of Qt.
36 Features can be in three states:
37 0 or undefined: This will lead to a compile error when testing for it
38 -1: The feature is not available
39 1: The feature is available
40*/
41#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
42#define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
43
44// valid for both C and C++
45#define QT_MANGLE_NAMESPACE0(x) x
46#define QT_MANGLE_NAMESPACE1(a, b) a##_##b
47#define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
48#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
49# define QT_MANGLE_NAMESPACE(name) name
50#else
51# define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
52 QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
53#endif
54
55#ifdef __cplusplus
56
57#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
58
59# define QT_PREPEND_NAMESPACE(name) ::name
60# define QT_USE_NAMESPACE
61# define QT_BEGIN_NAMESPACE
62# define QT_END_NAMESPACE
63# define QT_BEGIN_INCLUDE_NAMESPACE
64# define QT_END_INCLUDE_NAMESPACE
65#ifndef QT_BEGIN_MOC_NAMESPACE
66# define QT_BEGIN_MOC_NAMESPACE
67#endif
68#ifndef QT_END_MOC_NAMESPACE
69# define QT_END_MOC_NAMESPACE
70#endif
71# define QT_FORWARD_DECLARE_CLASS(name) class name;
72# define QT_FORWARD_DECLARE_STRUCT(name) struct name;
73
74#else /* user namespace */
75
76# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
77# define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
78# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
79# define QT_END_NAMESPACE }
80# define QT_BEGIN_INCLUDE_NAMESPACE }
81# define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
82#ifndef QT_BEGIN_MOC_NAMESPACE
83# define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
84#endif
85#ifndef QT_END_MOC_NAMESPACE
86# define QT_END_MOC_NAMESPACE
87#endif
88# define QT_FORWARD_DECLARE_CLASS(name) \
89 QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
90 using QT_PREPEND_NAMESPACE(name);
91
92# define QT_FORWARD_DECLARE_STRUCT(name) \
93 QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
94 using QT_PREPEND_NAMESPACE(name);
95
96namespace QT_NAMESPACE {}
97
98# ifndef QT_BOOTSTRAPPED
99# ifndef QT_NO_USING_NAMESPACE
100 /*
101 This expands to a "using QT_NAMESPACE" also in _header files_.
102 It is the only way the feature can be used without too much
103 pain, but if people _really_ do not want it they can add
104 QT_NO_USING_NAMESPACE to their build configuration.
105 */
106 QT_USE_NAMESPACE
107# endif
108# endif
109
110#endif /* user namespace */
111
112#else /* __cplusplus */
113
114# define QT_BEGIN_NAMESPACE
115# define QT_END_NAMESPACE
116# define QT_USE_NAMESPACE
117# define QT_BEGIN_INCLUDE_NAMESPACE
118# define QT_END_INCLUDE_NAMESPACE
119
120#endif /* __cplusplus */
121
122/* silence syncqt warning */
123QT_BEGIN_NAMESPACE
124QT_END_NAMESPACE
125
126#endif /* QTCONFIGMACROS_H */
127

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