Commit Graph

65 Commits

Author SHA1 Message Date
Marc Mutz
51b3269eef cmake helpers: support NO_PCH_SOURCES wherever NO_UNITY_BUILD_SOURCES are
The former implies the latter, so it makes little sense to treat them
differently. Even if some types of targets are (currently) never
compiled with PCH, users of qt_internal_all_x() shouldn't need to know
such details.

Pick-to: 6.6 6.5
Change-Id: I8ead238a8d9e55da632b2929638b67724a42d73c
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-08-07 23:56:10 +02:00
Amir Masoud Abdol
ed85df8008 Improvement to NO_UNITY_BUILD_SOURCES, and fix related bugs
The source of the problem was in `qt_set_target_info_properties` which
was not able to process the NO_UNITY_BUILD_SOURCES, and therefore
leaking it into the `TARGET_COPYRIGHT`, ie., the last argument. So, I
decided to pass Unity Build arguments before them, and closer to
SOURCES, which is nicer to read, and avoid similar situation. And
I reverted the work around in the amend commit, and passing the
arguments normally.

This happens because we pass an unfiltered ${ARGN} from
qt_internal_add_executable to qt_set_target_info_properties and that the
current change is merely a workaround that ensures they get
circumstantially filtered out, because the NO_UNITY_BUILD_SOURCES option
appears before any of the first TARGET_ props.

Amend cd12c1f332

Task-number: QTBUG-99238
Task-number: QTBUG-109394
Pick-to: 6.5
Change-Id: Idb37937cf53e708425402c90f55bda8816e27f29
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-04-03 10:41:13 +00:00
Amir Masoud Abdol
cd12c1f332 Fix an issue with passing NO_UNITY_BUILD_SOURCES
Amend 31518f1a4e
Amend 3602936230

Pick-to: 6.5
Task-number: QTBUG-109394
Change-Id: Ibb2fd881c02b6496f06b8b623fa6009358755a26
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-03-15 18:18:01 +01:00
Alexandru Croitor
a804ac3d88 CMake: Relax example dependencies to be per-repo
When doing a top-level build with ExternalProject examples, it doesn't
make sense to make qtbase examples depend on e.g. qtdeclarative
plugins. Instead the qtbase example should only depend on plugins
built in qtbase.

Create per-repo custom targets that depend on all plugins built within
that particular repo.

Create an additional per-repo target which depends on all
plugins built in that repo, as well as plugins from dependent repos.
Use the latter as a dependency for examples built as part of the
current repo.

Repo dependencies are parsed from dependencies.yaml.

Pick-to: 6.5
Fixes: QTBUG-110913
Change-Id: I149860cc549caf53271c9ea296eb7bac2a663715
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2023-03-06 18:54:00 +01:00
Amir Masoud Abdol
31518f1a4e Add some utilities for UNITY_BUILD
- The following commands accepts NO_UNITY_BUILD, and
  NO_UNITY_BUILD_SOURCES arguments to opt out of the unity build, and
  to exclude some source files from unity build, respectively.
  - qt_internal_add_executable
  - qt_internal_add_module
  - qt_internal_add_plugin
  - qt_internal_add_tool
  - qt_internal_extend_target
  - qt_internal_add_common_qt_library_helper
  - qt_internal_add_cmake_library
  - qt_internal_add_simd_part
- Unity build is disabled by default in these:
  - qt_internal_add_test
  - qt_internal_add_test_helper
  - qt_internal_add_benchmark
  - qt_internal_add_3rdparty_library
- qt_update_ignore_pch_source also excludes the files from unity_build

