CMake: Run export(EXPORT) for prefixed and top-level builds

This is necessary to be able to find Qt6 modules in CMake
ExternalProjects before Qt is installed, regardless of top-level or
per-repo builds.
One use case is examples that are built as ExternalProjects.

Pick-to: 6.2 6.3
Task-number: QTBUG-90820
Task-number: QTBUG-96232
Change-Id: Ic6a9bfd1c52a04e34b221deab40f419a6fee9463
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2021-08-13 13:50:48 +02:00 committed by Alexandru Croitor
parent fb8bd02e63
commit b954a79e25

View File

@ -18,14 +18,18 @@ function(qt_install)
install(${ARGV})
endif()
# Exit early if this is a prefix build.
if(QT_WILL_INSTALL)
return()
endif()
# In a non-prefix build, when install(EXPORT) is called,
# also call export(EXPORT) to generate build tree target files.
# When install(EXPORT) is called, also call export(EXPORT)
# to generate build tree target files.
if(NOT is_install_targets AND arg_EXPORT)
# For prefixed builds (both top-level and per-repo) export build tree CMake Targets files so
# they can be used in CMake ExternalProjects. One such case is examples built as
# ExternalProjects as part of the Qt build.
# In a top-level build the exported config files are placed under qtbase/lib/cmake.
# In a per-repo build, they will be placed in each repo's build dir/lib/cmake.
if(QT_WILL_INSTALL)
qt_path_join(arg_DESTINATION "${QT_BUILD_DIR}" "${arg_DESTINATION}")
endif()
set(namespace_option "")
if(arg_NAMESPACE)
set(namespace_option NAMESPACE ${arg_NAMESPACE})