Commit Graph

22 Commits

Author SHA1 Message Date
Joerg Bornemann
c9c04291f5 CMake: Add Linux support to qt_deploy_runtime_dependencies
Before this change, qt_deploy_runtime_dependencies supported Windows and
macOS only.  We add a generic deployment method implemented in
cmake-language with file(GET_RUNTIME_DEPENDENCIES).  This deployment
method is now enabled for shared builds on Linux.

The file(GRD) command requires that the EXECUTABLE argument points to
the executable in the build directory.

Only libraries in Qt's installation directory are considered for
deployment.  This includes Qt's own libraries and also things like
libicu*.so we're shipping with the installer.

Unlike macdeployqt and windeployqt, the generic
qt_deploy_runtime_dependencies does not yet support deploying
translations.  We will catch up on this in a later commit.

Change-Id: Iea23abcdba774d4c1885c8d2c243eb3e48fb7fae
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-09-15 12:55:23 +02:00
Lucie Gérard
32df595275 Change the license of all CMakeLists.txt and *.cmake files to BSD
Task-number: QTBUG-105718
Change-Id: I5d3ef70a31235868b9be6cb479b7621bf2a8ba39
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-23 23:58:42 +02:00
Lucie Gérard
fb1b20eab3 Add license headers to cmake files
CMakeLists.txt and .cmake files of significant size
(more than 2 lines according to our check in tst_license.pl)
now have the copyright and license header.

Existing copyright statements remain intact

Task-number: QTBUG-88621
Change-Id: I3b98cdc55ead806ec81ce09af9271f9b95af97fa
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-03 17:14:55 +02:00
Alexandru Croitor
4720735103 CMake: Change __qt_internal_include_plugin_packages to be a macro
The __qt_internal_include_plugin_packages function includes
PluginConfig.cmake files which in turn might look for dependencies
with find_dependency. The dependencies that were found not have their
_FOUND variables set in the calling scope, which could cause multiple
lookups of the same dependency packages.

Change the function to be macro, so that all relevant _FOUND variables
are set and no unnecessary package lookups are done.

As a result, no need to set the QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE
variable using set(PARENT_SCOPE)

Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: Iba0fc83d9e58651f095e7b70d1ed19f064c4e577
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-25 19:52:54 +02:00
Tor Arne Vestbø
f68e2c92cc cmake: Link static plugins even in shared Qt builds
It's perfectly possible to create static plugins in an otherwise shared
Qt build, but the logic to import these plugins into applications was
assuming a fully static Qt build. We now handle this more granularly.

This works for in-source tools and tests as well, which don't go through
the same CMake machinery for plugins as user projects do. The only case
that does not currently work is in-source examples, as they don't share
any of the plugin machinery with neither Qt internal tools/tests or user
project, but that's a bigger architectural issue that goes beyond this
change.

Change-Id: Ie00a97b02ac38ec4affadc447a3bfd0ec7d9c69a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-07-25 18:02:37 +02:00
Alexandru Croitor
7d6f1ee5a7 CMake: Create and include plugin packages in shared builds
Previously QtModulePlugins.cmake files were only created and
included in static library Qt builds.

Having the targets available in shared library builds would be
useful for custom project deployment purposes. One could query
the location of the plugins or use various generator expressions
referencing their location.

Ensure we always generate and include the QtModulePlugins.cmake files
regardless of the build type.

Allow opting out of including the files by setting
QT_SKIP_AUTO_PLUGIN_INCLUSION to ON, just like we allow for Qml
plugins with QT_SKIP_AUTO_QML_PLUGIN_INCLUSION.

Pick-to: 6.4
Fixes: QTBUG-94066
Change-Id: I69a5dc17762a8e43265578fc33b82b5c4b7a1f5c
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-07-05 13:04:09 +02:00
Alexandru Croitor
ff4be4cf30 CMake: Move plugin package inclusion logic into a common function
Don't duplicate the logic of plugin package inclusion for each Qt
module. Instead move it into QtPublicPluginHelpers.cmake.

Pick-to: 6.4
Task-number: QTBUG-94066
Change-Id: I5e1f5176a0e754ed56a792c97865752529462617
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-07-05 13:04:09 +02:00
Alexey Edelev
7e794d71c0 Avoid implicit linking of plugin init library if finalizers were called
Propagating of plugin init libraries should take into account
plugin finalizers to avoid duplicating of object files in a linker
line.

