[Cmake] Letting SOURCE_GROUP get a list of file names from a variable

Karr, David David . Karr at titan . com
Wed, 23 Jul 2003 11:06:27 -0400


Supposing I have assigned a list of source files to a=20
variable in my CMakeLists.txt, I want to create a
source group that contains the files listed in that
variable.  That is, I want to do something like this:

  SET(var FILES alpha.cpp bravo.cpp)
  SOURCE_GROUP("Some Files" FILES alpha.cpp bravo.cpp)

but I do NOT want to have to write the same explicit
list of files in both places.

I managed to do this, but only by modifying the source
of CMake version 1.6.7.  What I did was to modify
cmSourceGroupCommand.cxx so that, instead of passing
each argument after "FILES" directly to the AddSource
function, it uses ExpandListArgument to put the individual
semicolon-separated components of the argument in a vector,
and it passes the elements of the vector to AddSource.
So the example above could be rewritten

  SET(var FILES alpha.cpp bravo.cpp)
  SOURCE_GROUP("Some Files" FILES ${var})

You could even write

  SOURCE_GROUP("Some Files" FILES ${var} ${another_var})

although this doesn't really add any power since one could=20
have concatenated the variables into a (temporary) third=20
variable and passed that to the SOURCE_GROUP command.

Is there any way to get similar functionality from the
existing CMake?

-- David A. Karr (karr at acm . org)