summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-03-05 11:31:09 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-04-03 17:17:11 +0200
commitfdac1e22053f4144be0c4c501e6396cd873dd158 (patch)
tree8ba7af2c2dcd5cc5482d8aee7e2317ab1efe4902
parente23ea6a5d3bf09921bb98150a4f0f504e77ef4a3 (diff)
Add support for using an inline namespaces for -qtnamespace
Inline namespaces serve the purpose for which the original -qtnamespace option was added and allow for macro simplification (no need for any using directives). This makes it possible to use namespaced builds of Qt also for Qt for Python and similar use cases which have issues with the additional namespace. [ChangeLog][QtCore] It is now possible to use an inline namespace for -qtnamespace (option -qtinlinenamespace). Task-number: PYSIDE-2590 Change-Id: Ia0cecf041321933a2e02d1fd8ae0e9cda699cd1e Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
-rw-r--r--cmake/QtProcessConfigureArgs.cmake1
-rw-r--r--cmake/configure-cmake-mapping.md1
-rw-r--r--config_help.txt1
-rw-r--r--qt_cmdline.cmake1
-rw-r--r--src/corelib/CMakeLists.txt6
-rw-r--r--src/corelib/global/qtconfigmacros.h16
-rw-r--r--src/tools/rcc/rcc.cpp4
-rw-r--r--tests/auto/tools/rcc/data/images/images.expected4
-rw-r--r--tests/auto/tools/rcc/data/images/images.expected324
-rw-r--r--tests/auto/tools/rcc/data/sizes/size-0.expected4
-rw-r--r--tests/auto/tools/rcc/data/sizes/size-1.expected4
-rw-r--r--tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected4
-rw-r--r--tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected324
13 files changed, 46 insertions, 8 deletions
diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake
index 97bf49efbe..55980f275b 100644
--- a/cmake/QtProcessConfigureArgs.cmake
+++ b/cmake/QtProcessConfigureArgs.cmake
@@ -910,6 +910,7 @@ translate_boolean_input(ccache QT_USE_CCACHE)
translate_boolean_input(vcpkg QT_USE_VCPKG)
translate_boolean_input(shared BUILD_SHARED_LIBS)
translate_boolean_input(warnings_are_errors WARNINGS_ARE_ERRORS)
+translate_boolean_input(qtinlinenamespace QT_INLINE_NAMESPACE)
translate_string_input(qt_namespace QT_NAMESPACE)
translate_string_input(qt_libinfix QT_LIBINFIX)
translate_string_input(qreal QT_COORD_TYPE)
diff --git a/cmake/configure-cmake-mapping.md b/cmake/configure-cmake-mapping.md
index 28da5a17a0..d504bd8d4b 100644
--- a/cmake/configure-cmake-mapping.md
+++ b/cmake/configure-cmake-mapping.md
@@ -45,6 +45,7 @@ The following table describes the mapping of configure options to CMake argument
| -device-option <key=value> | -DQT_QMAKE_DEVICE_OPTIONS=key1=value1;key2=value2 | Only used for generation qmake-compatibility files. |
| | | The device options are written into mkspecs/qdevice.pri. |
| -appstore-compliant | -DFEATURE_appstore_compliant=ON | |
+| -qtinlinenamespace | -DQT_INLINE_NAMESPACE=ON | Make the namespace specified by -qtnamespace an inline one. |
| -qtnamespace <name> | -DQT_NAMESPACE=<name> | |
| -qtlibinfix <infix> | -DQT_LIBINFIX=<infix> | |
| -coverage <tool> | -DINPUT_coverage=<tool> | Enables code coverage using the specified tool. |
diff --git a/config_help.txt b/config_help.txt
index a5f8cd62df..13fc516da5 100644
--- a/config_help.txt
+++ b/config_help.txt
@@ -101,6 +101,7 @@ Build options:
-qt-host-path <path> . Specify path to a Qt host build for cross-compiling.
-qtnamespace <name> .. Wrap all Qt library code in 'namespace <name> {...}'.
+ -qtinlinenamespace ... Make -qtnamespace an inline namespace
-qtlibinfix <infix> .. Rename all libQt6*.so to libQt6*<infix>.so.
-coverage <tool> ..... Instrument with the code coverage tool.
diff --git a/qt_cmdline.cmake b/qt_cmdline.cmake
index 11ba47854a..9c023614a9 100644
--- a/qt_cmdline.cmake
+++ b/qt_cmdline.cmake
@@ -101,6 +101,7 @@ qt_commandline_option(platform TYPE string)
qt_commandline_option(plugin-manifests TYPE boolean)
qt_commandline_option(profile TYPE boolean)
qt_commandline_option(qreal TYPE string)
+qt_commandline_option(qtinlinenamespace TYPE boolean)
qt_commandline_option(qtlibinfix TYPE string NAME qt_libinfix)
qt_commandline_option(qtnamespace TYPE string NAME qt_namespace)
qt_commandline_option(reduce-exports TYPE boolean NAME reduce_exports)
diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt
index 98bca333db..daf98e929a 100644
--- a/src/corelib/CMakeLists.txt
+++ b/src/corelib/CMakeLists.txt
@@ -350,7 +350,11 @@ _qt_internal_setup_deploy_support()
add_dependencies(Core qmodule_pri)
if (NOT QT_NAMESPACE STREQUAL "")
- target_compile_definitions(Core PUBLIC "QT_NAMESPACE=${QT_NAMESPACE}")
+ set(core_namespace_defs "QT_NAMESPACE=${QT_NAMESPACE}")
+ if(QT_INLINE_NAMESPACE)
+ list(APPEND core_namespace_defs QT_INLINE_NAMESPACE)
+ endif()
+ target_compile_definitions(Core PUBLIC ${core_namespace_defs})
set_target_properties(Core PROPERTIES _qt_namespace "${QT_NAMESPACE}")
set_property(TARGET Core APPEND PROPERTY EXPORT_PROPERTIES _qt_namespace)
endif()
diff --git a/src/corelib/global/qtconfigmacros.h b/src/corelib/global/qtconfigmacros.h
index 6080562ab4..ee7ebca52b 100644
--- a/src/corelib/global/qtconfigmacros.h
+++ b/src/corelib/global/qtconfigmacros.h
@@ -105,6 +105,22 @@
# define QT_FORWARD_DECLARE_CLASS(name) class name;
# define QT_FORWARD_DECLARE_STRUCT(name) struct name;
+#elif defined(QT_INLINE_NAMESPACE) /* user inline namespace FIXME in Qt 7: Default */
+
+# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
+# define QT_USE_NAMESPACE
+# define QT_BEGIN_NAMESPACE inline namespace QT_NAMESPACE {
+# define QT_END_NAMESPACE }
+# define QT_BEGIN_INCLUDE_NAMESPACE }
+# define QT_END_INCLUDE_NAMESPACE inline namespace QT_NAMESPACE {
+# define QT_FORWARD_DECLARE_CLASS(name) \
+QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE
+
+# define QT_FORWARD_DECLARE_STRUCT(name) \
+QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE
+
+inline namespace QT_NAMESPACE {}
+
#else /* user namespace */
# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp
index 14c4979b6d..444e9c4ae5 100644
--- a/src/tools/rcc/rcc.cpp
+++ b/src/tools/rcc/rcc.cpp
@@ -1382,7 +1382,9 @@ bool RCCResourceLibrary::writeInitializer()
"# define QT_RCC_MANGLE_NAMESPACE(name) name\n"
"#endif\n\n");
- writeString("#ifdef QT_NAMESPACE\n"
+ writeString("#if defined(QT_INLINE_NAMESPACE)\n"
+ "inline namespace QT_NAMESPACE {\n"
+ "#elif defined(QT_NAMESPACE)\n"
"namespace QT_NAMESPACE {\n"
"#endif\n\n");
}
diff --git a/tests/auto/tools/rcc/data/images/images.expected b/tests/auto/tools/rcc/data/images/images.expected
index 15a08b77a2..b30c6ce623 100644
--- a/tests/auto/tools/rcc/data/images/images.expected
+++ b/tests/auto/tools/rcc/data/images/images.expected
@@ -115,7 +115,9 @@ TIMESTAMP:images/subdir/triangle.png
# define QT_RCC_MANGLE_NAMESPACE(name) name
#endif
-#ifdef QT_NAMESPACE
+#if defined(QT_INLINE_NAMESPACE)
+inline namespace QT_NAMESPACE {
+#elif defined(QT_NAMESPACE)
namespace QT_NAMESPACE {
#endif
diff --git a/tests/auto/tools/rcc/data/images/images.expected32 b/tests/auto/tools/rcc/data/images/images.expected32
index 8b7c7e420f..7e98fdd4fc 100644
--- a/tests/auto/tools/rcc/data/images/images.expected32
+++ b/tests/auto/tools/rcc/data/images/images.expected32
@@ -115,7 +115,9 @@ TIMESTAMP:images/subdir/triangle.png
# define QT_RCC_MANGLE_NAMESPACE(name) name
#endif
-#ifdef QT_NAMESPACE
+#if defined(QT_INLINE_NAMESPACE)
+inline namespace QT_NAMESPACE {
+#elif defined(QT_NAMESPACE)
namespace QT_NAMESPACE {
#endif
diff --git a/tests/auto/tools/rcc/data/sizes/size-0.expected b/tests/auto/tools/rcc/data/sizes/size-0.expected
index 0c38ee797c..79defe7868 100644
--- a/tests/auto/tools/rcc/data/sizes/size-0.expected
+++ b/tests/auto/tools/rcc/data/sizes/size-0.expected
@@ -57,7 +57,9 @@ TIMESTAMP:data/data-0.txt
# define QT_RCC_MANGLE_NAMESPACE(name) name
#endif
-#ifdef QT_NAMESPACE
+#if defined(QT_INLINE_NAMESPACE)
+inline namespace QT_NAMESPACE {
+#elif defined(QT_NAMESPACE)
namespace QT_NAMESPACE {
#endif
diff --git a/tests/auto/tools/rcc/data/sizes/size-1.expected b/tests/auto/tools/rcc/data/sizes/size-1.expected
index c29a378f44..925de99c32 100644
--- a/tests/auto/tools/rcc/data/sizes/size-1.expected
+++ b/tests/auto/tools/rcc/data/sizes/size-1.expected
@@ -58,7 +58,9 @@ TIMESTAMP:data/data-1.txt
# define QT_RCC_MANGLE_NAMESPACE(name) name
#endif
-#ifdef QT_NAMESPACE
+#if defined(QT_INLINE_NAMESPACE)
+inline namespace QT_NAMESPACE {
+#elif defined(QT_NAMESPACE)
namespace QT_NAMESPACE {
#endif
diff --git a/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected b/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected
index 097572504d..d858e15dba 100644
--- a/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected
+++ b/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected
@@ -95,7 +95,9 @@ TIMESTAMP:data/data-1.txt
# define QT_RCC_MANGLE_NAMESPACE(name) name
#endif
-#ifdef QT_NAMESPACE
+#if defined(QT_INLINE_NAMESPACE)
+inline namespace QT_NAMESPACE {
+#elif defined(QT_NAMESPACE)
namespace QT_NAMESPACE {
#endif
diff --git a/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected32 b/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected32
index a779dc07c8..a67e0ffc6e 100644
--- a/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected32
+++ b/tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected32
@@ -95,7 +95,9 @@ TIMESTAMP:data/data-1.txt
# define QT_RCC_MANGLE_NAMESPACE(name) name
#endif
-#ifdef QT_NAMESPACE
+#if defined(QT_INLINE_NAMESPACE)
+inline namespace QT_NAMESPACE {
+#elif defined(QT_NAMESPACE)
namespace QT_NAMESPACE {
#endif