[CMake] managing lists with space separated elements

Piotr Dobrogost pd at opensource.dobrogost.pl
Sat Apr 11 15:09:54 EDT 2009


Bill Hoffman wrote:

> It was a mistake
> to have CMAKE_CXX_FLAGS and CMAKE_C_STANDARD_LIBRARIES be strings they
> should have been lists.

I'm glad you said this. It's something I've been trying to show in my posts.

> If you want to convert a string to a list you
> can do it like this:
> 
> set(list ${string})
> 
> That will make the space separated list string into a ; separated list.
>  If you want to keep string a string you need quotes:
> set(newstring "${string}").

Thanks. I'm aware of it.

> Converting a list back into a string requires a foreach loop or a regex.

Such a basic and very common operation in the world of build systems
shouldn't require boilerplate code.
It should be possible with one command.
I'm learning cmake and I'm sure it has many great features. However, the
fact there is no build-in command for doing such a basic and common
thing strikes me.

> The problem is there are some variables in CMake which are currently
> strings that should be lists.  I don't think the solution is to add list
> operations for strings.

This is a solution. Not a bad one because it doesn't change the meaning
of existing code.

The best solution is to make them lists as they should. Taking into
account you have tools for dealing with changes in cmake api
(cmake_minimum_required and cmake_policy) this should be possible.

Another solution is to implicitly convert every colon separated list
(the only right list in cmake currently :) to space separated list in
the last possible moment - when shell commands are constructed using
variables' values.


-- 
Piotr Dobrogost
*** curlpp.org - c++ wrapper for libcurl ***



More information about the CMake mailing list