Pick-to: 6.5
Task-number: QTBUG-109394
Change-Id: I5d0e7df633738310a015142a6c73fbb78b6c3467
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-02-08 23:47:07 +01:00
Amir Masoud Abdol
897579edab Remove the extra quote, now that we use cmake_parse_arguments(PARSE_ARGV
The extra quote enforces the arguments to be string, and stops the
COMMAND_EXPAND_LISTS within
QtDbusHelpers.cmake::qt_create_qdbusxml2cpp_command from expanding it
as a list.

Fixes: QTBUG-110459
Fixes: QTBUG-110450
Task-number: QTBUG-99238
Change-Id: Ifddd6570c7bf8f2d1757f275d9445ce2924a93f1
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-01-23 20:21:10 +01:00
Amir Masoud Abdol
7e82577680 Retire the qt_parse_all_arguments
This replaces the qt_parse_all_arguments macro with the built-in
`cmake_parse_arguments(PARSE_ARGV`. In addition, a new function,
_qt_internal_validate_all_args_are_parsed, can be used to check whether
any _UNPARSED_ARGUMENTS have been passed to the function.

Fixes: QTBUG-99238
Change-Id: I8cee83dc92dc6acdaaf747ea6ff9084c11dc649b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-01-18 14:47:12 +01:00
Joerg Bornemann
a707ae094d Fix macOS build for CMake < 3.18
We must explicitly set the GENERATED property on source files we
generate.

This amends commit f0a7d74e1d.

Change-Id: Ifab405cd98deece49a1566ae04220e2b5d576429
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-01-17 21:28:06 +01:00
Thiago Macieira
9cc0fc385e CMake: add SYSTEM_INCLUDE_DIRECTORIES to qt_internal_extend_target
This allows one to add an extra set of directories to the build, but let
the compiler know that they are system paths (that is, the compiler
should refrain from emitting warnings in code found there). This extends
INCLUDE_DIRECTORIES and is by necessity a private include set.

Will be used by qtquick3dphysics, due to its PhysX dependency.

Change-Id: I76216ced393445a4ae2dfffd1729c556db0cce3d
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-28 10:58:21 -08:00
Tor Arne Vestbø
3d03001d2d macOS: Add dependency to Foundation for permission plugins
Fixes: QTBUG-108270
Change-Id: Ic09c3422d2006e18ab355af564ac1bb3f24318c2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
2022-11-08 19:44:58 +01:00
Timur Pocheptsov
f0a7d74e1d Add permission API backend for macOS and iOS
When submitting applications to the iOS and macOS AppStore the
application goes through static analysis, which will trigger on
uses of various privacy protected APIs, unless the application
has a corresponding usage description for the permission in the
Info.plist file. This applies even if the application never
requests the given permission, but just links to a Qt library
that has the offending symbols or library dependencies.

To ensure that the application does not have to add usage
descriptions to their Info.plist for permissions they never
plan to use we split up the various permission implementations
into small static libraries that register with the Qt plugin
mechanism as permission backends. We can then inspect the
application's Info.plist at configure time and only add the
relevant static permission libraries.

Furthermore, since some permissions can be checked without any
usage description, we allow the implementation to be split up
into two separate translation units. By putting the request in
its own translation unit we can selectively include it during
linking by telling the linker to look for a special symbol.
This is useful for libraries such as Qt Multimedia who would
like to check the current permission status, but without
needing to request any permission of its own.

Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Change-Id: Ic2a43e1a0c45a91df6101020639f473ffd9454cc
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-11-03 15:02:36 +01:00
Alexey Edelev
b89d63515b Replace the syncqt.pl script with syncqt tool
syncqt.pl adds an extra dependency on perl when building Qt. Modern C++
provides the convenient cross-platform way to access a filesystem and
to use regular expressions, so we may replace the perl script with C++
application. The syncqt executable is built at configure time and
installed as QtCore tool. It's running at configure time to deliver the
required header files for IDE to build a consistent code model and at
the build time to keep tracking changes in header files and generate
the missing aliases without reconfiguring. 'syncqt' only parses header
files from a CMake build tree, so the resulting Qt installation only
contains interfacing headers that belong to the platform that Qt is
built for. 'sync.profile' files are not used as the 'source of truth'
for sync qt procedure anymore, all the necessary information is taken
from either CMake files at configure time or from the module header
files while parsing them.

syncqt.pl is still in place since it's required as fallback solution
for a smooth transition to the new syncqt implementation for all qt
repositories.

This patchset only enables the C++ based syncqt for 'qtbase'
repository.

From the performance perspective C++ version works faster then perl
script, also the configure time is reduced significally on subsequent
reconfigurations - up x2 times faster when re-configuring repository,
but it also takes time to compile the tool itself the first time.
Numbers for qtbase:
           syncqt.pl  syncqt.cpp
 initial:  0m16,035s  0m20,413s
 reconfig: 0m6,819s   0m3,725s

The syncing procedure can be run separately for each module using
<ModuleName>_sync_headers targets. The 'sync_headers' target can be
used to sync all the modules at once.

Task-number: QTBUG-87480
Task-number: QTBUG-103196
Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-09-27 13:12:11 +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
Tor Arne Vestbø
ca2979cc16 cmake: Move qt_install call into qt_generate_plugin_pri_file
The same way qt_generate_module_pri_file does it.

Change-Id: I42047ce7d23e8a289535041ccace8b0f0140ea12
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-08 16:30:35 +02:00
Tor Arne Vestbø
02a5b34c07 cmake: Defer generating plugin .pri file until finalizer
Allows adding additional properties to the target after the initial
call to qt_internal_add_plugin.

Change-Id: I7998c906e53699ec41b44b51aabbe480ae698b21
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-08 16:30:35 +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
f62412e6ec CMake: Add shared library plugin names to the QT_PLUGINS property
Otherwise we don't create a Qt6FooPlugins.cmake file in shared Qt
builds.

Adjust comment.

Amends f68e2c92cc
Related to 7d6f1ee5a7

Change-Id: I9c66d81197a4867039d5c53daf1b7edf0391c701
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-07-27 15:43:18 +02:00
Tor Arne Vestbø
2b9b5d43f4 cmake: Generate prl and pri files for static plugins in shared Qt builds
The CMake build system files are properly generated, but the qmake parts
were missing.

Change-Id: Icbcce3143db976c536c802ea2314bc3f2595da51
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-07-25 18:02:37 +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
Joerg Bornemann
df764df3ea Fix potentially wrong version in Windows resources of Qt plugins
qt_internal_add_plugin calls qt_set_target_info_properties with the
TARGET_VERSION argument and passes arg_VERSION.  However, the function
qt_internal_add_plugin does not have a VERSION argument.

If arg_VERSION is set before calling qt_internal_add_plugin, that value
will be used, and that could be wrong for the plugin.

Remove the TARGET_VERSION argument from the
qt_set_target_info_properties call.

Pick-to: 6.4
Change-Id: I0ae9e0e6636d74fdc20e6ab9ca525c5a9126000c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-07-06 12:20:40 +02:00
Alexandru Croitor
dd1030a450 CMake: Record used package version for each target dependency
When recording which package version to look for in
QtFooModuleDependencies.cmake and other files like it,
instead of using PROJECT_VERSION, use the version of the
package that contains the dependency.

For example if we're hypothetically building the qtdeclarative repo
from the 6.4 branch, against an installed 6.2 qtbase, then
the Qt6QmlModuleDependencies.cmake file will have a
find_package(Qt6Core 6.2) call because qtdeclarative's
find_package(Qt6Core) call found a 6.2 Core when it was configured.

This allows switching the versioning scheme of specific Qt modules
that might not want to follow the general Qt versioning scheme.

The first candidate would be QtWebEngine which might want to
follow the Chromium versioning scheme, something like
Qt 6.94.0 where 94 is the Chromium major version.

Implementation notes.
We now record the package version of a target in a property
called _qt_package_version. We do it for qt modules, plugins,
3rd party libraries, tools and the Platform target.

When we try to look up which version to write into the
QtFooModuleDependencies.cmake file (or the equivalent Plugins and
Tools file), we try to find the version
from a few sources: the property mentioned above, then the
Qt6{target}_VERSION variable, and finally PROJECT_VERSION.
In the latter case, we issue a warning because technically that should
never have to happen, and it's a bug or an unforeseen case if it does.

A few more places also need adjustments:
 - package versions to look for when configuring standalone
   tests and generating standalone tests Config files
 - handling of tools packages
 - The main Qt6 package lookup in each Dependencies.cmake files

Note that there are some requirements and consequences in case a
module wants to use a different versioning scheme like 6.94.0.

Requirements.
 - The root CMakeLists.txt file needs to call find_package with a
   version different from the usual PROJECT_VERSION. Ideally it
   should look for a few different Qt versions which are known to be
   compatible, for example the last stable and LTS versions, or just
   the lowest supported Qt version, e.g. 6.2.6 or whenever this change
   would land in the 6.2 branch.
 - If the repository has multiple modules, some of which need to
   follow the Qt versioning scheme and some not,
   project(VERSION x.y.z) calls need to be carefully placed in
   subdirectory scopes with appropriate version numbers, so that
   qt_internal_add_module / _tool / _plugin pick up the correct
   version.

Consequences.
 - The .so / .dylib names will contain the new version, e.g. .so.6.94
 - Linux ELF symbols will contain the new versions
 - syncqt private headers will now exist under a
   include/QtFoo/6.94.0/QtFoo/private folder
 - pri and prl files will also contain the new version numbers
 - pkg-config .pc files contain the new version numbers
 - It won't be possible to write
   find_package(Qt6 6.94 COMPONENTS WebEngineWidgets) in user code.
   One would have to write find_package(Qt6WebEngineWidgets 6.94)
   otherwise CMake will try to look for Qt6Config 6.94 which won't
   exist.
 - Similarly, a
   find_package(Qt6 6.4 COMPONENTS Widgets WebEngineWidgets) call
   would always find any kind of WebEngine package that is higher than
   6.4, which might be 6.94, 6.95, etc.
 - In the future, if we fix Qt6Config to pass EXACT to its
   subcomponent find_package calls,
   a find_package(Qt6 6.5.0 EXACT COMPONENTS Widgets WebEngineWidgets)
   would fail to find WebEngineWidgets, because its 6.94.0 version
   will not be equal to 6.5.0. Currently we don't pass through EXACT,
   so it's not an issue.

Augments 5ffc744b79

Task-number: QTBUG-103500
Change-Id: I8bdb56bfcbc7f7f6484d1e56651ffc993fd30bab
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-07-01 10:50:57 +02:00
Li Xinwei
9539c8a7f8 CMake: set correct COMPILE_PDB_NAME for static libraries
Output names of static libraries might be different from target names.
For example, the library name of Qt6::DeviceDiscoverySupportPrivate is
"Qt6DeviceDiscoverySupport.lib", and the library name of
Qt6::QTlsBackendCertOnlyPlugin is "qcertonlybackend.lib".
This commit make pdb files names consistent with the library names.

And make sure we have set correct OUTPUT_NAME property before calling
qt_set_common_target_properties()/qt_internal_set_compile_pdb_names().

Change-Id: Idb3cacd7a46a4f298fd584b927b5d726956faea8
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-05-20 17:41:20 +08:00
Alexandru Croitor
251033fb0a CMake: Work around build rpath issue when CMAKE_STAGING_PREFIX is set
CMake has logic to rewrite build rpaths that contain
CMAKE_STAGING_PREFIX to instead point to CMAKE_INSTALL_PREFIX.

This breaks running executables from the build directory, because
their build rpath will point to a location where the libraries might
not exist yet (we didn't install Qt yet).

Work around this by setting CMAKE_STAGING_PREFIX to a fake path, so
that CMake does not do the rewriting anymore.

CMAKE_STAGING_PREFIX needs to be set at subdirectory scope, not
function scope, which is why
qt_internal_apply_staging_prefix_build_rpath_workaround() is a macro
that is called from within each Qt internal function that creates
a target.

The workaround can be disabled by configuring with
-DQT_NO_STAGING_PREFIX_BUILD_RPATH_WORKAROUND=ON

The downside of this workaround is that it breaks per-subdirectory
install rules like 'ninja src/gui/install'.
Regular global installation like 'ninja install' works fine.

This is similar to what we do for tests in
qt_set_up_fake_standalone_tests_install_prefix()
introduced by 20292250d4
The reason it's not as good for other target types is because in
contrast to tests, we do want to install them.

In case if someone does call `ninja src/gui/install' they will most
likely get a permission error, telling them it's not possible to
install into
/qt_fake_staging_prefix/
 check_qt_internal_apply_staging_prefix_build_rpath_workaround

Fixes: QTBUG-102592
Change-Id: I6ce78dde1924a8d830ef5c62808ff674c9639d65
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-04-22 14:34:47 +02:00
Fabian Kosmale
57c1e8d533 build system: support module local definitions
This introduces a new helper function,
qt_internal_add_repo_local_defines and makes use of it in
qt_internal_add_{module,test,executable,benchmark,plugin}. That function
checks whether QT_EXTRA_INTERNAL_TARGET_DEFINES is set. If it is, the
defines listed in there will be aded to all targets passed to the
functions mentioned above.

The intended usage is that QT_EXTRA_INTERNAL_TARGET_DEFINES gets set
in the repository local .cmake.conf. This allows e.g. opting in to
source incompatible changes in leaf modules (as long as those are
guarded by some define).

Pick-to: 6.2 6.3
Fixes: QTBUG-101640
Change-Id: I06c3693ee69f46e95a48de724621f0c97e7cc3a8
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-03-11 20:32:08 +01:00
Alexandru Croitor
5ffc744b79 CMake: Allow disabling package version check
When building Qt repos, all find_package(Qt6) calls request a
PROJECT_VERSION version which is set in .cmake.conf via
QT_REPO_MODULE_VERSION.

This means trying to configure qtsvg from a 6.3 branch using a
6.2 qtbase won't work, because qtsvg will call find_package(Qt6 6.3)
and no such Qt6 package version exists.

There are certain scenarios where it might be useful to try to do
that though.
One of them is doing Qt development while locally mixing branches.
Another is building a 6.4 QtWebEngine against a 6.2 Qt.

Allow to opt out of the version check by configuring each Qt repo
with -DQT_NO_PACKAGE_VERSION_CHECK=TRUE. This setting is not
recorded and will have to be set again when configuring another
repo.

The version check will also be disabled by default when configuring
with the -developer-build feature. This will be recorded and embedded
into each ConfigVersion file.

If the version check is disabled, a warning will be shown mentioning
the incompatible version of a package that was found but that package
will still be accepted.
The warning will show both when building Qt or using Qt in a user
project.
The warnings can be disabled by passing
-DQT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING=TRUE

Furthermore when building a Qt repo, another warning will show when an
incompatible package version is detected, to suggest to the Qt builder
whether they want to use the incompatible version by disabling the
version check.

Note that there are no compatibility promises when using mixed
non-matching versions. Things might not work. These options are only
provided for convenience and their users know what they are doing.

Pick-to: 6.2
Fixes: QTBUG-96458
Change-Id: I1a42e0b2a00b73513d776d89a76102ffd9136422
Reviewed-by: Craig Scott <craig.scott@qt.io>
2021-10-27 16:41:26 +02:00
Alexandru Croitor
3c1125d9fe CMake: Create plugin initializers for static user plugins
Previously we only created object library static plugin initializers
for Qt plugins only, not user-project plugins.

The reason was that if a user tried to install the plugin target via
an export set, CMake would error out saying that the _init library is
not part of the same export set.

Introduce an OUTPUT_TARGETS option that would allow projects to get
the name of the generated _init target, so they can install it if
needed.
This was already done for qt6_add_qml_module, so we just introduce the
same option for qt6_add_plugin.

Now user static plugins will have an _init target created, which will
be propagated to consumers whenever the consumers link against the
plugin itself.

We also need an internal option to disable this propagation, because
it's handled a bit differently for Qt plugins which can be linked
either via finalizers or via usage requirements.

Amends 91c65dd80c

As a result of the implementation change, cleanup example projects
to ensure that they build successfully (the important part is
specifying the CLASS_NAME).

Only plugandpaint works properly with both shared and static Qt
builds.

echoplugin works with a shared Qt build, but not a static one due to
some assumptions in the C++ code about shared plugins.

styleplugin doesn't seem to work properly neither with shared Qt
builds nor static Qt builds, at least on macOS. But it builds fine.
For some reason even if the plugin is found, the style is not applied.

Amends 4caac1feea

Pick-to: 6.2
Task-number: QTBUG-80863
Task-number: QTBUG-92933
Change-Id: I6f631cda9566229b7a63992b23d7d7fa50303eeb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-08-24 16:10:31 +02:00
Kai Köhne
d6661c5622 CMake: Warn if qt_internal_plugin(target) does not end with 'Plugin'
The logic for linking plugins in a static build in Qt6*Plugins.cmake
looks up plugins that are named Qt6*PluginConfig.cmake, and the file
name is computed by the target name.

Not naming the target 'Plugin' therefore means it won't be picked up
in static builds.

Pick-to: 6.2
Task-number: QTBUG-95731
Change-Id: Ic83a29d7c91492c302eb413a69577a0c550e1a1b
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-08-12 12:43:49 +02:00
Alexandru Croitor
b2f00dfb46 CMake: Rename qt6_add_plugin TYPE option to PLUGIN_TYPE
The intention is to remove TYPE as a keyword completely before 6.2.0
release, but in case if that's not possible due to the large amount
of repositories and examples, just print a deprecation warning for
now and handle both TYPE and PLUGIN_TYPE.

Task-number: QTBUG-95170
Pick-to: 6.2
Change-Id: If0c18345483b9254b0fc21120229fcc2a2fbfbf5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-08-06 21:08:21 +02:00
Alexandru Croitor
e0a0101290 CMake: Apply bitcode flags to internal plugin object lib initializers
All internal libraries, plugins, object libraries (resources, plugin
initializers) need to be built with bitcode flags when targeting iOS.

Internal here means all libraries added by qt_internal_add_X
functions or associated with internal libraries.

We didn't do that for plugin initializers, which were added not too
long ago.

Extract the logic that links to Qt::PlatformModuleInternal into a
separate function to be used for object libraries.
Use it for resources and plugin initializers. It will also be used
in qtdeclarative for qml plugin initializers.

Pick-to: 6.2
Task-number: QTBUG-95208
Change-Id: I366996078f5e9d1c2d2797f6b81c522ee99529e3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-07-16 09:52:26 +02:00
Alexandru Croitor
3595613a0a CMake: Don't propagate -fapplication-extension to user projects
Both the compiler and linker -fapplication-extension flag should only
be applied when building Qt's libraries (not executables).

It's up to the user project whether their code will be restricted with
application-extension-only APIs.

In qmake that can be achieved by adding to the qmake project
  CONFIG += app_extension_api_only

In CMake it can be achieved by either adding the compiler and link flags
in the project directly (using target_X_options) or by setting the
appropriate setting in the Xcode project when using the Xcode
generator.

Amends e189126f1a

Pick-to: 6.2
Task-number: QTBUG-95199
Change-Id: Ie7a764d460a89c7650391abff0fcc5abfcabef64
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-07-16 09:52:24 +02:00
Joerg Bornemann
8ac8d812f7 Warn on any PUBLIC usage requirements specified for Qt plugins
Repositories have been changed to be free of this warning. We're now
changing the default of QT_WARN_PLUGIN_PUBLIC_KEYWORDS to ON.

Set this variable to OFF to disable the warnings.

Pick-to: 6.2
Change-Id: Ie37a4df1032f5b1e9152d970e8a14c574ed70241
Reviewed-by: Craig Scott <craig.scott@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-07-12 19:49:13 +02:00
Alexandru Croitor
103c1bc7ba CMake: Don't generate .pri files for qml plugins
We didn't do it in Qt 5 times and it was accidentally done for Qt 6.

There's no reason to generate them, the .pri files are only meant to
be used for regular plugins so a project can do QTPLUGINS += foo.

That mechanism is not needed for qml plugins which use
qmlimportscanner instead.

Furthermore the pri contents didn't contain a class name, so they
couldn't be used anyway.

Pick-to: 6.2
Change-Id: I6299fda21ece0f693a817ab558b45aa46b97e5ee
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-06-17 18:56:12 +02:00
Alexandru Croitor
561fc8107f CMake: Allow promoting the Qt libraries to be global targets
User projects can set the QT_PROMOTE_TO_GLOBAL_TARGETS variable to
true so that the various imported targets created by find_package(Qt6)
are promoted to global targets.

This would allow a project to find Qt packages in a subdirectory scope
while using those Qt targets from a different scope.

E.g. it fixes errors like

  CMake Error at CMakeLists.txt:5 (target_link_libraries):
  Error evaluating generator expression:

    $<TARGET_OBJECTS:Qt6::Widgets_resources_1>

  Objects of target "Qt6::Widgets_resources_1" referenced but no such
  target exists.

when trying to use a static Qt from a sibling scope.

Various 3rd party dependency targets (like Atomic or ZLIB) are not
made global due to limitations in CMake, but as long as those targets
are not mentioned directly, it shouldn't cause issues.

The targets are made global in the generated
QtFooAdditionalTargetInfo.cmake file.

To ensure that resource object libraries promoted, the generation
of the file has to be done at the end of the defining scope
where qt_internal_export_additional_targets_file is called,
which is achieved with a deferred finalizer.

Replaced all occurrences of target promotion with a helper function
which allows tracing of all promoted targets by specifying
--log-level=debug to CMake.

Pick-to: 6.2
Fixes: QTBUG-92878
Change-Id: Ic4ec03b0bc383d7e591a58c520c3974fbea746d2
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-06-16 13:22:17 +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
6969496e00 CMake: Fix auto-linking of static plugins for non-QML in-tree tests
Certain repositories like qtsvg, qtimageformats and qtvirtualkyboard
build plugins associated with Qt modules from other repositories
(qtsvg's QSvgPlugin associated to qtbase's QtGui).

When configuring in-tree tests in the same build folder as the
repository, the test executables would not automatically link to these
plugins.

Fix this by recording the existence of such plugins in a separate
property of the associated Qt module and only link them when both the
test executable and plugin are from the same project (their
PROJECT_NAME coincides).
This is in addition to linking the plugins associated with the
module where both are built in the same repository.

The logic is a bit tricky and ensures that plugins are not
accidentally initialized twice, so that in-tree tests work for both
top-level and per-repo builds.

As a drive-by, added a TODO explaining why in-tree tests that need to
link to static QML plugins won't work (somewhat unrelated to this
change).

Amends 734d2cdbc4ff6db6b3df8fffbb23dbbb565c076b
Amends b1fcdad9c9b9ad2bddd00f7301c8dd1159d523c2

Pick-to: 6.1
Task-number: QTBUG-87580
Change-Id: I3e1ff8166864f92dea931ec2ea34b6f56b4eec60
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-04-22 16:15:41 +02:00
Alexandru Croitor
c1ac201f5c CMake: Fix condition evaluation in plugin's DEFAULT_IF option
Expand the condition without an extra negation.

This fixes incorrect condition evaluation for conditions not enclosed
in parenthesis.

Pick-to: 6.1
Change-Id: I4923059b6b199676058091c23d51c9368daaebd0
Reviewed-by: Craig Scott <craig.scott@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-04-12 11:40:44 +02:00
Alexandru Croitor
ededf39142 CMake: Fix duplicate symbol errors in Windows static super builds
qt_internal_add_executable has some special logic to link static
plugins in order to avoid issues with link cycles on exported
Qt module targets. This logic does not take into account if a plugin
is a default plugin.

On windows this caused duplicate symbol linking issues in static super
builds, because both qwindows and qdirect2d define a subset of
the same symbols.

Make sure to only link to default static plugins.

This will skip linking to qdirect2d because it's not a default qpa
plugin and thus avoid linker issues.

Amends 5807e1ae81

Pick-to: 6.1 6.1.0
Fixes: QTBUG-92451
Change-Id: I56df2ce0201625088417de53038642518c1d3bbd
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Craig Scott <craig.scott@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-04-12 11:40:39 +02:00
Alexey Edelev
bbe26a7667 Skip adding externally added plugins to the plugin meta-sets
Plugin meta-sets are not visible outside of the module build tree, so
there is no point in adding dependencies for externally added plugins.

Change-Id: Ica5b29b57c032f4fc9b128172aaa806392e9e581
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-04-08 16:15:54 +02:00
Alexey Edelev
ae70011377 Remove use of qt_internal_module_info from qt_internal_add_plugin
Plugin targets don't fit the requirements of the module but use
the function associated to the module. The purpose of using
qt_internal_module_info is to get the path to the top-level include
directory. So there is no point in breaking the encapsulation rules
to get a well-known directory.

Change-Id: If3d2a31d4ec186929e3d662a79a1ae9eac988d1a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-04-07 10:03:41 +02:00
Lorn Potter
4972fdb350 wasm: add cmake build support
A few configure defines get changed:
QMAKE_WASM_PTHREAD_POOL_SIZE is now QT_WASM_PTHREAD_POOL_SIZE
QMAKE_WASM_TOTAL_MEMORY is now QT_WASM_INITIAL_MEMORY
QMAKE_WASM_SOURCE_MAP_BASE is now QT_WASM_SOURCE_MAP_BASE

device-option EMSCRIPTEN_ASYNCIFY=1 is QT_EMSCRIPTEN_ASYNCIFY=1

To create source maps for debugging. use
device-option QT_WASM_SOURCE_MAP=1

Task-number: QTBUG-78647
Change-Id: If9f30cd7fb408c386d6d69b5f7b1beecf1ab44b5
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-04-01 19:23:42 +10:00
Craig Scott
256dea0df7 Avoid using prohibited target property names with INTERFACE targets
CMake 3.19 removed the restrictions on allowable names for properties
on INTERFACE targets. With earlier CMake versions (back to CMake 3.11),
names for custom properties must begin with either a lowercase letter
or an underscore.

In 5807e1ae81 (Add plugins to Qt tools and executables for static
builds, 2021-03-19), the names QT_REPO_PLUGIN_CLASS_NAMES and
QT_REPO_PLUGINS were used, but in some cases, the targets on which they
were being set are INTERFACE targets. Replace these with names that
are supported with CMake 3.11 or later.

Amends 5807e1ae81

Task-number: QTBUG-91915
Pick-to: 6.1
Change-Id: Ife702a1fb339b190d46a8dafb380253219199ba6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-03-31 18:30:04 +11:00
Alexandru Croitor
4ffaaaf118 CMake: Semi-handle non-current repo qt modules when creating plugins
In the recent refactoring of qt_internal_add_plugin, a new target
existence check was added when associating a plugin with a qt module.
That check didn't account for a qualified qt module target name.

This failed configuration of qtsvg which checked for the existence of
a namespace-less 'Gui' in a per-repo build.

Make sure to prepend the Qt namespace to the qt module name and also
handle aliased target names.

As a drive-by, add a TODO item to figure out how to link executables
to plugins who's plugin type belong to a different repo, but both the
executable and plugin are built in the current repo.

Amends aa4a1006cb

Fixes: QTBUG-92235
Change-Id: I1c0f83672ab00f4702be9bad9a66ccc35e82f5c8
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit 734d2cdbc4ff6db6b3df8fffbb23dbbb565c076b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2021-03-31 02:38:02 +00:00
Alexey Edelev
361daa2990 Fix plugin SKIP_INSTALL option
If SKIP_INSTALL option is specified for the qt_internal_add_plugin
function the install_directory variable become empty and finalizer unable
to call qt_finalize_plugin, because of lack of the second argument. It
makes sense to use the INSTALL_PATH single argument instead.

Change-Id: I2d4b40c8cf812a834c0e045569b45a649d339508
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-03-29 18:49:40 +02:00
Craig Scott
aa4a1006cb Refactor qt_internal_add_plugin() and qt6_add_plugin()
Remove code duplication by calling qt6_add_plugin() from
qt_internal_add_plugin().

Separate out the public and internal arguments for the
variables defined in QtBuild.cmake for these functions.
Provide them via commands instead for greater robustness.
This separation allows other Qt repos to access the appropriate
set of keywords where they define commands that forward
on to *_add_plugin() in their implementations. Retain
the old variables for now to simplify the integration
steps for updating other repos. The old variables can
be removed once there are no more references left to
them in any repo.

Task-number: QTBUG-88763
Pick-to: 6.1
Change-Id: I0105523afd95995923bd20fc963d245bbb15d34d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-03-29 18:10:22 +11:00
Craig Scott
5807e1ae81 Add plugins to Qt tools and executables for static builds
In static builds, we cannot allow any part of the main build to make a
call to find_package(Qt6...) where such a call may load a
Qt6*Plugins.cmake file. That would add additional dependencies to the
main module targets, setting up a circular dependency in the set of
*Config.cmake files which cannot be resolved. This scenario would be
triggered by per-repo builds or user projects.

But Qt's tools and other executables still need to load some plugins
in static builds. Sometimes a platform plugin may be enough, other
times we may want all supportable plugins (e.g. Qt Designer).
Therefore, add all plugins we can identify as relevant for an
executable that is part of the Qt build, but add them directly to the
executable without affecting the linking relationships between the
main module libraries.

Also remove the now unnecessary check for QT_BUILD_PROJECT_NAME in
top level builds because there should be no difference between per-repo
and top level builds any more (as far as linking static plugins is
concerned).

Examples that build as part of the main build will still build
successfully after this change, but they will not run if they require
a platform plugin. Examples need to be moved out to a separate build
where they can call find_package(Qt6) without QT_NO_CREATE_TARGETS
set to TRUE to be runnable (see QTBUG-90820).

Fixes: QTBUG-91915
Pick-to: 6.1
Change-Id: I8088baddb54e394ca111b103313596d6743570ba
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-03-23 11:15:33 +11:00
Joerg Bornemann
82d50925f1 Fix build of QTuioTouchPlugin with Makefile generator on macOS
For each plugin, we create a custom target with it's OUTPUT_NAME such
that one simply can do 'ninja qtuiotouchplugin' to build it.

QTuiTouchPlugin has qtuiotouchplugin as OUTPUT_NAME, which is
problematic with Makefile generators on case-insensitive file systems.
See CMake upstream issue #21915 for details.

Work around this issue by not creating the custom target in this
situation.

Pick-to: 6.1
Fixes: QTBUG-84342
Change-Id: Id9a6cf0a01c179d5c93da4146e393cf00153ac4f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-03-11 11:29:25 +00:00
Craig Scott
78a64e310e qtdeclarative now directly handles more qml-specific logic
Associated changes in the qtdeclarative repo now ensure that arguments
for qml plugins are handled on the calling side. This reduces the
qml-specific logic needed in qtbase and gives qtdeclarative clearer
control over qml build and install locations.

As part of that work, the INSTALL_LOCATION keyword used in
qt_internal_record_rcc_object_files() has been renamed to
INSTALL_DIRECTORY to make it consistent with the keyword used for the
same concept in other commands.

Pick-to: 6.1
Change-Id: Iebd319899f63d79fbe15ce965b84ce324c28a508
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-03-10 18:46:48 +11:00
Craig Scott
c6bbca7486 Make qt_get_module_for_plugin() internal and do what its name says
Contrary to its name, this command was also setting a target property.
Since it was only called in one place and that caller can just as
easily set the property instead, rename the command to make clear its
internal nature and refactor it so that the caller is responsible for
setting that property instead.

Also make it an error rather than just a warning if the command is used
for a target that doesn't belong to any module. Since this is now
unambiguously an internal command, we should always expect the target
to belong to a module.

Pick-to: 6.1
Change-Id: I929a652ddd482653868fc9df887f38f4bc7f35d9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-03-02 16:44:45 +11:00
Craig Scott
fe29159aad cmake: Don't give plugins PUBLIC usage requirements
The pro2cmake.py conversion script faithfully reproduced the .pro files
for the plugins, which specified the libraries as public. But in CMake,
the implications of this are that public usage requirements should then
be propagated to consumers. We don't expect any consumers, since a
plugin is created as a MODULE library in CMake, so for Windows we don't
even have an import library to link with. The only exception to this is
for static builds where plugins are created as STATIC libraries
instead, but only in certain controlled situations do we then link to
plugins. Even then, usage requirements are not expected to propagate to
the consumers, so these relationships should always be specified as
private.

This change warns on any PUBLIC usage requirements specified for a
plugin. This check is disabled by default to avoid spamming CI builds
for repos that haven't been fixed yet. The check can be enabled by a
CMake cache option, which is intended for developers to use locally
when fixing this issue in other repos (all plugins in qtbase should
not trigger this warning as a result of changes in this commit).

Task-number: QTBUG-90819
Pick-to: 6.1
Change-Id: I09f2c8da77db1193ad3370f85d367dfc6ab7b9a6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-02-24 10:37:49 +11:00
Alexey Edelev
dac4d5a492 Clear non-relevant CMake compiler flags
Add internal function to cleanup compiler flags out of the
CMAKE_xxx_FLAGS_xxx variables. Use introduced interface to clear
the '/EHsc' flag for the MSVC compiler family. This adjusts the
CMake behavior to the qmake one.

Change the 'EXCEPTIONS' option handling in helper functions. Add
ability to add enabling and disabling exception flags. Previously
it was only possible to add disabling exception flags.

Fixes: QTBUG-89952
Change-Id: I60d47660a97ae9b5a1d1f4107d352c9e97890144
Reviewed-by: Craig Scott <craig.scott@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-01-27 20:44:16 +01:00