Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cmake list-get command

Tags:

cmake

Why doesn't the following command work?

SET(MY_LIST a b c d) LIST(GET ${MY_LIST} 0 HEAD) MESSAGE("HEAD = ${HEAD}") 

I want it to assign a to HEAD but instead I'm getting NOTFOUND.

I have already tried surrounding ${MY_LIST} with double quotes and changing the index to 1 instead of 0 (don't know why someone would do that but it didn't hurt to try).

like image 760
freitass Avatar asked Aug 18 '11 17:08

freitass


People also ask

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.

What is CMakeLists txt?

CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.

How do I use CMake variables?

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


1 Answers

The list commands require an unsubstituted variable as the second argument, i.e.:

set (MY_LIST a b c d) list (GET MY_LIST 0 HEAD) message ("HEAD = ${HEAD}")  
like image 116
sakra Avatar answered Sep 18 '22 10:09

sakra