summaryrefslogtreecommitdiffstats
path: root/cmake/QtConfig.cmake.in
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-08-02 16:02:04 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-08-06 17:00:21 +0200
commit825cb50c27fc0942a76771f9fb2ec052dc9142bf (patch)
tree2fbe555c9b1061a31aea43e9d29e3af146277253 /cmake/QtConfig.cmake.in
parent9b860ece42e4012821b7e2140f363dbe3e256062 (diff)
CMake: Improve component / package not found error messages
Provide better error messages when a Qt package / component is not found. Mention the location of the expected Config file on the file system, whether it exists Also mention the location of the Config file that was specified by the user when configuring the project or which CMake computed and stored in QtModule_DIR cache var. Mention that a package is not found in case if the main target exposed by that package is not found. If the target is not found, mention that it might be due to QT_NO_CREATE_TARGETS being set to TRUE (when it is set to true). If it is set to true, the assumption is that the target must have been defined by something else before the find_package call (either an earlier find_package call without QT_NO_CREATE_TARGETS set to TRUE or maybe it's the use case of Qt being built together with its examples or it's a super build). Unset _Qt_NOTFOUND_MESSAGE to ensure that the Qt6 not found error message is not spilled into any subsequent find_package(Qt6) calls, causing a cascade of unwarranted warnings / errors. Make sure to unset it only if components were specified, so the message is not shown or unset in any of the recursive find_package(Qt6) calls which is a dependency for regular Qt module packages. This works fine, because find_package(Qt6) calls with components are only done in project code and not done by the transitive dependency code (which looks for Qt6Foo packages directly). Remove some dead code. Pick-to: 6.2 Task-number: QTBUG-95532 Change-Id: Ie93d18e25e33aa0fe9e9da9a60e3d3e4cd6adb58 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'cmake/QtConfig.cmake.in')
-rw-r--r--cmake/QtConfig.cmake.in47
1 files changed, 35 insertions, 12 deletions
diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in
index 7f5698a34c..c44a17995e 100644
--- a/cmake/QtConfig.cmake.in
+++ b/cmake/QtConfig.cmake.in
@@ -33,12 +33,6 @@ if(NOT "${QT_HOST_PATH}" STREQUAL "")
NO_DEFAULT_PATH)
endif()
-# if (NOT @INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS)
-# set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "The Qt package requires at least one component")
-# set(@INSTALL_CMAKE_NAMESPACE@_FOUND False)
-# return()
-# endif()
-
get_filename_component(_qt_import_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_qt_import_prefix "${_qt_import_prefix}" REALPATH)
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}")
@@ -112,21 +106,50 @@ foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS})
${__qt_use_no_default_path_for_qt_packages}
)
if (NOT @INSTALL_CMAKE_NAMESPACE@${module}_FOUND)
- string(CONFIGURE ${_qt5_module_location_template} _expected_module_location @ONLY)
+ set(_qt_expected_component_config_path
+ "${_qt_cmake_dir}/@INSTALL_CMAKE_NAMESPACE@${module}/@INSTALL_CMAKE_NAMESPACE@${module}Config.cmake")
+ get_filename_component(
+ _qt_expected_component_dir_path "${_qt_expected_component_config_path}" DIRECTORY)
+
+ set(_qt_component_not_found_msg
+ "\nExpected Config file at \"${_qt_expected_component_config_path}\"")
+
+ if(EXISTS "${_qt_expected_component_config_path}")
+ string(APPEND _qt_component_not_found_msg " exists \n")
+ else()
+ string(APPEND _qt_component_not_found_msg " does NOT exist\n")
+ endif()
+
+ set(_qt_candidate_component_dir_path "${@INSTALL_CMAKE_NAMESPACE@${module}_DIR}")
+
+ if(_qt_candidate_component_dir_path AND
+ NOT _qt_expected_component_dir_path STREQUAL _qt_candidate_component_dir_path)
+ string(APPEND _qt_component_not_found_msg
+ "\n@INSTALL_CMAKE_NAMESPACE@${module}_DIR was computed by CMake or specified on the "
+ "command line by the user: \"${_qt_candidate_component_dir_path}\" "
+ "\nThe expected and computed paths are different, which might be the reason for "
+ "the package not to be found.")
+ endif()
- if (@INSTALL_CMAKE_NAMESPACE@_FIND_REQUIRED_${module})
- set(_Qt_NOTFOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}Failed to find Qt component \"${module}\" config file at \"${_expected_module_location}\"\n")
+ if(@INSTALL_CMAKE_NAMESPACE@_FIND_REQUIRED_${module})
+ set(_Qt_NOTFOUND_MESSAGE
+ "${_Qt_NOTFOUND_MESSAGE}Failed to find Qt component \"${module}\". ${_qt_component_not_found_msg}")
elseif(NOT @INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
- message(WARNING "Failed to find Qt component \"${module}\" config file at \"${_expected_module_location}\"")
+ message(WARNING
+ "Failed to find Qt component \"${module}\". ${_qt_component_not_found_msg}")
endif()
- unset(_expected_module_location)
+ unset(_qt_expected_component_config_path)
+ unset(_qt_expected_component_dir_path)
+ unset(_qt_candidate_component_dir_path)
+ unset(_qt_component_not_found_msg)
endif()
endforeach()
-if (_Qt_NOTFOUND_MESSAGE)
+if(@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS AND _Qt_NOTFOUND_MESSAGE)
set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}")
set(@INSTALL_CMAKE_NAMESPACE@_FOUND False)
+ unset(_Qt_NOTFOUND_MESSAGE)
endif()
__qt_internal_defer_promote_targets_in_dir_scope_to_global()