When pulling in a module that has plugins (e.g. Gui) with find_package(), part of the CMake code path that gets invoked comes from the qtbase/cake/QtPlugins.cmake.in template. That code generates C++ sources that call the Q_IMPORT_PLUGIN macro for each associated plugin (e.g. GIF, ICO, Jpeg, etc.). These sources are added as INTERFACE sources to the module target. In a project where there is more than one such call to find_package() that brings in the module, it doesn't check if it has already added these sources and will generate and add another copy.
In the extreme case where you are building qtbase and have tests and examples enabled, there are many such calls to find_package(). This results in a blowout in files to be generated, compiled and linked for each target that links against a module like Gui. The giveaway symptom is a blow-out in CMake generation time and a huge build.ninja file.
The QtPlugins.cmake.in file needs to ensure it only generates and adds the plugin import sources once for a given module target. Note also that the module target might or might not be global. When building Qt from source, the target will be global, but when building against an installed Qt, the target will have local scope (find_package() creates imported targets which have local scope by default - this is standard CMake behavior). This means there could be multiple local targets in different scopes for the same module, so the mechanism used to track whether the generated files have been added yet needs to be recorded on the module target itself somehow.
|For Gerrit Dashboard: QTBUG-90465|
|330756,2||Only generate and add static plugin imports once per module target||dev||qt/qtbase||Status: MERGED||+2||0|