Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does "CACHE STRING" in CMake CMakeLists file mean?

Tags:

cmake

I came to this sentences in a CMakeLists file, I googled it but couldn't find relevant resources on the word CACHE STRING.

set(CMAKE_BUILD_TYPE Debug CACHE STRING "set build type to debug") 

What does it mean? And imho, isn't this quite obscure to use?

like image 497
richard.g Avatar asked Mar 19 '16 02:03

richard.g


People also ask

What is cache in CMake?

The CMake cache may be thought of as a configuration file. The first time CMake is run on a project, it produces a CMakeCache. txt file in the top directory of the build tree. CMake uses this file to store a set of global cache variables, whose values persist across multiple runs within a project build tree.

Does CMake have a cache?

CMake cacheCMake caches variables and settings in the CMakeCache. txt file. When you load a project for the first time, this file is generated in the build directory (cmake-build-debug or cmake-build-release by default) according to the contents of CMakeLists. txt.

How do I set CMake cache variables?

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 is a cache variable?

7.4. 1 Cache Variable NamesAn abbreviation for your package or organization; the same prefix you begin local Autoconf macros with, except lowercase by convention. For cache values used by the distributed Autoconf macros, this value is ' ac '.


Video Answer


1 Answers

Read https://cmake.org/cmake/help/v3.0/command/set.html

Within CMake sets <variable> to the value <value>. <value> is expanded before <variable> is set to it. Normally, set will set a regular CMake variable. If CACHE is present, then the <variable> is put in the cache instead, unless it is already in the cache. See section ‘Variable types in CMake’ below for details of regular and cache variables and their interactions. If CACHE is used, <type> and <docstring> are required. <type> is used by the CMake GUI to choose a widget with which the user sets a value.

STRING is the variable type; this really only affects the config tools when they display the edit widgets for a variable.

You would normally use this if you wanted to override a setting, with FORCE; otherwise you probably wouldn't.

It's not particularly obscure.

NB. The main difference between a CACHE and normal variable is that CACHE ones turn up in the cmake config tool as setting you can set (eg. cmake-gui, ccmake).

like image 190
Doug Avatar answered Oct 11 '22 06:10

Doug