Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the CMake cache?

Tags:

caching

cmake

What is CMake cache?

I'm reading the cmake manual and have occasionally come across the term cmake cache. For instance this paragraph:

-C <initial-cache> Pre-load a script to populate the cache.

When cmake is first run in an empty build tree, it creates a CMakeCache.txt file and populates it with customizable settings for the project. This option may be used to specify a file from which to load cache entries before the first pass through the project’s cmake listfiles. The loaded entries take priority over the project’s default values. The given file should be a CMake script containing SET commands that use the CACHE option, not a cache-format file.

What is this cache?
Are there different types of cache?
Or would a better question be: what is cache in general?

Also, what is the importance of cache?
And are there certain caveats when dealing with cache?
For example, does the cache reset when you turn restart your computer?

like image 548
John DeBord Avatar asked Nov 06 '18 00:11

John DeBord


People also ask

Does CMake have a cache?

CMake only has one type of cache. It is created and saved into CMakeCache. txt after the first configuring the build, and under normal use does not reset itself.

Can I delete CMake cache?

Deleting CMakeCache. txt should not affect any binaries, a full rebuild is not triggered. Otherwise you might have a local variable passed on before being cached which then leads to inconsistent runs. The regeneration of the project can trigger rebuilds if the configuration is different to the previous one.

How do I set CMake cache entry?

You can use the command line to set entries in the Cache with the syntax cmake -D var:type=value , just cmake -D var=value or with cmake -C CMakeInitialCache. cmake . You can unset entries in the Cache with unset(... CACHE) .

What does it mean to cache a variable?

When Analytica computes the result of a variable, it stores the computed value in memory. If that result is requested later, it simply returns the previously computed value without having to recompute it. This process is referred to as caching. The stored result is the cached result.


1 Answers

CMake cache refers to a set of persistent variables - persisted in a file named CMakeCache.txt in the build directory. These include things like user configurable options, which define some behavior of your project. For example, you may run cmake -D CMAKE_BUILD_TYPE=Release . in the build directory and find that variable saved in CMakeCache.txt.

CMake only has one type of cache. It is created and saved into CMakeCache.txt after the first configuring the build, and under normal use does not reset itself.

like image 95
Raul Laasner Avatar answered Oct 15 '22 01:10

Raul Laasner