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>
This commit is contained in:
parent
9b860ece42
commit
825cb50c27
@ -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)
|
||||
|
||||
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")
|
||||
elseif(NOT @INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
|
||||
message(WARNING "Failed to find Qt component \"${module}\" config file at \"${_expected_module_location}\"")
|
||||
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()
|
||||
|
||||
unset(_expected_module_location)
|
||||
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}\". ${_qt_component_not_found_msg}")
|
||||
elseif(NOT @INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
|
||||
message(WARNING
|
||||
"Failed to find Qt component \"${module}\". ${_qt_component_not_found_msg}")
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
@ -115,5 +115,17 @@ if (TARGET @QT_CMAKE_EXPORT_NAMESPACE@::@target@)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@BuildInternals.cmake")
|
||||
endif()
|
||||
else()
|
||||
set("@INSTALL_CMAKE_NAMESPACE@@target@_FOUND" FALSE)
|
||||
|
||||
set(@INSTALL_CMAKE_NAMESPACE@@target@_FOUND FALSE)
|
||||
if(NOT DEFINED @INSTALL_CMAKE_NAMESPACE@@target@_NOT_FOUND_MESSAGE)
|
||||
set(@INSTALL_CMAKE_NAMESPACE@@target@_NOT_FOUND_MESSAGE
|
||||
"Target \"@QT_CMAKE_EXPORT_NAMESPACE@::@target@\" was not found. ${@INSTALL_CMAKE_NAMESPACE@@target@_extra_not_found_message}")
|
||||
|
||||
if(QT_NO_CREATE_TARGETS)
|
||||
string(APPEND @INSTALL_CMAKE_NAMESPACE@@target@_NOT_FOUND_MESSAGE
|
||||
"Possibly due to QT_NO_CREATE_TARGETS being set to TRUE and thus "
|
||||
"${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake was not "
|
||||
"included to define the target.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user