Help with cmake maximum version

This is a dumb quick question I had with cmake_minimum_required. I was reading the help page and saw that it could specify a maximum version. I made a silly CMakeLists.txt:

cmake_minimum_required(VERSION 3.7...3.15)
project(test VERSION 1.0.0 LANGUAGES C)
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")

and then did:

❯ cmake --version
cmake version 3.19.5

CMake suite maintained and supported by Kitware (kitware.com/cmake).
❯ cmake ..
-- The C compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_C_COMPILER: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mathomp4/CmakeTest/build

I was surprised it worked as I have CMake 3.19. But reading that help more closely, does the maximum version only affect cmake_policy() and not CMake as a whole for a project?

Yes, you’ve figured it out. Minimum version is enforced but maximum is only for the polices. It’s like saying “I’ve tested this thing with the max declared version, so please set the polices according to that version”.