Improve error message when wrong keywords are used in project()
Consider the error reported here: A user mis-types a keyword in their project()
command, e.g.
project(foo Version 1.0)
or perhaps:
project(foo LANG CXX)
They should get an error message making it (relatively) clear what they did wrong. Instead, what the user gets is:
CMake Error: Could not find cmake module file: CMakeDetermineVersionCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_Version_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
and so on. It is not at all obvious to the lay reader what the cause of these messages is. If you already know CMake was trying to interpret "Version" as a language name, then you go "oh, I see what's going on" - but this is unlikely to be the case for users who make this mistake in the first place.
These error message should be improved to cater to lay users.
A simple improvement would be, once any error is encountered w.r.t. language somelang
, to first emit:
CMake Error: Failed resolving variables for language 'somelang'
then print the actual errors. In this example, we would get:
CMake Error: Failed resolving variables for language 'Version'
and the user is much more likely to realize that the word 'Version' was interpreted as a language name.
See also #23769 .