[CMake] How to assign data from subexpressions of regular expressions to CMake variables?

David Cole david.cole at kitware.com
Thu Jan 20 08:14:25 EST 2011


On Thu, Jan 20, 2011 at 8:06 AM, Michael Wild <themiwi at gmail.com> wrote:

> On 01/20/2011 02:01 PM, David Cole wrote:
> > On Thu, Jan 20, 2011 at 7:39 AM, Michael Wild <themiwi at gmail.com> wrote:
> >
> >> On 01/20/2011 12:10 PM, SF Markus Elfring wrote:
> >>>> Thanks for your help to make CMake better,
> >>>
> >>> Is the command variant "string(REGEX REPLACE ...)" completely
> documented?
> >>>
> >>> Can multiple variables be specified that will receive the data from the
> >>> evaluation of subexpressions in the passed regular expression?
> >>>
> >>> Regards,
> >>> Markus
> >>
> >> AFAIK no, but you can "misuse" if(<string|varname> MATCHES <pattern>)
> >> for this. It stores the groups in CMAKE_MATCH_<n> where <n> is {0..9}.
> >> Match 0 is always the whole match of <pattern> and match 1 is the
> >> contains the first group.
> >>
> >> Michael
> >> _______________________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Please keep messages on-topic and check the CMake FAQ at:
> >> http://www.cmake.org/Wiki/CMake_FAQ
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://www.cmake.org/mailman/listinfo/cmake
> >>
> >
> >
> > I think it's the case that the CMAKE_MATCH_* variables are set after
> *any*
> > regex matching operation, be it from an "if(... MATCHES ...)" or a
> > "string(REGEX" or "string(MATCH" command. Let us know if you find that
> not
> > to be true.
> >
> > From the bottom of (
> > http://cmake.org/cmake/help/cmake-2-8-docs.html#command:string ) :
> >
> >   () Saves a matched subexpression, which can be referenced
> >      in the REGEX REPLACE operation. Additionally it is saved
> >      by all regular expression-related commands, including
> >      e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).
> >
> >
> > HTH,
> > David
> >
>
> Ah, yes. I keep forgetting. Might I propose that the documentation about
> regular expressions be extracted into its own section and then be
> referenced from all commands that have a REGEX mode? Because,
> confusingly, the only documentation about regular expression is at the
> end of the string(REGEX REPLACE) command, but then uses if(... MATCHES
> ...) as an example. For the reader of the if( MATCHES ) documentation,
> this isn't very discoverable, it doesn't even refer him to the
> string(REGEX REPLACE) command.
>
>
> Michael
>


Me too. I had to go searching for "CMAKE_MATCH_" because I knew it was
stated somewhere. Much to my surprise, there was only a single "CMAKE_MATCH"
on our whole documentation page. It would make sense to document the
variables CMAKE_MATCH_0 and friends explicitly. And cross-referencing left,
right, north and south would also be good.

You can propose all you want. I keep getting distracted by the "real bugs"
on my plate...

:-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110120/abc0abec/attachment-0001.htm>


More information about the CMake mailing list