Link only applications against static Qt plugins

* Which plugins should be included should only be decided
  when building the final application and not before.
* Also prevents those libs from appearing in pkg-config
  files.
This commit is contained in:
Martchus 2017-10-08 19:26:56 +02:00
parent 68b0e1a044
commit d65835be50
1 changed files with 18 additions and 20 deletions

View File

@ -70,32 +70,30 @@ foreach(KF_MODULE ${IMPORTED_KF_MODULES})
endforeach()
# built-in platform, imageformat and iconengine plugins when linking statically against Qt Gui
# -> determine which targets link statically against Qt Gui
set(USING_STATIC_QT_GUI_FOR_SHARED_TARGET NO)
set(USING_STATIC_QT_GUI_FOR_STATIC_TARGET NO)
foreach(MODULE Gui Widgets Quick)
if(NOT USING_STATIC_QT_GUI_FOR_SHARED_TARGET AND (QT5_${MODULE}_STATIC_LIB IN_LIST LIBRARIES OR QT5_${MODULE}_STATIC_LIB IN_LIST PRIVATE_LIBRARIES))
set(USING_STATIC_QT_GUI_FOR_SHARED_TARGET YES)
message(STATUS "Linking shared target of project ${META_PROJECT_NAME} against static Qt 5 plugins.")
endif()
if(NOT USING_STATIC_QT_GUI_FOR_STATIC_TARGET AND (QT5_${MODULE}_STATIC_LIB IN_LIST STATIC_LIBRARIES OR QT5_${MODULE}_STATIC_LIB IN_LIST PRIVATE_STATIC_LIBRARIES))
set(USING_STATIC_QT_GUI_FOR_STATIC_TARGET YES)
message(STATUS "Linking static target of project ${META_PROJECT_NAME} against static Qt 5 plugins.")
endif()
endforeach()
# -> determine whether application target links statically against Qt Gui
if(META_PROJECT_TYPE STREQUAL "application")
set(USING_STATIC_QT_GUI_FOR_APPLICATION NO)
foreach(MODULE Gui Widgets Quick)
if(QT5_${MODULE}_STATIC_LIB IN_LIST LIBRARIES OR QT5_${MODULE}_STATIC_LIB IN_LIST PRIVATE_LIBRARIES)
set(USING_STATIC_QT_GUI_FOR_APPLICATION YES)
message(STATUS "Linking application ${META_PROJECT_NAME} against static Qt 5 plugins.")
break()
endif()
endforeach()
endif()
# -> link against plugins according to platform and configuration
if(USING_STATIC_QT_GUI_FOR_SHARED_TARGET OR USING_STATIC_QT_GUI_FOR_STATIC_TARGET)
if(USING_STATIC_QT_GUI_FOR_APPLICATION)
if(NOT USE_STATIC_QT5_Gui)
find_qt5_module(Gui REQUIRED)
endif()
# ensure platform integration plugins for corresponding platforms are built-in when creating a GUI application
if(WIN32)
use_static_qt5_plugin(Gui WindowsIntegration ${USING_STATIC_QT_GUI_FOR_SHARED_TARGET} ${USING_STATIC_QT_GUI_FOR_STATIC_TARGET})
use_static_qt5_plugin(Gui WindowsIntegration ON OFF)
elseif(APPLE)
use_static_qt5_plugin(Gui CocoaIntegration ${USING_STATIC_QT_GUI_FOR_SHARED_TARGET} ${USING_STATIC_QT_GUI_FOR_STATIC_TARGET})
use_static_qt5_plugin(Gui CocoaIntegration ON OFF)
elseif(TARGET ${QT5_Gui_STATIC_PREFIX}QXcbIntegrationPlugin)
use_static_qt5_plugin(Gui XcbIntegration ${USING_STATIC_QT_GUI_FOR_SHARED_TARGET} ${USING_STATIC_QT_GUI_FOR_STATIC_TARGET})
use_static_qt5_plugin(Gui XcbIntegration ON OFF)
else()
message(WARNING "The required platform plugin for your platform is unknown an can not be linked in statically.")
endif()
@ -108,7 +106,7 @@ if(USING_STATIC_QT_GUI_FOR_SHARED_TARGET OR USING_STATIC_QT_GUI_FOR_STATIC_TARGE
set(SVG_SUPPORT ON)
list(REMOVE_ITEM IMAGE_FORMAT_SUPPORT Svg)
else()
use_static_qt5_plugin(Gui "${IMAGE_FORMAT}" ${USING_STATIC_QT_GUI_FOR_SHARED_TARGET} ${USING_STATIC_QT_GUI_FOR_STATIC_TARGET})
use_static_qt5_plugin(Gui "${IMAGE_FORMAT}" ON OFF)
endif()
endforeach()
@ -122,10 +120,10 @@ if(USING_STATIC_QT_GUI_FOR_SHARED_TARGET OR USING_STATIC_QT_GUI_FOR_STATIC_TARGE
find_qt5_module(Svg REQUIRED)
endif()
if(SVG_SUPPORT)
use_static_qt5_plugin(Svg Svg ${USING_STATIC_QT_GUI_FOR_SHARED_TARGET} ${USING_STATIC_QT_GUI_FOR_STATIC_TARGET})
use_static_qt5_plugin(Svg Svg ON OFF)
endif()
if(SVG_ICON_SUPPORT)
use_static_qt5_plugin(Svg SvgIcon ${USING_STATIC_QT_GUI_FOR_SHARED_TARGET} ${USING_STATIC_QT_GUI_FOR_STATIC_TARGET})
use_static_qt5_plugin(Svg SvgIcon ON OFF)
endif()
endif()