CMake: Pass along the version in FindWrap cmake scripts
The QtFindWrapHelper include used in FindWrap scripts can choose to call find_package() on one of two packages. The packages might set a VERSION variable. We should set the same version for the FindWrap package as well. There are two sources where the version will be queried from. First from the underlying ${package_name}_VERSION variable. And if that is empty, from a property that is set by qt_find_package() The former might be empty because find_package might be called from a function instead of a macro, which is the case for any find_package call in configure.cmake files that get loaded by the qt_feature_evaluate_features function. Thus we need the indirection via the property that qt_find_package will set. Change-Id: I57fd818cb9dedf5e27a6d805e3d817d8d18be36d Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
8fe9cabe16
commit
28c8f8e92a
@ -190,6 +190,15 @@ macro(qt_find_package)
|
||||
PROPERTIES INTERFACE_QT_PACKAGE_VERSION ${ARGV1})
|
||||
endif()
|
||||
|
||||
# Save the retrieved package version.
|
||||
set(_qt_find_package_found_version "")
|
||||
if(${ARGV0}_VERSION)
|
||||
set(_qt_find_package_found_version "${${ARGV0}_VERSION}")
|
||||
set_target_properties(${qt_find_package_target_name}
|
||||
PROPERTIES
|
||||
_qt_package_found_version "${_qt_find_package_found_version}")
|
||||
endif()
|
||||
|
||||
if(arg_COMPONENTS)
|
||||
string(REPLACE ";" " " components_as_string "${arg_COMPONENTS}")
|
||||
set_property(TARGET ${qt_find_package_target_name}
|
||||
|
@ -80,10 +80,39 @@ macro(qt_find_package_system_or_bundled _unique_prefix)
|
||||
INTERFACE_QT_3RD_PARTY_PACKAGE_TYPE
|
||||
"${${_unique_prefix}_qt_package_type}")
|
||||
|
||||
|
||||
# This might not be set, because qt_find_package() is called from a configure.cmake file via
|
||||
# qt_feature_evaluate_features, which means the _VERSION var is confined to the function
|
||||
# scope.
|
||||
if(${${_unique_prefix}_qt_package_name_to_use}_VERSION)
|
||||
set(_qfwrap_${_unique_prefix}_package_version
|
||||
"${${${_unique_prefix}_qt_package_name_to_use}_VERSION}"
|
||||
)
|
||||
else()
|
||||
# We set this in qt_find_package, so try to retrieve it.
|
||||
get_target_property(_qfwrap_${_unique_prefix}_package_version_from_prop
|
||||
"${${_unique_prefix}_qt_package_target_to_use}" _qt_package_found_version)
|
||||
if(_qfwrap_${_unique_prefix}_package_version_from_prop)
|
||||
set(_qfwrap_${_unique_prefix}_package_version
|
||||
"${_qfwrap_${_unique_prefix}_package_version_from_prop}"
|
||||
)
|
||||
else()
|
||||
set(_qfwrap_${_unique_prefix}_package_version "")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(_qfwrap_${_unique_prefix}_package_version)
|
||||
set(_qfwrap_${_unique_prefix}_package_version_option
|
||||
VERSION_VAR "_qfwrap_${_unique_prefix}_package_version"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
Wrap${_qfwrap_${_unique_prefix}_FRIENDLY_PACKAGE_NAME}
|
||||
DEFAULT_MSG ${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_FOUND_VAR_NAME})
|
||||
REQUIRED_VARS ${_qfwrap_${_unique_prefix}_WRAP_PACKAGE_FOUND_VAR_NAME}
|
||||
${_qfwrap_${_unique_prefix}_package_version_option}
|
||||
)
|
||||
elseif(${_unique_prefix}_qt_package_type STREQUAL "bundled")
|
||||
message(FATAL_ERROR "Can't find ${${_unique_prefix}_qt_package_target_to_use}.")
|
||||
endif()
|
||||
|
Loading…
x
Reference in New Issue
Block a user