From a1ae8bb7c07e718829ebbc17deed81e12167ddad Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 13 Jul 2022 18:51:00 +0200 Subject: [PATCH] CMake: Don't propagate REQUIRED to find_dependency / find_package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Task-number: QTBUG-104998 Change-Id: Idcf0b6ed6f6bb38dc082110bbd817b05e287c052 Reviewed-by: Jörg Bornemann (cherry picked from commit db07310c5183918346b852904938ea5f8df3ac57) Reviewed-by: Alexandru Croitor --- cmake/QtConfigDependencies.cmake.in | 4 ++++ cmake/QtModuleDependencies.cmake.in | 4 ++++ cmake/QtPublicDependencyHelpers.cmake | 3 --- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmake/QtConfigDependencies.cmake.in b/cmake/QtConfigDependencies.cmake.in index 52a0e1d2243..3f4fe7ff799 100644 --- a/cmake/QtConfigDependencies.cmake.in +++ b/cmake/QtConfigDependencies.cmake.in @@ -5,6 +5,10 @@ set(__qt_third_party_deps "@third_party_deps@") @third_party_extra@ +# Don't propagate REQUIRED so we don't immediately FATAL_ERROR, rather let the find_dependency calls +# set _NOT_FOUND_MESSAGE which will be displayed by the includer of the Dependencies file. +set(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED FALSE) + _qt_internal_find_third_party_dependencies(Platform __qt_third_party_deps) set(@INSTALL_CMAKE_NAMESPACE@_FOUND TRUE) diff --git a/cmake/QtModuleDependencies.cmake.in b/cmake/QtModuleDependencies.cmake.in index f48fe81fd1f..d2269d64a5c 100644 --- a/cmake/QtModuleDependencies.cmake.in +++ b/cmake/QtModuleDependencies.cmake.in @@ -9,6 +9,10 @@ if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES) set(__qt_use_no_default_path_for_qt_packages "") endif() +# Don't propagate REQUIRED so we don't immediately FATAL_ERROR, rather let the find_dependency calls +# set _NOT_FOUND_MESSAGE which will be displayed by the includer of the Dependencies file. +set(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED FALSE) + find_dependency(@INSTALL_CMAKE_NAMESPACE@ @main_qt_package_version@ PATHS "${CMAKE_CURRENT_LIST_DIR}/.." diff --git a/cmake/QtPublicDependencyHelpers.cmake b/cmake/QtPublicDependencyHelpers.cmake index 09242376361..ccc15bf7462 100644 --- a/cmake/QtPublicDependencyHelpers.cmake +++ b/cmake/QtPublicDependencyHelpers.cmake @@ -54,9 +54,6 @@ macro(_qt_internal_find_tool_dependencies target target_dep_list) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) list(APPEND __qt_${target}_find_package_args QUIET) endif() - if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) - list(APPEND __qt_${target}_find_package_args REQUIRED) - endif() find_package(${__qt_${target}_pkg} ${__qt_${target}_version} ${__qt_${target}_find_package_args}