I try to recognize the version of flexc++ program with regular expressions in CMake.
The ouput of flexc++ version is something like:
prompt$ flexc++ --version
flexc++ V1.01.00
I try to extract the version with regular expressions. The name of the executable is in a variable (and this variable is the output of other command). The problem is the string “++” in the flexc++ name. This string create a conflict with the symbol “+” (one or more matchs). A mini test:
set(sample "flexc++ V1.01.00")
set(flexname "flexc++")
string(REGEX REPLACE "^${flexname} V([0-9.]+)$" "\\1"
output "${sample}")
message("${output}")
Throwing the next error:
RegularExpression::compile(): Nested *?+.
RegularExpression::compile(): Error in compile.
CMake Error at prueba.cmake:4 (string):
string sub-command REGEX, mode REPLACE failed to compile regex "^flexc++
V([0-9.]+)$".
If I erase the “++” string in sample and filename variables, it recognize perfect the version:
set(sample "flexc V1.01.00")
set(flexname "flexc")
string(REGEX REPLACE "^${flexname} V([0-9.]+)$" "\\1"
output "${sample}")
message("${output}")
Output:
1.01.00
That means the problem is the “++” string.
How can I avoid this problem? For example, are there in CMake any command like:
scape(flexname_scaped ${flexname})
performing
flexname_scaped <-- flexc\\+\\+
?
How can I solve this problem?
You can escape the "++" using
string(REPLACE...):