[CMake] if(string MATCHES regex) question

Marcel Loose loose at astron.nl
Thu Jul 2 04:06:06 EDT 2009


Hi Eric,

On Wednesday 01 July 2009 18:28:57 Eric Noulard wrote:
> 2009/7/1 Marcel Loose <loose at astron.nl>:
> > Hi all,
> >
> > In a number of standard CMake modules I encountered the following line:
> >
> >  IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
> >
> > Can anyone explain the rationale of this conditional to me.
>
> The rational no but ....
>
> > To my cluttered mind this seems to be an "always-true" condition.
>
> this is definitely not always true.
> The variable your are testing may contain "un-evaluated" var
> or some special regex character( *, ?, ...)
>
> See attached example, you may test it with
> $ cmake -P matches.cmake
> MATCHES -- MYVAR = A good var
> Look that one = double-dollar = blah / single-dollar = MYVAR2
> NO MATCHES ** MYVAR = MYVAR2
> $
>
> However I have no such usage currently :-)

If I understand your script correctly, then the trick of this construct is to 
check whether the variable MYVAR is defined in terms of one (or more) other 
variables. Correct?

If so, I still don't quite get the usage pattern in, e.g., 
CheckIncludeFile.cmake. What are they trying to check?

Best regards,
Marcel Loose.


More information about the CMake mailing list