Pick-to: 6.2
Fixes: QTBUG-96062
Change-Id: I48feac94b08a7eb08d84134e9e9ae6e7214f5bdd
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-09-08 19:51:58 +02:00
Alexandru Croitor
d7c6d69a8c CMake: Fix 'Cannot find source file' error with older CMakes
Configuring a static plugin init library with CMake versions earlier
than 3.18.0 fails at generation phase with

CMake Error at Qt6CoreMacros.cmake:2071
(add_library):
  Cannot find source file:
    example/plugins/basictools/pnp_basictools_init.cpp
Call Stack (most recent call first):
    qtbase/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1998
  (_qt_internal_add_library)
    qtbase/lib/cmake/Qt6/QtPublicPluginHelpers.cmake:243
  (qt6_add_library)
    qtbase/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1967
  (__qt_internal_add_static_plugin_init_object_library)
    qtbase/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1989
  (qt6_add_plugin)
    qtbase/plugins/basictools/CMakeLists.txt:1 (qt_add_plugin)

Marking the generated file as GENERATED explicitly solves the issue.

Similar to e2c6f2ba7e

Fixes: QTBUG-96197
Pick-to: 6.2
Change-Id: If730a1fcbe6910d6041eb6eba03d6e45a025c424
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-09-06 10:35:36 +02:00
Alexandru Croitor
dfabb5b677 CMake: Use __qt_internal_propagate_object_library for static plugins
Address TODO and use the new helper
__qt_internal_propagate_object_library function instead of
target_sources when linking static plugin initializers via usage
requirements.

Note that to work correctly this depends on using the
target_link_options object library linking approach, which means a
minimum CMake version of 3.17, which is already the case for static
Qt usage.
With CMake 3.21, it will use target_link_libraries approach instead.

With CMake version 3.16 or lower, currently, this won't work correctly
on Linux if there are dependencies wrapped in genexes because the
__qt_internal_propagate_object_library call will try to use
the still-by-default-enabled 'object_libraries' finalizer mode via
__qt_internal_collect_dependency_object_libraries and that stops
the usage of the target_sources approach to link the object files
directly.

This isn't a big deal though, because we already require CMake 3.20
as the minimum.
It might be a bigger deal if we will need any of this functionality
to work with 3.16 in shared Qt builds where the user project tries
to create and link against custom static plugins. But that's already
likely to be a can of worms even without this specific edge case.

Amends a37957df5c
Amends 91c65dd80c
Uses 3329212815

Pick-to: 6.2
Task-number: QTBUG-92933
Change-Id: I8710e79eee265d820f65c8ccc3d0bd0c0ee6eccd
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-08-10 16:51:53 +02:00
Alexandru Croitor
5161d8d525 CMake: Remove qt6_enable_object_libraries_finalizer_mode
qt6_enable_object_libraries_finalizer_mode is not needed anymore
now that static Qt builds require CMake 3.21 and thus CMake takes
care of placing object library object files at the beginning of
the link line.

Rename qt6_enable_import_plugins_finalizer_mode to a more generic
qt6_set_finalizer_mode that can enable or disable multiple
different modes.

For now the only available mode is "static_plugins" which handles
the behavior of the old function name.

The mode can be enabled by calling

 qt6_set_finalizer_mode(${target} ENABLE MODES "static_plugins")

Note that the function is re-tagged as being in Technical Preview.

Ideally we would not need it at all. But we need to provide some
workaround for the limitations of linking Qt static plugins in CMake
on Linux-y platforms that use bfd ld or ld.gold.

The workaround does not work well with dependencies wrapped in
generator expressions which is why we can't confidently advertise it
as a proper solution.
Our hope is that this can be fixed in future upstream CMake versions
and the function can be removed.
See 6fcc272ac9 for details.

Adjust the tests due to the renamed and removed functions.

Amends 19e789bace
Amends cdbb390c4a
Amends a25027eecb
Amends 6fcc272ac9
Amends a3c430f390

Pick-to: 6.2
Fixes: QTBUG-95169
Task-number: QTBUG-95601
Task-number: QTBUG-95603
Change-Id: I51b85f776ec29fc04fed1a637eba7d1f60609e69
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-08-10 16:51:53 +02:00
Li Xinwei
a251443949 Avoid to call _qt_internal_set_up_static_runtime_library() twice
Pick-to: 6.2
Change-Id: I28985470b3e0b88befbbd2d62a027670d7d6c822
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-08-03 04:18:42 +08:00
Alexandru Croitor
51ae235080 CMake: Use correct MSVC runtime library for Qt object libraries
If Qt was configured with -static-runtime which implies MultiThreaded
-MT flag, the plugin initializer object libraries were still compiled
with the default -MD flag.

