The FindGTest.cmake module does not respect the version parameter?

bash-5.3$ cmake -S . -B build --log-level=DEBUG --fresh
-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GTest: /usr/local/lib/libgtest.a (Required is exact version "1.17.1")
-- GTest_FOUND=TRUE
-- GTest_VERSION=
-- Configuring done (2.0s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/beman-project/exemplar/src/build
bash-5.3$ 

My project file is:

cmake_minimum_required(VERSION 3.30...4.2)

# XXX NO! set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES provide_dependency.cmake)

project(test)

# TODO: find_package(GTest CONFIG 1.17.1 EXACT REQUIRED)
# CMake Error at CMakeLists.txt:7 (find_package):
#   Could not find a configuration file for package "GTest" that exactly
#   matches requested version "1.17.1".
#
#   The following configuration files were considered but not accepted:
#
#     /usr/local/lib/cmake/GTest/GTestConfig.cmake, version: 1.17.0
#       The version found is not compatible with the version requested.


find_package(GTest 1.17.1 EXACT REQUIRED)
# FIXME: Found GTest: /usr/local/lib/libgtest.a (Required is exact version "1.17.1")

message(STATUS "GTest_FOUND=${GTest_FOUND}")
message(STATUS "GTest_VERSION=${GTest_VERSION}")

and for the dependency_provider I have no idea how to check the find_package(ARGN)?

cmake_minimum_required(VERSION 3.24)

# Because we declare this very early, it will take precedence over any
# details the project might declare later for the same thing
include(FetchContent)
FetchContent_Declare(
    googletest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG v1.17.0
)

# Both FIND_PACKAGE and FETCHCONTENT_MAKEAVAILABLE_SERIAL methods provide
# the package or dependency name as the first method-specific argument.
macro(mycomp_provide_dependency method dep_name)
    if("${dep_name}" MATCHES "^(GTest|googletest)$")
        message(VERBOSE "args=${ARGN}")

        # Save our current command arguments in case we are called recursively
        list(APPEND mycomp_provider_args ${method} ${dep_name})

        # This will forward to the built-in FetchContent implementation,
        # which detects a recursive call for the same thing and avoids calling
        # the provider again if dep_name is the same as the current call.
        FetchContent_MakeAvailable(googletest)

        # Restore our command arguments
        list(POP_BACK mycomp_provider_args dep_name method)

        # Tell the caller we fulfilled the request
        if("${method}" STREQUAL "FIND_PACKAGE")
            # We need to set this if we got here from a find_package() call
            # since we used a different method to fulfill the request.
            # This example assumes projects only use the gtest targets,
            # not any of the variables the FindGTest module may define.
            set(${dep_name}_FOUND TRUE)
            set(${dep_name}_VERSION "1.17.0")
        elseif(NOT "${dep_name}" STREQUAL "googletest")
            # We used the same method, but were given a different name to the
            # one we populated with. Tell the caller about the name it used.
            FetchContent_SetPopulated(
                ${dep_name}
                SOURCE_DIR "${googletest_SOURCE_DIR}"
                BINARY_DIR "${googletest_BINARY_DIR}"
            )
        endif()
    endif()
endmacro()

cmake_language(
    SET_DEPENDENCY_PROVIDER mycomp_provide_dependency
    SUPPORTED_METHODS FIND_PACKAGE FETCHCONTENT_MAKEAVAILABLE_SERIAL
)

@vito.gamberini How should / can it work?

Dependency providers are free to (and often will) ignore a version specification, or indeed any of the information you provide in a call to find_package() or FetchContent_Declare(). Their only job is to provide the dependency, as they see fit to define it. This is critical for many package managers, who expect the dependency details to be defined separately and will ignore any details provided through CMake.

If you, as the implementor of the dependency provider, want to honour details like the version, then it’s up to you how to do that according to what you want your provider logic to be and what you want it to achieve.

But than this seems simpler and better to me:

cmake_minimum_required(VERSION 3.30...4.2)

project(test)

include(FetchContent)
FetchContent_Declare(
    GTest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG v1.17.0
    FIND_PACKAGE_ARGS 1.17.0 EXACT
)
FetchContent_MakeAvailable(GTest)
message(STATUS "GTest_FOUND=${GTest_FOUND}")
message(STATUS "GTest_VERSION=${GTest_VERSION}")

# later this will fail:
# XXX find_package(GTest CONFIG 1.17.1 EXACT REQUIRED)

# FIXME: but this not?
find_package(GTest 1.17.1 EXACT REQUIRED)
message(DEBUG "GTest_FOUND=${GTest_FOUND}")
message(DEBUG "GTest_VERSION=${GTest_VERSION}")

But the FindGTest.cmake module seems buggy to me!