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?
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.
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.
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) .
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 '.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With