AKKO
AKKO

Reputation: 1081

Understanding CMake variable behavior in SET() and MESSAGE() commands

I am trying to understand CMake and have worked with some statements requiring me to comprehend the behavior of SET() and MESSAGE(). I worked out the following in Terminal and the results leave me puzzled:

➜  ~  cmake -P /dev/stdin
set(STATUS 5)
message(${STATUS} STATUS)
5STATUS

➜  ~  cmake -P /dev/stdin
set(STATUS 5)
message(STATUS ${STATUS})
-- 5

My questions are:

  1. I've realized that STATUS itself is like a variable because it by default seems to print a line of -- before any string that comes after it (try executing this statement MESSSAGE( STATUS "Setting flags for GNU GCC") and you will see what I mean). STATUS just will not work if I had put it in lower case status inside the MESSAGE() command. Similarly, we have the FATAL_ERROR variable which gives us a statement like CMake Error at /foo/bar.c:2 (MESSAGE). It seems like STATUS and FATAL_ERROR are variables with pre-determined values. However, I have never seen any documentation for them, yet I have seen that other variables like CMAKE_BUILD_TYPE and CMAKE_CONFIGURATION_TYPES are documented, with their definitions being explained in books like Mastering CMake. Does anyone know where I can get a comprehensive listing and definition of all such variables like STATUS and FATAL_ERROR?

  2. I do not understand the behavior that I saw on Terminal. Why is it that in the first case, having STATUS after ${STATUS} gave me the word STATUS itself, while in the second case, with the order being reversed, STATUS before ${STATUS} gave its original value of --?

  3. For commands like MESSAGE() and SET() I've read from http://www.cmake.org/Wiki/CMake/Language_Syntax that they are case insensitive. However, it this also the same for variables?

Thank you very much everyone and I will appreciate any feedback or comments to correct my misconceptions.

Upvotes: 0

Views: 795

Answers (2)

user4408289
user4408289

Reputation: 31

See cmake --help-command message or the documentation at cmake.org

The STATUS and FATAL_ERROR are not variables but function arguments. And yes, they are case sensitive. And yes, it's all documented. And yes, argument order matters.

Upvotes: 3

Joel
Joel

Reputation: 2035

message command. Also note the following:
1.- Using like this:

set(STATUS 5)
message(${STATUS} STATUS)

Is like passing none (see link to documentation) as first parameter to message. Meaning that you'll get a clean 5 status on screen.

2.-Using like this:

set(STATUS 5)
message(STATUS ${STATUS})

you are actually passing STATUS as the first parameter (again, see documentation about message) and as ${STATUS} is set to 5, you'll get only 5 on screen.

Upvotes: 4

Related Questions