问题描述:

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?

网友答案:

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

Within CMake sets to the value . is expanded before is set to it. Normally, set will set a regular CMake variable. If CACHE is present, then the 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, and are required. 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).

相关阅读:
Top