Cache variables(CMake)

Cache variables(CMake)

Cache variables #

Cache variables are not available in scripts. Set a cache variable:

set(<variable> <value> CACHE <type> <docstring> [FORCE])

Specifying CACHE as a set() argument means that we intend to change what was provided during the configuration stage, and it imposes a requirement to provide the variable <type> and <docstring> values. This is because these variables are configurable by the user and the GUI needs to know how to display it.

The following types are accepted: • BOOL: A Boolean on/off value. The GUI will show a checkbox. • FILEPATH: A path to a file on a disk. The GUI will open a file dialog. • PATH: A path to a directory on a disk. The GUI will open a directory dialog. • STRING: A line of text. The GUI offers a text field to be filled. It can be replaced by a drop-down control by calling set_property(CACHE <variable> STRINGS <values>). • INTERNAL: A line of text. The GUI skips internal entries. The internal entries may be used to store variables persistently across runs. Use of this type implicitly adds the FORCE keyword.

If the value doesn’t exist in cache or an optional FORCE argument is specified, the value will be persisted.

Set with command line #

cmake -D <var>[:<type>]=<value> <path-to-source>

From #