diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -11,6 +11,21 @@ set(QT_REQUIRED_COMPONENTS Core Widgets Network Test) find_package(Qt5 COMPONENTS ${QT_REQUIRED_COMPONENTS} REQUIRED HINTS "${QT5_PREFIX}") +# Add the minimal integration plugin, and other plugins according to the target +# platform. +set(QT_PLUGIN_COMPONENTS QMinimalIntegrationPlugin) +set(QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_MINIMAL=1) +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + list(APPEND QT_PLUGIN_COMPONENTS QXcbIntegrationPlugin) + list(APPEND QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_XCB=1) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + list(APPEND QT_PLUGIN_COMPONENTS QCocoaIntegrationPlugin) + list(APPEND QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_COCOA=1) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + list(APPEND QT_PLUGIN_COMPONENTS QWindowsIntegrationPlugin) + list(APPEND QT_PLUGIN_PLATFORM_DEFINITIONS -DQT_QPA_PLATFORM_WINDOWS=1) +endif() + # Find out more about Qt. This is similar to # http://code.qt.io/cgit/qt/qtwebkit.git/tree/Source/cmake/OptionsQt.cmake get_target_property(QT_CORE_TYPE Qt5::Core TYPE) @@ -49,6 +64,13 @@ # to correctly find qtpcre link_directories("${QT5_LIB_DIR}") + # If the build is static, consider that the plugins are also static. + # This simplification reduces by far the cmake script complexity, while + # still covering most if not all the use cases. + foreach(qt_plugin ${QT_PLUGIN_COMPONENTS}) + CONVERT_PRL_LIBS_TO_CMAKE(${qt_plugin}) + endforeach() + # Now that we generated the dependencies, import them. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CONVERT_PRL_PATH}") if(NOT EXISTS ${STATIC_DEPENDENCIES_CMAKE_FILE}) @@ -182,6 +204,23 @@ ${Protobuf_LIBRARIES} ) +if(QT_STATIC_BUILD) + # If the plugins are built static, we need to define QT_STATICPLUGIN. + # Setting this definition tells the code to import . + target_compile_definitions(bitcoin-qt-base PUBLIC -DQT_STATICPLUGIN=1) + + # Add the platform plugin definition if required + # Setting this definition tells the code what is the target for Q_IMPORT_PLUGIN(). + foreach(qt_platform_definition ${QT_PLUGIN_PLATFORM_DEFINITIONS}) + target_compile_definitions(bitcoin-qt-base PUBLIC "${qt_platform_definition}") + endforeach() + + # Link the required plugins + foreach(qt_plugin ${QT_PLUGIN_COMPONENTS}) + target_link_libraries(bitcoin-qt-base Qt5::${qt_plugin}) + endforeach() +endif() + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set_property(TARGET bitcoin-qt-base PROPERTY AUTOMOC_MOC_OPTIONS "-DQ_OS_MAC") endif()