When an application linked to Qt, that caused linking to fail with
mismatched symbol errors between the application symbols and the
plugin initializer object library symbols.

Make sure to set the MSVC_RUNTIME_LIBRARY property on both plugin
initializer and resource object libraries, depending on the value of
QT_FEATURE_static_runtime.

We did set the property for resources added by
qt_internal_add_resource, but not for the resource created by
the public qt6_add_resources counterpart.

Pick-to: 6.2
Fixes: QTBUG-95043
Change-Id: Ia543cd0241db94a12080be2655ad420fe9ad3f24
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-07-09 12:44:35 +02:00
Alexandru Croitor
5ec937115b CMake: Export info if an object lib target is a plugin initializer
Needed for qtdeclarative so we can filter out which object library
should go into which export set, because qt_internal_add_qml_module
can create both a backing library export set and a plugin export set.
The plugin initializer object lib should go to the plugin export set.

Pick-to: 6.2
Task-number: QTBUG-92933
Change-Id: I0fce131eff75a0b3090ac0fbb2a12ecfcba5e38d
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-06-17 18:56:12 +02:00
Alexandru Croitor
a37957df5c CMake: Add TODO to apply generalized object library linking approach
Pick-to: 6.2
Change-Id: I1ea368e81d8b055ef353a0f021f188b45588c937
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-06-17 18:56:12 +02:00
Alexandru Croitor
602d26c38f CMake: Set the plugin class name for qml plugins
This is needed for a change in qtdeclarative to allow building the
Q_IMPORT_PLUGIN-containing object library initializer of a qml plugin.

Show an error if the qml plugin has no class name, it's needed for
plugin initialization so it's mandatory to have a class name.

Show an error if a class name is not found when computing the import
macro for a plugin (both for a regular qt plugin and a qml plugin).

When querying for the class name of a target, query both a Qt6::
prefixed target as well as a non-prefixed one, with the Qt one
taking precedence.
This is to allow querying the class name of user project created qml
plugins.

Currently regular qt user plugins don't use the object library
initializer approach. This will likely be revisited in the future.

Pick-to: 6.2
Task-number: QTBUG-92933
Change-Id: I46417471a7d8b49651e6821f7b28e7a9d44c2557
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-06-17 18:56:12 +02:00
Alexandru Croitor
a3c430f390 CMake: Revise plugin finalizer mode usage
Only use plugin finalizer mode if qt_finalize_target is called at the
end of the user project (which we can't really check, the user has to
ensure that) or when qt_finalize_target is automatically defer-called
by CMake 3.19+ (which is done by qt_add_executable).

This removes the previous behavior of using the finalizer mode if
qt_import_plugins is called. Instead the old regular mode is used
if the above preconditions are not met.

The removed behavior had ordering issues if qt_import_plugins was called
before target_link_libraries. The dependency walking would be done
before Qt dependencies were added and thus no plugins would be
linked.

Amends 6fcc272ac9

Task-number: QTBUG-80863
Task-number: QTBUG-92933
Task-number: QTBUG-94030
Change-Id: I78702b653a35596f5581c2f4282b2336f0124e60
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-05-27 14:28:17 +02:00
Alexandru Croitor
6fcc272ac9 CMake: Introduce finalizer mode handling of static plugins
Allow linking all plugin initializer object libraries directly
into the final target (executable or shared library).

The finalizer mode is triggered when the project adds a call
to qt_import_plugins, as well when the project has an explicit
call to qt_finalize_executable or when it is defer called by
CMake 3.19+.

Otherwise the old non-finalizer mode is used, where each plugin
initializer object library is propagated via the usage
requirements of its associated module.

A user can explicitly opt in or out of the new mode by calling
qt_enable_import_plugins_finalizer_mode(target TRUE/FALSE)

The implementation, at configure time, recursively collects all
dependencies of the target to extract a list of used Qt modules.

From each module we extract its list of associated plugins and
their genex conditions. These genexes are used to conditionally
link the plugins and the initializers.

Renamed QT_PLUGINS property to _qt_plugins, so we can safely query the
property even on INTERFACE libraries with lower CMake versions.
QT_PLUGINS is kept for backwards compatibility with projects already
using it, but should be removed in Qt 7.

