[RFE]: emit SCRIPT CMAKE_ROLE warning if no cmake_minimum_required(VERSION)
In cmake -P my.cmake
SCRIPT CMAKE_ROLE, there is no default cmake-policy set. This leads to confusing behavior of scripts as most users/devs are no longer accustomed to CMake < 2.6 policies, yet this is the default in CMake Script role.
I propose CMake script role cmake -P
emits a warning like the warning CMake emits in PROJECT role if CMakeLists.txt does not have a cmake_minimum_required(VERSION)
. The behavior when CMAKE_ROLE is SCRIPT and don't have cmake_minimum_required(VERSION)
set is just as confusing as in PROJECT role where there has long been such a warning.
Rather than having users set discrete cmake_policy()
I would like to encourage the better practice of using cmake_minimum_required(VERSION)
in SCRIPT role as for PROJECT role.
For example, cmake -P regex.cmake
fails if regex.cmake is:
file(STRINGS my.txt match REGEX "([\.A-Za-z0-9_]+)")
CMake Warning (dev) at regex.cmake:5 (file):
Syntax error in cmake code at
/tmp/regex.cmake:5
when parsing string
([\.A-Za-z0-9_]+)
Invalid escape sequence \.
Policy CMP0010 is not set: Bad variable reference syntax is an error. Run
"cmake --help-policy CMP0010" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
I would rather have the CMake SCRIPT role emit warning as in PROJECT role:
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.25)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project.
This warning is for project developers. Use -Wno-dev to suppress it.