Cmake datatypes

From wikinotes

Intro

general info

All variables in cmake are strings, but tokens can be used within strings so that lists are supported (ex: varA;varB;varC ). Variables are case-sensitive

Both _ and - can be used in variable names

variable scope

  • variables defined in a function are available to that function, and nested-function calls, then are discarded.
  • any other variables are defined for the entire directory, and any subdirectories.

setting, unsetting, and usage

SET( x 3 )                                                  # saves '3' to the variable 'x'
SET( x "some text" )                                        # saves 'some text' to variable 'x'
                                   
MESSAGE( "value of ${x}" )                                  # use variable 'x' in string
UNSET( x )                                                  # delete variable 'x'
 
SET( var = "x" )                                            # set a variable-variable
SET( ${var} "some text" )

Datatypes

string

SET( var "abc" )

list

SET( x 1 2 3 4 5 )                                          # sets variable 'x' to '1;2;3;4;5'
COUNTARGS( x )                                              # displays '5' for 'x == 1;2;3;4;5'


boolean

# =====
# False
# =====
 
"FALSE"
"OFF"
"NO"
"<anything>-NOTFOUND"
 
 
# ====
# True
# ====
 
#.. any other set variable..

environment variables

MESSAGE( "Using Home Directory: $ENV{HOME}" )             # environment variables are in the namespace $ENV{<variable-name>}