Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cache list in CMake

Tags:

caching

cmake

Is is possible to use list instead of variables in case of cache variables?

Here how I use cache variables

set(VAR "Value" CACHE INTERNAL "My Var")
set(VAR "${VAR} Value2" CACHE INTERNAL "My Var")
like image 897
user14416 Avatar asked May 25 '13 21:05

user14416


People also ask

Does Cmake have a cache?

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.

Where is the Cmake cache?

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

What is cache variable in Cmake?

Cache variables (unless set with INTERNAL) are mostly intended for configuration settings where the first CMake run determines a suitable default value, which the user can then override, by editing the cache with tools such as ccmake or cmake-gui.

How do I use a list in Cmake?

A list in cmake is a ; separated group of strings. To create a list the set command can be used. For example, set(var a b c d e) creates a list with a;b;c;d;e , and set(var "a b c d e") creates a string or a list with one item in it.


1 Answers

CMake lists are semi-colon separated, so you can set the list directly like this:

set(VAR Value;Value2 CACHE INTERNAL "My Var")

Having said that, even though lists are held as semi-colon separated items, they can be constructed using set with spaces between each item; e.g.

set(MyList Value Value2)  # list is  Value;Value2

So, if your values contain spaces, you need to wrap the list in quotation marks ":

set(VAR "Value 1;Value 2" CACHE INTERNAL "My Var")  # list is  Value 1;Value 2

The final point is that if you already have your list constructed, you don't need to wrap the list variable in quotation marks when caching it:

set(MyList "Value 1;Value 2")  # list is  Value 1;Value 2
set(VAR ${MyList} CACHE INTERNAL "My Var")  # no quotes required

Edit:

As I now understand it, you're asking if the list(APPEND...) command can be used to cache values directly.

The answer is no, but you were almost correct in your attempt. To get the desired effect, you'd need to use a semi-colon rather than space when caching the list:

set(VAR "${VAR};Value2" CACHE INTERNAL "My Var")
like image 147
Fraser Avatar answered Sep 28 '22 06:09

Fraser