Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a safe way to edit a cache variable from the command line?

Tags:

cmake

As far as I know, CMake only comes with graphical cache editors. However, I need to edit some cache variables from a shell script. One way is to directly edit CMakeCache.txt but this is not considered safe. Or is it? If not, what is the general practice of editing a cache variable from the command line?

like image 672
Raul Laasner Avatar asked Mar 15 '18 14:03

Raul Laasner


People also ask

How do I change a variable in CMake?

Options and variables are defined on the CMake command line like this: $ cmake -DVARIABLE=value path/to/source You can set a variable after the initial `CMake` invocation to change its value. You can also undefine a variable: $ cmake -UVARIABLE path/to/source Variables are stored in the `CMake` cache.

How do I change CMake cache entry?

In a CMake script you can only change existing Cache entries if you use the set(... CACHE ... FORCE) syntax. This behavior is made use of e.g. by CMake itself, because it normally does not force Cache entries itself and therefore you can pre-define it with another value.

What is CMake cache variable?

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.

What is ${} in CMake?

In CMake, every variable is a string. You can substitute a variable inside a string literal by surrounding it with ${} . This is called a variable reference. Modify hello.txt as follows: message("Hello ${NAME}!") # Substitute a variable into the message.


1 Answers

You may call cmake:

  • with -D option(s) for set/modify cache variables, or
  • with -U option(s) for remove variables from the cache.

Running cmake will cause the project to be reconfigured, but this should be an ultimate purpose of any cache modification.

like image 92
Tsyvarev Avatar answered Nov 15 '22 07:11

Tsyvarev