[CMake] Need help with GLOB expression

James Bigler jamesbigler at gmail.com
Mon Mar 30 00:46:40 EDT 2009


Why doesn't *.[hi]pp work?  It works for me with ls and with file(GLOB):

$ touch blah.hpp blah2.ipp
$ ls *.[hi]pp
blah.hpp	blah2.ipp

Also, if the glob expressions get translated into regular expressions,
is there any way we could get access to creating regular expressions?

find . -E -regex ""

That's essentially what's going on under the hood, right?

I filed a bug to make the documentation more clear
(http://public.kitware.com/Bug/view.php?id=8814).

I also looked into the bash man page.  Curly braces {} are filed under
Brace Expansion while the globbing characters (*,?,[]) were under
Pathname Expansion.  The only discerning difference between the two
expansions is whether or not the files have to exist (Brace Expansion
allows for arbitrary string creation where the file names need not
exist).

I suspect CMake could add support for curly braces, but it might be
easier to add support for regular expressions instead since the
machinery already uses regex under the hood.

James

On Sun, Mar 29, 2009 at 3:14 PM, Bill Hoffman <bill.hoffman at kitware.com> wrote:
> James Bigler wrote:
>>
>> Ah, yes.  I also was getting globbing expressions and regular
>> expressions mixed up.
>>
>>> From the docs (and experimentation), it looks like CMake only supports
>>
>> *, ?, and [], but not {} which would be required to do what we want:
>>
>> file(GLOB_RECURSE sources "*.{h,cpp}")
>>
>
> CMake uses a simple conversion from glob to regex, the code for that can be
> found here:
>
> http://public.kitware.com/cgi-bin/viewcvs.cgi/Source/kwsys/Glob.cxx?revision=1.16&root=CMake&view=markup
>
> It does a simple glob with *,?, and [], and that is about it.
>
> The best thing to do would be to try using a glob expression from a bash
> shell and ls.  For example, the first one you gave does not work .[hi]pp.
>  It was added to cmake to give simple globs like *.c *.cxx *.h, etc.
>
> -Bill
>


More information about the CMake mailing list