Commit Graph

18 Commits

Author SHA1 Message Date
Alexandru Croitor
0f8017efb6 CMake: Move QT_HOST_PATH check and computation into Qt6 package
Instead of trying to compute and validate the QT_HOST_PATH and
QT_HOST_PATH_CMAKE_DIR variables in the generated toolchain file,
do it in the Qt6 package.

This provides better error messages when a project is configured
without using the Qt generated toolchain file.
Because it's not done in the toolchain anymore, remove the various
host variables from __qt_toolchain_used_variables.

Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: I1ca239ff83b8f783897e171fee352fc43e8ad7a8
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-25 19:52:25 +02:00
Alexandru Croitor
7b24ffa936 CMake: Improve Qt6HostInfo package lookup condition
Instead of checking if QT_HOST_PATH is set during user project
configuration to find out if Qt6HostInfo should be looked up,
record if QT_HOST_PATH was provided during Qt configuration
into Qt6Dependencies.cmake and look up the package in a user
project based on that information.

This improves handling of the case where cmake is directly used
to configure a Qt project (instead of qt-cmake), which means no
QT_HOST_PATH might be set by the user, and then cmake would error out
saying that e.g. Qt6CoreTools is not found, instead of saying that
Qt6HostInfo is not found.

Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: I0377d5440e4b5b295af73cfd4b5188f61d48e440
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-25 19:52:22 +02:00
Alexandru Croitor
a41bef8ede CMake: Move Qt6HostInfo lookup into a function
Also replace the duplicate call in QtSetup using the
new function.
To do that, we have to actually the call it in QtBuild
after QtPublicDependencyHelpers.cmake is available.

That call is needed so that Qt6_HOST_INFO_foo variables
are available in qt_generate_qmake_and_qtpaths_wrapper_for_target.

Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: Ic5776c214bee6bedcea714b213b0e5a42c1bae06
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-25 19:52:18 +02:00
Alexandru Croitor
50d0296ed4 CMake: Suggest hints on how to debug missing packages
Depending on CMake version suggest usage of either
--debug-find-pkg or CMAKE_FIND_DEBUG_MODE to help troubleshoot
why dependent packages are not found.

To achieve that, append the hint message to the _NOT_FOUND_MESSAGE.

To ensure it works for qt dependencies, and not only tool and 3rd
party dependencies, _qt_internal_find_qt_dependencies
is modified to set variable names infixed by the target name, so the
name is consistent with the other dependency lookup functions.

The check and message are also added when a Qt6 component is not
found.

Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: I4ef23d1c53ac8e04eb72c260d6860c1eeec8d7a3
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-18 16:21:19 +02:00
Alexandru Croitor
db07310c51 CMake: Don't propagate REQUIRED to find_dependency / find_package
If find_package(Qt6 REQUIRED COMPONENTS Core) is called, don't
propagate the REQUIRED option to all the dependencies of Core,
regardless if it's a 3rd party library, tool or another Qt package
dependency.

Propagating REQUIRED causes the find_dependency -> find_package call
to exit the calling file immediately when the package is not found,
not giving an opportunity for find_dependency to set the
_NOT_FOUND_MESSAGE variable.

Instead force all find_dependency / find_package calls
to be optional, set the calling _FOUND variable to FALSE if the
dependency is not found, also set the _NOT_FOUND_MESSAGE variable.
Then the find_package call that loaded FooModuleConfig.cmake file
will show that message as the reason for the package not being
found.

Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: Idcf0b6ed6f6bb38dc082110bbd817b05e287c052
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-07-18 16:21:19 +02:00
Alexandru Croitor
6a2358e20f CMake: Remove custom Qt6 3rd party dependency implementation
Use _qt_internal_find_third_party_dependencies instead.
We rely on the inner find_dependency call to set the
Qt6_NOT_FOUND_MESSAGE message when a dependency is not found.
This implies removing the custom FATAL_ERROR handling
and relying on the parent find_package to display the
Qt6_NOT_FOUND_MESSAGE message.

We also clear Qt6_FIND_COMPONENTS if a dependency is not found.
No need to look for Qt packages if the Qt6 dependency was not met.
This reduces the amount of recursive error messages.

Pick-to: 6.4
Task-number: QTBUG-104998
Change-Id: I5c611aaededfa63eb507ec5385b37a2fb6fcc698
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-07-18 16:21:18 +02:00
Li Xinwei
bd594f9457 CMake: Use namespaced variables in Qt6*Dependencies.cmake
Pick-to: 6.2 6.1
Change-Id: I166988020cfd9750a4d58e519742215d0c03ad3e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-07-24 03:51:53 +08:00
Alexandru Croitor
b6c5e06676 CMake: Handle OPTIONAL_COMPONENTS in qt_find_package
The optional components arguments were not handled before which
caused the recorded package information for static builds to be
incorrect, it only recorded the package name without the component.

