But then 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}")
The FindGTest.cmake module seems buggy to me because it doesn’t check the required version!