From 0e0352ab4d38ca31bb8e488783e35c2f8955e540 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 26 Jul 2022 15:51:02 +0200 Subject: [PATCH] CMake: Fix install destination of in-tree examples Previously we called _qt_internal_override_example_install_dir_to_dot in Qt6CoreConfigExtras.cmake as part of a find_package(Qt6 COMPONENTS Core) call, and we assumed that the Extras file would always be included in each example project. But our package dependencies handling code skips calling find_package(Qt6Core) if Qt6Core_FOUND is already set to TRUE, which will definitely happen due to root-scope find_package calls when configuring other repos. That means we wouldn't override INSTALL_EXAMPLEDIR to "." and the install destination would end up being something like ${CMAKE_INSTALL_PREFIX}/example_relative_path/example_relative_path aka a double nested path. Make sure we call the _qt_internal_override_example_install_dir_to_dot function in Qt6ConfigConfig.cmake in addition to Qt6CoreConfig.cmake. That way, even if Qt6Core is skipped during dependency resolution, it's still handled by the Qt6 package itself. Because the function is defined in the Core package, guard the call with an if(COMMAND) and only call the function if it wasn't previously called within the current or ancestor scopes. Amends ac4a913f333561803003650817de453f43be924d Pick-to: 6.2 6.3 6.4 Fixes: QTBUG-102879 Change-Id: Id47e3ce06faec6d156ae1473942dae0f9b90cb46 Reviewed-by: Christophe Giboudeaux Reviewed-by: Alexey Edelev --- cmake/QtConfig.cmake.in | 6 ++++++ src/corelib/Qt6CoreMacros.cmake | 1 + 2 files changed, 7 insertions(+) diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 3b38eb037d..cd7fdf7c02 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -257,6 +257,12 @@ if(@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS AND _Qt_NOTFOUND_MESSAGE) unset(_Qt_NOTFOUND_MESSAGE) endif() +if(@INSTALL_CMAKE_NAMESPACE@_FOUND + AND COMMAND _qt_internal_override_example_install_dir_to_dot + AND NOT _qt_internal_example_dir_set_to_dot) + _qt_internal_override_example_install_dir_to_dot() +endif() + __qt_internal_defer_promote_targets_in_dir_scope_to_global() if(CMAKE_VERSION VERSION_LESS 3.21) __qt_internal_check_link_order_matters() diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 2464d0677f..ca0f512828 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -2664,6 +2664,7 @@ macro(_qt_internal_override_example_install_dir_to_dot) # to CMAKE_INSTALL_PREFIX. if(QT_INTERNAL_SET_EXAMPLE_INSTALL_DIR_TO_DOT) set(INSTALL_EXAMPLEDIR ".") + set(_qt_internal_example_dir_set_to_dot TRUE) endif() endmacro()