Skip to content

Commit

Permalink
Add support for using an inline namespaces for -qtnamespace
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
FriedemannKleint committed Apr 3, 2024
1 parent e23ea6a commit fdac1e2
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmake/QtProcessConfigureArgs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmake/configure-cmake-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
1 change: 1 addition & 0 deletions config_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions qt_cmdline.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/corelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions src/corelib/global/qtconfigmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/tools/rcc/rcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 3 additions & 1 deletion tests/auto/tools/rcc/data/images/images.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/auto/tools/rcc/data/images/images.expected32
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/auto/tools/rcc/data/sizes/size-0.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/auto/tools/rcc/data/sizes/size-1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/auto/tools/rcc/data/sizes/size-2-0-35-1.expected32
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fdac1e2

Please sign in to comment.