Skip to content

Commit

Permalink
CMake: Pass along the version in FindWrap cmake scripts
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
alcroito committed May 29, 2024
1 parent 8fe9cab commit 28c8f8e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cmake/QtFindPackageHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
31 changes: 30 additions & 1 deletion cmake/QtFindWrapHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 28c8f8e

Please sign in to comment.