[Cmake] Set a variable to a list of filenames that match a pattern

Karr, David David . Karr at titan . com
Wed, 23 Jul 2003 11:34:07 -0400


> FILE(GLOB var "${CMAKE_CURRENT_SOURCE_DIR}/*.cxx")
>=20
> which will do what you want and will match:
>=20
> var =3D .../foo/a.cxx .../foo/b.cxx
>=20
> the second one is:
>=20
> FILE(GLOB_RECURSE var "${CMAKE_CURRENT_SOURCE_DIR}/*.cxx")
>=20
> which will match:
>=20
> var =3D .../foo/a.cxx .../foo/b.cxx .../foo/bar/c.cxx =
.../foo/bar/d.cxx

Cool!

It would be slightly better for my purposes if there were a
way to use this *without* inserting the .../foo/ in front of
every file name; that way I wouldn't have to run CMake every=20
time I made a temporary copy of my project under a new directory,
but only when the actual contents of the build changed.
Would it be possible to support a syntax like this:

  FILE(GLOB_RECURSE var "*.cxx")

which implies that the recursive search starts in
${CMAKE_CURRENT_SOURCE_DIR} but that the output names the files
using their paths relative to ${CMAKE_CURRENT_SOURCE_DIR}=20
instead of absolute paths; the result would be

  var =3D a.cxx b.cxx bar/c.cxx bar/d.cxx


Also, I wonder if I could write:

  FILE(GLOB var2 "bar/*.cxx")

with the result that

  var2 =3D bar/c.cxx bar/d.cxx

This is useful to me because I want to do some things with=20
the files foo/bar/*.cxx that I don't do with the files=20
foo/*.cxx, for example I want to put them in their own
source group (this apparently requires an extension to
to SOURCE_GROUP, but I discussed this in a different message).


I suspect the implementation of these features could be
lifted from my hack to cmSetCommand.cxx, with appropriate
changes to use the newer "glob" function.  For that matter
it was a very easy thing to add in the first place, at=20
least in the way I tried it.

-- David A. Karr