[Cmake] Capture regular expressions

Brad King brad.king at kitware.com
Mon, 03 May 2004 10:11:45 -0400


Filipe Sousa wrote:
> On Monday 03 May 2004 14:19, Brad King wrote:
> 
>>Filipe Sousa wrote:
>>
>>>I wrote my own FindQt.cmake so that I could find the right qt lib on
>>>Windows. I need to extract the version from global.h. I managed that
>>>using two STRING command, but I would like to capture version around
>>>parentheses with regular expressions using only one STRING command. Is
>>>this possible with cmake?
>>
>>What do you mean by "version around parentheses"?  Code like this is
>>supported:
>>
>>STRING(REGEX REPLACE "#define[\\t\\ ]+QT_VERSION_STR[\\t\\
>>]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\"" "\\1" qt_version "${VERSION_STR}")
>>
>>Note the "\\1" in the replace expression.  The two backslashes make it
>>through argument processing as a single backslash, and then the "\1" is
>>replaced by the part of the string matched inside the parentheses.
> 
> 
> That's exactly what i've been looking for. I didn't known that i could do that 
> with STRING(REGEX REPLACE using "\\1". Is this feature well documented?

Not in 1.8.3.  I've just added the documentation to the STRING command 
for the current CVS version.  It will be included in the 2.0 release.

-Brad