richard.g
richard.g

Reputation: 3765

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

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?

Upvotes: 18

Views: 19493

Answers (1)

Doug
Doug

Reputation: 35186

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).

Upvotes: 11

Related Questions