Set

Use cache_set() to cache a variable. The function accepts the following parameters:

  • KEY: The variable to assign and cache.
  • VALUE: Value to assign and cache.
  • TTL: (optional), Time-To-Live of cache entry in seconds (see TTL for details).
  • TYPE: (optional), Cmake cache entry type, BOOL, STRING,…etc. Defaults to STRING if not specified.
  • DESCRIPTION: (optional), Description of cache entry.

Caution

Invoking the cache_set() function, is the equivalent to using CMake’s set(... CACHE FORCE).

Example

cache_set(
    KEY foo
    VALUE "bar"
)

message("${foo}") # bar

TTL

You can optionally specify a time-to-live (ttl) duration (in seconds), for the cache entry. Whenever the cached variable is queried (via has or get), the entry will automatically be removed, if it has expired.

cache_set(
    KEY foo
    VALUE "bar"
    TTL 5
)

# ... Elsewhere in your cmake scripts, 5 seconds later...

cache_get(KEY foo)

message("${foo}") # (empty string)