Commit Graph

5 Commits

Author SHA1 Message Date
Alexandru Croitor
87ba355d95 Fix automatic plugin importing in static builds
QtPlugins.cmake.in uses file(GENERATE) and target_sources() to
propagate the generated cpp files which contain plugin initialization
code to their consuming targets.

Unfortunately due to a bug in CMake, if the file is generated in a
different scope than the consuming target, the CMake generation
step will fail saying that the source file can not be found.
See https://gitlab.kitware.com/cmake/cmake/issues/18399 for details.

In the case of qtdeclarative, find_package(Qt6) is called at the top
level scope (this is when the file gets generated),
but the targets are created in subdirectory scopes, and the GENERATED
source file property is not propagated across scropes.

Circumvent the issue by instead using file(WRITE) and configure_file()
which create the file at configure time rather than generate time.

This will pollute the current binary directory with some more files,
but at least successfully fixes the build.

Change-Id: I3ab3b12dcbf6a9d0ab9ee87173e4a1952325b37b
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Qt CMake Build Bot
2019-10-09 09:22:27 +00:00
Jean-Michaël Celerier
d1542e8a73 Match qt_import_plugin API with qt5's
Some work was needed to make the plug-in types,
and which plug-ins are available for each type
in client code.

Change-Id: Ib71feca31069deca3d3f54c8613054f5f8ae410c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Qt CMake Build Bot
2019-10-09 09:05:39 +00:00
Alexandru Croitor
59912b9558 Fix building examples when doing a Qt static build
The build failed due to two different reasons.

We tried to assign properties on an aliased target, which does not
work. Make sure to set properties on the original unaliased target.

We tried to query for the value of the QT_DEFAULT_PLUGINS property
when automatically linking to plugins, but the generator expression
failed in the AND section, because querying for an unexisting value
does not return an integer, and the AND expression expects an integer.
The fix is to wrap the relevant expression in a BOOL generator
expression.

Change-Id: Ia065bc1de939cee49e5de0b2aef70e356cc5419a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Qt CMake Build Bot
2019-07-22 18:48:17 +00:00
Jean-Michaël Celerier
a5b78a3660 cmake: implement default qpa plugin behavior for static builds
This is done by adding a DEFAULT_IF argument to add_qt_plugin, which accepts
if-evaluated expressions.

e.g.

    add_qt_plugin(myplugin
	DEFAULT_IF ${foo} STREQUAL ${bar}
        ...
    )

so that this mechanism can be reused later if necessary.

Change-Id: I7eba9adaaa28e55a4f0f94cf206e868b990027e6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-07-05 14:58:52 +00:00
Jean-Michaël Celerier
5769e1a2f6 cmake: allow client apps to load static plug-ins
Based in part on Kyle Edwards's implementation :
https://codereview.qt-project.org/c/qt/qtbase/+/243731

Example :
```
cmake_minimum_required(VERSION 3.15)
project(foo)

add_executable(foo main.cpp)

find_package(ICU COMPONENTS i18n uc data REQUIRED)
find_package(Qt6 COMPONENTS Core Gui REQUIRED)
target_link_libraries(foo Qt6::Core Qt6::Gui)

qt_import_plugins(foo
    INCLUDE
        Qt6::qxcb
    EXCLUDE
        Qt6::qgtk3 Qt6::qeglfs-kms-integration Qt6::qjpeg
)
```

Change-Id: If7736c42f669f7d7f43052cae59c28fc7fcb4156
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-07-05 14:56:56 +00:00