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

Andy Cedilnik andy . cedilnik at kitware . com
31 Jul 2003 08:13:11 -0400


Hi Ingmar,

FILE command will be available in CMake 1.8. 

The syntax for what you want will be:

FILE(GLOB var 
  ${CMAKE_CURRENT_SOURCE_DIR}/*.C
  ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/*.cxx
  ${CMAKE_CURRENT_SOURCE_DIR}/*.h
)

That said, several issues:

1. Adding *.cxx has a problem, since you have to rerun CMake every time
you add or remove source file. CMake will expand the list into the
actual list of files, which will be written in the Makefiles. *.cxx will
never be in the Makefile.

2. *.C is not a portable extension, since on Mac OSX and Windows, there
is no difference between .C and .c 

3. My personal oppinion is to use single extension, so I don't think you
should use .cpp, .cxx, and .C in a single project.

			Andy



On Thu, 2003-07-31 at 07:56, Bitter, Ingmar (NIH/CC/DRD) wrote:
> Hi,
> 
> I would love to use the FILE() command as well.
> (1) how do I specify that I want *.C and *.cpp and *.cxx and *.h
> (2) how do I make it work at all (i.e. my version 1.6.7 of cmake does not
> know the FILE() command :-(
> 
> -Ingmar 
> 
> -----Original Message-----
> From: Andy Cedilnik [mailto:andy . cedilnik at kitware . com] 
> Sent: Wednesday, July 23, 2003 11:42 AM
> To: Karr, David
> Cc: cmake at www . cmake . org
> Subject: RE: [Cmake] Set a variable to a list of filenames that match a
> pattern
> 
> Hi David,
> 
> Without specifying the directory, it will pick your current source
> directory. So,
> 
> FILE(GLOB var "${CMAKE_CURRENT_SOURCE_DIR}/*.cxx") 
> 
> and 
> 
> FILE(GLOB var "*.cxx") 
> 
> is the same.
> 
> I just do not think it is a good think to refer to things relatively.
> So, you better use full path to things.
> 
> Why would you need relative paths anyway?
> 
> 				Andy
> 
> On Wed, 2003-07-23 at 11:34, Karr, David wrote:
> > 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 
> > 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} 
> > instead of absolute paths; the result would be
> > 
> >   var = 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 = bar/c.cxx bar/d.cxx
> > 
> > This is useful to me because I want to do some things with 
> > the files foo/bar/*.cxx that I don't do with the files 
> > 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 
> > least in the way I tried it.
> 
> 
> _______________________________________________
> Cmake mailing list
> Cmake at www . cmake . org
> http://www . cmake . org/mailman/listinfo/cmake
> _______________________________________________
> Cmake mailing list
> Cmake at www . cmake . org
> http://www . cmake . org/mailman/listinfo/cmake