Skip to content

Commit

Permalink
Merge #103: cmake: Do not interfere with Qt plugin handling
Browse files Browse the repository at this point in the history
f3b3928 fixup! cmake: Build `bitcoin-qt` executable (Hennadii Stepanov)
3c27391 qt: Drop `Q_IMPORT_PLUGIN` macros (Hennadii Stepanov)
edc8c18 qt, build: Drop `QT_STATICPLUGIN` macro (Hennadii Stepanov)

Pull request description:

  1. When using CMake, each plugin comes with a C++ stub file that automatically initializes the static plugin. Consequently, any target that links against a plugin has this C++ file added to its `SOURCES`, which makes the removed code redundant and [duplicates](#103 (comment)) the included plugins. For example, on the staging branch @ 1a976ca:
  ```
  2024-03-01T10:51:26Z Bitcoin Core version v26.99.0-1a976ca427ca (release build)
  2024-03-01T10:51:26Z Qt 5.15.11 (static), plugin=windows (static)
  2024-03-01T10:51:26Z Static plugins:
  2024-03-01T10:51:26Z  QWindowsIntegrationPlugin, version 331520
  2024-03-01T10:51:26Z  QWindowsVistaStylePlugin, version 331520
  2024-03-01T10:51:26Z  QWindowsVistaStylePlugin, version 331520
  2024-03-01T10:51:26Z  QWindowsIntegrationPlugin, version 331520
  2024-03-01T10:51:26Z Style: windowsvista / QWindowsVistaStyle
  2024-03-01T10:51:26Z System: Windows 11 Version 2009, x86_64-little_endian-llp64
  2024-03-01T10:51:26Z Screen: \\.\DISPLAY1 1920x1080, pixel ratio=1.0
  ```

  Initially noticed in #101 (review).

  Here are `LogQtInfo()` outputs in the `debug.log`:
  - `x86_64-pc-linux-gnu`:
  ```
  2024-02-25T10:15:18Z Qt 5.15.11 (static), plugin=xcb (static)
  2024-02-25T10:15:18Z Static plugins:
  2024-02-25T10:15:18Z  QXcbIntegrationPlugin, version 331520
  2024-02-25T10:15:18Z Style: fusion / QFusionStyle
  2024-02-25T10:15:18Z System: Ubuntu 22.04.4 LTS, x86_64-little_endian-lp64
  2024-02-25T10:15:18Z Screen: XWAYLAND0 1920x1080, pixel ratio=1.0
  ```
  - `x86_64-w64-mingw32`
  ```
  2024-02-25T10:44:54Z Qt 5.15.11 (static), plugin=windows (static)
  2024-02-25T10:44:54Z Static plugins:
  2024-02-25T10:44:54Z  QWindowsVistaStylePlugin, version 331520
  2024-02-25T10:44:54Z  QWindowsIntegrationPlugin, version 331520
  2024-02-25T10:44:54Z Style: windowsvista / QWindowsVistaStyle
  2024-02-25T10:44:54Z System: Windows 11 Version 2009, x86_64-little_endian-llp64
  2024-02-25T10:44:54Z Screen: \\.\DISPLAY1 1600x900, pixel ratio=1.0
  ```

  ---

  2. Apparently, Qt tries to link its default set of static plugins to every suitable target. When building on Windows, it leads to an insane list of plugins:
  ```
  2024-03-01T19:11:04Z Qt 5.15.10 (static), plugin=windows (dynamic)
  2024-03-01T19:11:04Z Static plugins:
  2024-03-01T19:11:04Z  QGifPlugin, version 331520
  2024-03-01T19:11:04Z  QICNSPlugin, version 331520
  2024-03-01T19:11:04Z  QICOPlugin, version 331520
  2024-03-01T19:11:04Z  QJpegPlugin, version 331520
  2024-03-01T19:11:04Z  QSvgIconPlugin, version 331520
  2024-03-01T19:11:04Z  QSvgPlugin, version 331520
  2024-03-01T19:11:04Z  QTgaPlugin, version 331520
  2024-03-01T19:11:04Z  QTiffPlugin, version 331520
  2024-03-01T19:11:04Z  QWbmpPlugin, version 331520
  2024-03-01T19:11:04Z  QWebpPlugin, version 331520
  2024-03-01T19:11:04Z  QWindowsIntegrationPlugin, version 331520
  2024-03-01T19:11:04Z  QWindowsVistaStylePlugin, version 331520
  ```

  Therefore, in this PR, we prevent Qt from such a behaviour.

ACKs for top commit:
  m3dwards:
    ACK f3b3928

Tree-SHA512: e77aad13349b6938d1c4c48c12a2e32226ef9b2c9e52e021df94a9a21b6bd0e42685f73f032eb5bfded9438f16edf2badac775200e941e18d73da85b0b817d3c
  • Loading branch information
hebasto committed Mar 8, 2024
2 parents 8478fcf + f3b3928 commit 2716ccf
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 50 deletions.
1 change: 0 additions & 1 deletion build-aux/m4/bitcoin_qt.m4
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[
fi
fi
AC_DEFINE([QT_STATICPLUGIN], [1], [Define this symbol if qt plugins are static])
if test "$TARGET_OS" != "android"; then
_BITCOIN_QT_CHECK_STATIC_PLUGIN([QMinimalIntegrationPlugin], [-lqminimal])
AC_DEFINE([QT_QPA_PLATFORM_MINIMAL], [1], [Define this symbol if the minimal qt platform exists])
Expand Down
3 changes: 0 additions & 3 deletions build_msvc/bitcoin_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@
/* Define this symbol if the qt platform is windows */
#define QT_QPA_PLATFORM_WINDOWS 1

/* Define this symbol if qt plugins are static */
#define QT_STATICPLUGIN 1

/* Windows Universal Platform constraints */
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
/* Either a desktop application without API restrictions, or and older system
Expand Down
34 changes: 25 additions & 9 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

function(import_plugins target)
if(CMAKE_CROSSCOMPILING OR VCPKG_TARGET_TRIPLET MATCHES "-static")
set(plugins Qt5::QMinimalIntegrationPlugin)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND plugins Qt5::QXcbIntegrationPlugin)
elseif(WIN32)
list(APPEND plugins Qt5::QWindowsIntegrationPlugin Qt5::QWindowsVistaStylePlugin)
elseif(APPLE)
list(APPEND plugins Qt5::QCocoaIntegrationPlugin Qt5::QMacStylePlugin)
endif()
qt5_import_plugins(${target}
INCLUDE ${plugins}
EXCLUDE_BY_TYPE imageformats iconengines
)
endif()
endfunction()

# See:
# - https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html
# - https://doc.qt.io/qt-5/cmake-manual.html
Expand Down Expand Up @@ -140,15 +157,12 @@ if(ENABLE_WALLET)
)
endif()

if(CMAKE_CROSSCOMPILING)
target_compile_definitions(bitcoinqt PRIVATE QT_STATICPLUGIN)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND TARGET Qt5::QXcbIntegrationPlugin)
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_XCB)
elseif(WIN32 AND TARGET Qt5::QWindowsIntegrationPlugin AND TARGET Qt5::QWindowsVistaStylePlugin)
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_WINDOWS)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND TARGET Qt5::QCocoaIntegrationPlugin AND TARGET Qt5::QMacStylePlugin)
target_compile_definitions(bitcoinqt PRIVATE QT_QPA_PLATFORM_COCOA)
endif()
if(CMAKE_CROSSCOMPILING OR VCPKG_TARGET_TRIPLET MATCHES "-static")
# We want to define static plugins to link ourselves, thus preventing
# automatic linking against a "sane" set of default static plugins.
qt5_import_plugins(bitcoinqt
EXCLUDE_BY_TYPE bearer iconengines imageformats platforms styles
)
endif()

add_executable(bitcoin-qt
Expand All @@ -164,6 +178,8 @@ target_link_libraries(bitcoin-qt
bitcoin_node
)

import_plugins(bitcoin-qt)

if(WIN32)
set_target_properties(bitcoin-qt PROPERTIES WIN32_EXECUTABLE TRUE)
endif()
Expand Down
15 changes: 0 additions & 15 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,6 @@
#include <QTranslator>
#include <QWindow>

#if defined(QT_STATICPLUGIN)
#include <QtPlugin>
#if defined(QT_QPA_PLATFORM_XCB)
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
#elif defined(QT_QPA_PLATFORM_WINDOWS)
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin);
#elif defined(QT_QPA_PLATFORM_COCOA)
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
Q_IMPORT_PLUGIN(QMacStylePlugin);
#elif defined(QT_QPA_PLATFORM_ANDROID)
Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
#endif
#endif

// Declare meta types used for QMetaObject::invokeMethod
Q_DECLARE_METATYPE(bool*)
Q_DECLARE_METATYPE(CAmount)
Expand Down
7 changes: 1 addition & 6 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,7 @@ void LogQtInfo()
#else
const std::string qt_link{"dynamic"};
#endif
#ifdef QT_STATICPLUGIN
const std::string plugin_link{"static"};
#else
const std::string plugin_link{"dynamic"};
#endif
LogPrintf("Qt %s (%s), plugin=%s (%s)\n", qVersion(), qt_link, QGuiApplication::platformName().toStdString(), plugin_link);
LogPrintf("Qt %s (%s), plugin=%s\n", qVersion(), qt_link, QGuiApplication::platformName().toStdString());
const auto static_plugins = QPluginLoader::staticPlugins();
if (static_plugins.empty()) {
LogPrintf("No static plugins.\n");
Expand Down
16 changes: 0 additions & 16 deletions src/qt/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@

#include <functional>

#if defined(QT_STATICPLUGIN)
#include <QtPlugin>
#if defined(QT_QPA_PLATFORM_MINIMAL)
Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin);
#endif
#if defined(QT_QPA_PLATFORM_XCB)
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
#elif defined(QT_QPA_PLATFORM_WINDOWS)
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
#elif defined(QT_QPA_PLATFORM_COCOA)
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
#elif defined(QT_QPA_PLATFORM_ANDROID)
Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
#endif
#endif

const std::function<void(const std::string&)> G_TEST_LOG_FUN{};

const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{};
Expand Down

0 comments on commit 2716ccf

Please sign in to comment.