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) @@ -22,42 +37,6 @@ get_target_property(QT_CORE_LIB_LOCATION Qt5::Core LOCATION) get_filename_component(QT5_LIB_DIR "${QT_CORE_LIB_LOCATION}" DIRECTORY) -set(STATIC_DEPENDENCIES_CMAKE_FILE "${CMAKE_BINARY_DIR}/QtStaticDependencies.cmake") -if(EXISTS ${STATIC_DEPENDENCIES_CMAKE_FILE}) - file(REMOVE ${STATIC_DEPENDENCIES_CMAKE_FILE}) -endif() - -set(CONVERT_PRL_PATH "${CONTRIB_PATH}/qt/convert-prl-libs-to-cmake.pl") -macro(CONVERT_PRL_LIBS_TO_CMAKE _qt_component) - if(TARGET Qt5::${_qt_component}) - get_target_property(_lib_location Qt5::${_qt_component} LOCATION) - execute_process(COMMAND ${PERL_EXECUTABLE} "${CONVERT_PRL_PATH}" - --lib "${_lib_location}" - --qt_lib_install_dir "${QT5_LIB_DIR}" - --out "${STATIC_DEPENDENCIES_CMAKE_FILE}" - --component "${_qt_component}" - --compiler "${CMAKE_CXX_COMPILER_ID}" - ) - endif() -endmacro() - -if(QT_STATIC_BUILD) - foreach(qt_module ${QT_REQUIRED_COMPONENTS}) - CONVERT_PRL_LIBS_TO_CMAKE(${qt_module}) - endforeach() - # HACK: We must explicitly add LIB path of the Qt installation - # to correctly find qtpcre - link_directories("${QT5_LIB_DIR}") - - # 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}) - message(FATAL_ERROR "Unable to find ${STATIC_DEPENDENCIES_CMAKE_FILE}") - endif() - include(${STATIC_DEPENDENCIES_CMAKE_FILE}) - list(REMOVE_DUPLICATES STATIC_LIB_DEPENDENCIES) -endif() - # Localisation add_subdirectory(locale) @@ -174,6 +153,65 @@ ${Protobuf_LIBRARIES} ) +set(STATIC_DEPENDENCIES_CMAKE_FILE "${CMAKE_BINARY_DIR}/QtStaticDependencies.cmake") +if(EXISTS ${STATIC_DEPENDENCIES_CMAKE_FILE}) + file(REMOVE ${STATIC_DEPENDENCIES_CMAKE_FILE}) +endif() + +set(CONVERT_PRL_PATH "${CONTRIB_PATH}/qt/convert-prl-libs-to-cmake.pl") +macro(CONVERT_PRL_LIBS_TO_CMAKE _qt_component) + if(TARGET Qt5::${_qt_component}) + get_target_property(_lib_location Qt5::${_qt_component} LOCATION) + execute_process(COMMAND ${PERL_EXECUTABLE} "${CONVERT_PRL_PATH}" + --lib "${_lib_location}" + --qt_lib_install_dir "${QT5_LIB_DIR}" + --out "${STATIC_DEPENDENCIES_CMAKE_FILE}" + --component "${_qt_component}" + --compiler "${CMAKE_CXX_COMPILER_ID}" + ) + endif() +endmacro() + +if(QT_STATIC_BUILD) + # According to Qt documentation (https://doc.qt.io/qt-5/plugins-howto.html): + # "Plugins can be linked statically into your application. + # If you build the static version of Qt, this is the only option for + # including Qt's predefined plugins." + # So if the Qt build is static, the plugins should be statically linked. + list(APPEND QT_REQUIRED_COMPONENTS ${QT_PLUGIN_COMPONENTS}) + + foreach(qt_module ${QT_REQUIRED_COMPONENTS}) + CONVERT_PRL_LIBS_TO_CMAKE(${qt_module}) + endforeach() + # HACK: We must explicitly add LIB path of the Qt installation + # to correctly find qtpcre + link_directories("${QT5_LIB_DIR}") + + # 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}) + message(FATAL_ERROR "Unable to find ${STATIC_DEPENDENCIES_CMAKE_FILE}") + endif() + include(${STATIC_DEPENDENCIES_CMAKE_FILE}) + list(REMOVE_DUPLICATES STATIC_LIB_DEPENDENCIES) + + # If the build is static, the plugins should also be static and 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()