Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Passing Lists on Command Line

I need to run swig as part of my cmake build system. I want the user to be able to specify a list of languages to pass to swig and specify them on the command line.

$ cmake -DSWIG_LANGUAGES=java,scala <path to cmake_source_dir>

Is there a built in way for cmake to handle this?

like image 930
Matthew Hoggan Avatar asked Oct 20 '15 17:10

Matthew Hoggan


People also ask

How do you pass command line arguments in cmake?

If you create the cache variable in the CMakeLists. txt file and then pass the argument via calling cmake, won't the CMakeList. txt file keep overwriting the argument value? No, the cache is populated on the first run with either the default value, or the value supplied on the command line if it is provided.

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.

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

You can use semicolons to separate list items. Since semicolon is a special character in unix-like shells, you need to escape it or use quotes. Any of the following commands work:

cmake -DSWIG_LANGUAGES=java\;scala ...
cmake "-DSWIG_LANGUAGES=java;scala" ...
cmake '-DSWIG_LANGUAGES=java;scala' ...
like image 73
tamas.kenez Avatar answered Oct 29 '22 16:10

tamas.kenez