FindPackageHandleStandardArgs: warns about empty version found even if VERSION_VAR is unset
Let's take the following find module as an example:
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module(foo IMPORTED_TARGET GLOBAL foo)
if (foo_FOUND)
add_library(foo::foo ALIAS PkgConfig::foo)
else()
unset(foo_VERSION)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(foo
REQUIRED_VARS
foo_LINK_LIBRARIES
foo_FOUND
VERSION_VAR foo_VERSION
)
When the foo
pkg-config module is not present on my system, I would expect a message like this:
-- Checking for one of the modules 'foo'
CMake Error at /usr/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find foo (missing: foo_LINK_LIBRARIES foo_FOUND) (Required is
at least version "1.3")
But I instead receive a misleading message:
-- Checking for one of the modules 'foo'
CMake Error at /usr/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find foo: Found unsuitable version "", but required is at least
"1.3" (found )
Would it be possible to make find_package_handle_standard_args()
ignore empty/unset()
d VERSION_VAR
s? Or is this happening because FindPkgConfig's pkg_search_module()
and pkg_check_modules()
set the foo_VERSION
variable even when foo
isn't found?