diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 0c15c543f1..781c9aacf6 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -59,6 +59,7 @@ qt_internal_add_module(Core global/qsimd.cpp global/qsimd.h global/qsimd_p.h global/qsysinfo.h global/qsystemdetection.h + global/qtnamespacemacros.h global/qtypeinfo.h global/qvolatile_p.h global/q20algorithm.h diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 130b18a19e..50fcc2474f 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -188,79 +188,7 @@ static_assert(!std::is_convertible_v, # define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition) #endif -#ifdef __cplusplus - -#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */ - -# define QT_PREPEND_NAMESPACE(name) ::name -# define QT_USE_NAMESPACE -# define QT_BEGIN_NAMESPACE -# define QT_END_NAMESPACE -# define QT_BEGIN_INCLUDE_NAMESPACE -# define QT_END_INCLUDE_NAMESPACE -#ifndef QT_BEGIN_MOC_NAMESPACE -# define QT_BEGIN_MOC_NAMESPACE -#endif -#ifndef QT_END_MOC_NAMESPACE -# define QT_END_MOC_NAMESPACE -#endif -# define QT_FORWARD_DECLARE_CLASS(name) class name; -# define QT_FORWARD_DECLARE_STRUCT(name) struct name; -# define QT_MANGLE_NAMESPACE(name) name - -#else /* user namespace */ - -# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name -# define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE; -# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE { -# define QT_END_NAMESPACE } -# define QT_BEGIN_INCLUDE_NAMESPACE } -# define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE { -#ifndef QT_BEGIN_MOC_NAMESPACE -# define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE -#endif -#ifndef QT_END_MOC_NAMESPACE -# define QT_END_MOC_NAMESPACE -#endif -# define QT_FORWARD_DECLARE_CLASS(name) \ - QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \ - using QT_PREPEND_NAMESPACE(name); - -# define QT_FORWARD_DECLARE_STRUCT(name) \ - QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \ - using QT_PREPEND_NAMESPACE(name); - -# define QT_MANGLE_NAMESPACE0(x) x -# define QT_MANGLE_NAMESPACE1(a, b) a##_##b -# define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b) -# define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \ - QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE)) - -namespace QT_NAMESPACE {} - -# ifndef QT_BOOTSTRAPPED -# ifndef QT_NO_USING_NAMESPACE - /* - This expands to a "using QT_NAMESPACE" also in _header files_. - It is the only way the feature can be used without too much - pain, but if people _really_ do not want it they can add - DEFINES += QT_NO_USING_NAMESPACE to their .pro files. - */ - QT_USE_NAMESPACE -# endif -# endif - -#endif /* user namespace */ - -#else /* __cplusplus */ - -# define QT_BEGIN_NAMESPACE -# define QT_END_NAMESPACE -# define QT_USE_NAMESPACE -# define QT_BEGIN_INCLUDE_NAMESPACE -# define QT_END_INCLUDE_NAMESPACE - -#endif /* __cplusplus */ +# include #if defined(Q_OS_DARWIN) && !defined(QT_LARGEFILE_SUPPORT) # define QT_LARGEFILE_SUPPORT 64 diff --git a/src/corelib/global/qtnamespacemacros.h b/src/corelib/global/qtnamespacemacros.h new file mode 100644 index 0000000000..672c761739 --- /dev/null +++ b/src/corelib/global/qtnamespacemacros.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTNAMESPACEMACROS_H +#define QTNAMESPACEMACROS_H + +#ifdef __cplusplus + +#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */ + +# define QT_PREPEND_NAMESPACE(name) ::name +# define QT_USE_NAMESPACE +# define QT_BEGIN_NAMESPACE +# define QT_END_NAMESPACE +# define QT_BEGIN_INCLUDE_NAMESPACE +# define QT_END_INCLUDE_NAMESPACE +#ifndef QT_BEGIN_MOC_NAMESPACE +# define QT_BEGIN_MOC_NAMESPACE +#endif +#ifndef QT_END_MOC_NAMESPACE +# define QT_END_MOC_NAMESPACE +#endif +# define QT_FORWARD_DECLARE_CLASS(name) class name; +# define QT_FORWARD_DECLARE_STRUCT(name) struct name; +# define QT_MANGLE_NAMESPACE(name) name + +#else /* user namespace */ + +# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name +# define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE; +# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE { +# define QT_END_NAMESPACE } +# define QT_BEGIN_INCLUDE_NAMESPACE } +# define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE { +#ifndef QT_BEGIN_MOC_NAMESPACE +# define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE +#endif +#ifndef QT_END_MOC_NAMESPACE +# define QT_END_MOC_NAMESPACE +#endif +# define QT_FORWARD_DECLARE_CLASS(name) \ + QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \ + using QT_PREPEND_NAMESPACE(name); + +# define QT_FORWARD_DECLARE_STRUCT(name) \ + QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \ + using QT_PREPEND_NAMESPACE(name); + +# define QT_MANGLE_NAMESPACE0(x) x +# define QT_MANGLE_NAMESPACE1(a, b) a##_##b +# define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b) +# define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \ + QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE)) + +namespace QT_NAMESPACE {} + +# ifndef QT_BOOTSTRAPPED +# ifndef QT_NO_USING_NAMESPACE + /* + This expands to a "using QT_NAMESPACE" also in _header files_. + It is the only way the feature can be used without too much + pain, but if people _really_ do not want it they can add + DEFINES += QT_NO_USING_NAMESPACE to their .pro files. + */ + QT_USE_NAMESPACE +# endif +# endif + +#endif /* user namespace */ + +#else /* __cplusplus */ + +# define QT_BEGIN_NAMESPACE +# define QT_END_NAMESPACE +# define QT_USE_NAMESPACE +# define QT_BEGIN_INCLUDE_NAMESPACE +# define QT_END_INCLUDE_NAMESPACE + +#endif /* __cplusplus */ + +#endif /* QTNAMESPACEMACROS_H */