cmakecmake-language

What is the "VERSION" in "cmake_minimum_required(VERSION 3.10)”


I know the meaning of below CMake statement:

cmake_minimum_required(VERSION 3.10)

I am just wondering what the VERSION part is syntactically?

Is it a unquoted argument? If it is an argument, there must be some other argument choices.

But according to here, it seems VERSION is the only choice for the cmake_minimum_required() command.

If so, why do we even need to specify this argument explicitly??

And according to here, this command sets the variable CMAKE_MINIMUM_REQUIRED_VERSION. Is there some kind of string concatenation here? So I can use set_minimum_required(XXX <some_value>) to sent an arbitrary variable with the name CMAKE_MINIMUM_REQUIRED_XXX to <some_value>?

ADD 1

I just tried with below statement in the CMakeLists.txt:

cmake_minimum_required(XXX 123)

And cmake complains that:

CMake Error at CMakeLists.txt:2 (cmake_minimum_required):
  cmake_minimum_required called with unknown argument "XXX".

So it seems to be an argument.

But according to here for the project() command, a similar VERSION string is designated as an option. Seems a bit inconsistent.

ADD 2

I just tried with below statement in the CMakeLists.txt:

cmake_minimum_required(3.10)

And cmake complains that:

CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  cmake_minimum_required called with unknown argument "3.10".

So it seems CMake relies on the VERSION part to properly interpret the "3.10" argument. So I guess the VERSION is also an option here.

And since there's another possible option FATAL_ERROR, it is necessary to have a VERSION option.

So to summarize my current understanding:

The essential paradigm of CMake language is:

CMake commands just manipulate variables based on arguments and options.

Some variables are required to be manipulated and some are optional.

ADD 3

From here, for the VERSION in cmake_minimum_required():

The VERSION is a special keyword for this function. And the value of the version follows the keyword.

So here it is called keyword instead of option ...

Add 4

Some feelings about CMake...


Solution

  • I think the input to a CMake command can be classified as 3 types:

    1. keyword argument (also called option)

    2. positional argument

    3. variable arguments (like ... in C)

    For 1, Like the VERSION in cmake_minimum_required, whose value follows it immediately. It is called keyword or option.

    For 2, Such argument has a formal name and is referenced through that name within the command body.

    For 3, the argument can be referenced with ARGV, ARGN, ARGVC.

    I also see marker argument somewhere. But I forget where. Horrible syntax...

    ADD 1

    OK I found the marker argument. It's in the book Mastering CMake by the CMake team:

    enter image description here enter image description here

    ...while the CMake official document says it's an option:

    Search the paths specified by the PATHS option or in the short-hand version of the command. These are typically hard-coded guesses.

    What a chaotic wording...