The upside of the finalizer mode is that it avoids creating link
cycles (e.g. Gui -> SvgPlugin -> Gui case) which causes CMake to
duplicate the library on the link line, slowing down link time as well
as possibly breaking link order dependencies.

The downside is that finalizer mode can't cope with generator
expressions at the moment. So if a Qt module target is wrapped in a
generator expression, it's plugins will not be detected and thus
linked.

Task-number: QTBUG-80863
Task-number: QTBUG-92933
Change-Id: Ic40c8ae5807a154ed18fcac18b25f00864c8f143
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-05-20 00:55:46 +02:00
Alexandru Croitor
91c65dd80c CMake: Build plugin initializers as object libs
Instead of compiling the plugin initializers as part of a user
project, pre-compile them as object libraries while building Qt.

The installed object libraries can then be used with

    target_sources(qt_module INTERFACE $<TARGET_OBJECTS:plugin_init>)

so that they are linked into the final executable or shared library
via qt module usage requirement propagation.

This reduces the build times of user projects.

The link line placement of the object files should be correct for all
linux-y linkers because the only dependency for the object files is
Core and the Gui -> plugin -> Gui -> Core cycle does not hamper that
from empirical observations.

As a consequence of the recent change not to link plugin initialization
object files into static libraries, as well not having to compile the
files in user projects, we can get rid of the
_qt_internal_disable_static_default_plugins calls in various places.

A side note.

Consider a user static library (L) that links to a Qt static library
(Gui) which provides plugins (platform plugins).

If there is an executable (E) that links to (L), with no direct
dependency to any other Qt module and the intention is that the
executable will automatically get the platform plugin linked,
then (L) needs to link PUBLIC-ly to (Gui) so that the plugin usage
requirements are propagated successfully.

This is a limitation of using

  target_sources(qt_module INTERFACE $<TARGET_OBJECTS:plugin_init>)

which will propagate object files across static libraries only if
qt_module is linked publicly.

One could try to use

  target_link_libraries(qt_module
                        INTERFACE $<TARGET_OBJECTS:plugin_init>)

which preserves the linker arguments across static libs even if
qt_module is linked privately, but unfortunately CMake will lose
dependency information on Core, which means the object files might be
placed in the wrong place on the link line.
As far as I know this is a limitation of CMake that can't be worked
around at the moment.

Note this behavior was present before this change as well.

Task-number: QTBUG-80863
Task-number: QTBUG-92933
Change-Id: Ia99e8aa3d32d6197cacd6162515ac808f2c6c53f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-05-18 22:03:46 +02:00
Alexandru Croitor
5268edf581 CMake: Don't do plugin initialization for static libraries
Q_IMPORT_PLUGIN generates a global static symbol that initializes a
plugin. If this symbol is added to a static library and the library
is then linked to an executable, the linker decides that the symbol is
unused (because nothing references it) and discards it.

This means there's no point to compile the Q_IMPORT_PLUGIN containing
files into static libraries.

Change the generator expression we use for plugin propagation via
associated modules to not compile and link the plugin initialization
object file into a static library.

Pick-to: 6.1
Task-number: QTBUG-80863
Change-Id: Ide32c0124c1e313c352a72280ce32ce9fbe8fff1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-05-17 19:11:10 +02:00
Alexandru Croitor
b70a4da4f7 CMake: Hide qt plugin static import source files in a dot folder
To keep the build directory tidier.

Task-number: QTBUG-92933
Change-Id: I27213185a78b292bda7ae34bbc8161d4b5583872
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2021-05-11 18:57:17 +02:00
Alexandru Croitor
b104bedea1 CMake: Refactor handling of static plugins
Extract common static plugin handling functionality into a separate
QtPublicPluginHelpers.cmake file which is loaded by the Qt6 package.

Split the code into smaller functions that will be re-used by each
templated QtPlugins.cmake.in file, rather than copy pasting the same
code into each QtFooPlugins.cmake file.

As a drive-by, handle QtFeatures.cmake and QtFeaturesCommon.cmake
as public helper files just like QtPublicPluginHelpers.cmake.

This makes it clearer that the functions are available outside
the internal Qt build and also provides a way for not dumping new
helper functions into Qt6CoreMacros.cmake.

Task-number: QTBUG-92933
Change-Id: Id816ef009b4fac1cd317d3ef23f21b3530028067
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-05-11 18:57:17 +02:00