Remove REQUIRED_COMPONENTS TODO, there is no such find_package option,
it's already handled by the regular COMPONENTS code path.

Amends 07b6d3367d

Pick-to: 6.1 6.2
Fixes: QTBUG-94501
Change-Id: Ib48a7befcb70e20c3f21315897d51d3064b48134
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-06-17 23:28:18 +02:00
Joerg Bornemann
6718dea390 Revert "Revert "CMake: Add facility to mark package dependencies as optional""
This reverts commit b0c51f86f4.
The build failure caused by 58c1c6ee5c has
been fixed.

Change-Id: Ic7458d54c7a874588e8b1bfeca61df1842763656
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-09-14 15:03:14 +02:00
Joerg Bornemann
b96d350cff Revert "Revert "CMake: Reduce the number of find_dependency calls""
This reverts commit 6e1a570dc8.
The build failure caused by 58c1c6ee5c has
been fixed.

Change-Id: I67acaa2d1dd5fc88c205b054252be2e6e26898c7
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-09-14 15:03:14 +02:00
Joerg Bornemann
b9c493728a Revert "Revert "CMake: Fix usage of find_dependency()""
...and fix the build errors the original change caused.
This reverts commit 127fb8bb55.

Change-Id: I4006b32734a51c5d101dd73c957f81d2a0f84ba1
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-09-14 15:03:13 +02:00
Lars Knoll
127fb8bb55 Revert "CMake: Fix usage of find_dependency()"
This reverts commit 58c1c6ee5c.

This lead to configuration errors on some machines, blocking
development.

Change-Id: I744f6cc95fbaa273519ab8fc8fb492b87f5729b8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-09-13 12:21:06 +02:00
Lars Knoll
6e1a570dc8 Revert "CMake: Reduce the number of find_dependency calls"
This reverts commit a3cb002511.

This lead to configuration errors on some machines, blocking
development.

Change-Id: Ibb785c96c7d85692a6e22a73e086119eb571df71
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-09-13 12:21:01 +02:00
Lars Knoll
b0c51f86f4 Revert "CMake: Add facility to mark package dependencies as optional"
This reverts commit 3685483c4b.

This lead to configuration errors on some machines, blocking
development.

Change-Id: I309cdd55a8ef64899afcbeca54458d1c6d686951
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-09-13 12:20:56 +02:00
Joerg Bornemann
3685483c4b CMake: Add facility to mark package dependencies as optional
Every public dependency of a Qt module results in a find_package call in
the consuming project. But not all public dependencies are mandatory.

For example, vulkan is only needed if the user project actually uses Qt
classes that pull in vulkan headers.

This patch adds the option MARK_OPTIONAL to qt_find_package.
Dependencies that are marked as optional will not produce an error on
find failure.

Task-number: QTBUG-86421
Change-Id: Ia767e7f36991e236582c7509cbd37ea3487bb695
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-09-12 19:26:58 +02:00
Joerg Bornemann
a3cb002511 CMake: Reduce the number of find_dependency calls
...in code. The actual number of calls at runtime does not change.
The reason for this stunt is that we want to replace find_dependency
with find_package at runtime for optional dependencies, and this will
reduce the diff size of the next commit.

Change-Id: I304fdf09c69fea7b6d4adabf515712eb097f8c86
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-09-12 19:26:55 +02:00
Joerg Bornemann
58c1c6ee5c CMake: Fix usage of find_dependency()
The find_dependency() macro calls return() on failure, meaning any code
after it will be ignored, thus checking any XXX_FOUND variables after
find_dependency() is pointless.

Fix the places where we use find_dependency() and set the "failed" state
before the call and the "success" state afterwards.

Change-Id: Ia5239c704f02a9bec972210374ffed7808b14055
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-09-12 19:26:52 +02:00
Alexandru Croitor
92ee9bd6b8 CMake: Properly handle CONFIG += thread aka Threads::Threads
mkspecs/features/qt.prf adds a dependency on the system threading
library if the Qt Core thread feature is enabled. Because qt.prf is
loaded by any public or internal Qt project, it's essentially a public
dependency for any Qt consumer.

To mimic that in CMake, we check if the thread feature is enabled, and
and set the Threads::Threads library as a dependency of Qt6::Platform,
which is a public target used by all Qt modules and plugins and Qt
consumers.

We also need to create a Qt6Dependencies.cmake file so we
find_package(Threads) every time find_package(Qt6) is called.

For the .prl files to be usable, we have to filter out some
CMake implementation specific directory separator tokens
'CMAKE_DIRECTORY_ID_SEP' aka '::@', which are added because we call
target_link_libraries() with a target created in a different scope
(I think).

As a result of this change, we shouldn't have to hardcode
Threads::Threads in other projects, because it's now a global public
dependency.

Task-number: QTBUG-85801
Task-number: QTBUG-85877
Change-Id: Ib5d662c43b28e63f7da49d3bd77d0ad751220b31
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-08-06 19:15:39 +02:00