They are not persisted across cmake runs.
Cmake set variable.
In fact defining your own custom variables makes your cmakelists txt file.
To see the available variables for an environment open the corresponding command prompt and type set.
Set a normal cache or environment variable to a given value.
If you want to set a variable from the command line cmake offers a variable cache.
Some variables are already here like cmake build type.
Normal variables are meant for the internal use of the script just like variables in most programming languages.
Cmake variables are defined at file scope.
In addition you can also define any variables you need.
So it could get important to set some variables before those commands are used.
It s a lot like the include directive in c c.
Example set my variable the value is a string by default a local variable is only defined in the current directory and any subdirectories added through the add subdirectory command.
Cmake uses many variables that are officially documented.
The only way to set a compiler and flags to do cross compilation reliably with cmake is with a toolchain file as done in the tutorial you have found.
Normal variables and cache variables.
Set var true set var main cpp set var1 var2 but cmake does also know global cached variables persisted in cmakecache txt and if normal and cached variables of the same name exist in the current scope normal variables do hide the cached ones.
When we faced the same issue you have a toolkit which produces a script so set the compile environment we changed the toolkit in a way that it produces a toolchain file along with the script.
In which case the environment variable will be set.
Mostly you will use normal variables.
Variable types in cmake in cmake there are two types of variables.
These have default values or values that are based on your project environment.
Signatures of this command that specify a value.
Placeholder expect zero or more arguments.
To extend the scope of a variable there are two possibilities.
The include command executes another cmake script in the same scope as the calling script.
The syntax for declaring a variable and setting it if it is not already set is.
See the cmake language 7 variables documentation for the scopes and interaction of normal variables and cache entries.
Environment variables may differ from where cmake generated the make environment and when the the make files are put to use.
Set my cache variable value cache string description this will not replace an existing value.
Multiple arguments will be joined as a semicolon separated list to form the actual variable value to be set.
It s typically used to define a common set of functions or macros in the calling script.
You are allowed to change the value of these variables in your cmakelists txt.