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?
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.
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.
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) .
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' ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With