[CMake] Macro's all and string expansion
Tristan Carel
tristan.carel at gmail.com
Sat Sep 1 06:18:19 EDT 2007
Hi,
While passing a regular expression to macro as parameter, I
experimented strange behaviour:
$ cat bar.cmake
MACRO(FOO regexp)
IF("foo.bar" MATCHES "${regexp}")
MESSAGE(STATUS "FOO: match")
ENDIF("foo.bar" MATCHES "${regexp}")
ENDMACRO(FOO)
IF("foo.bar" MATCHES "foo\\.bar")
MESSAGE(STATUS "REFERENCE: OK")
ENDIF("foo.bar" MATCHES "foo\\.bar")
FOO("foo\\.bar")
$
$ /usr/bin/cmake --version
cmake version 2.4-patch 6
$
$ cmake -P bar.cmake
-- REFERENCE: OK
CMake Error: Invalid escape sequence \.
CMake Error: Syntax error in cmake code at
/tmp/bar.cmake:11:
syntax error, unexpected cal_ERROR, expecting $end (5), when parsing
string "foo\.bar"
I must increase the escape level to make the macro's call working:
FOO("foo\\\\.bar")
To figure out what is going on, I tried another test: a macro which
call another one, passing its input argument.
$ cat foobar.cmake
MACRO(BAR regexp)
IF("foo.bar" MATCHES ${regexp})
MESSAGE(STATUS "BAR: match")
ENDIF("foo.bar" MATCHES ${regexp})
ENDMACRO(BAR)
MACRO(FOO regexp)
BAR(${regexp})
ENDMACRO(FOO)
IF("foo.bar" MATCHES "foo\\.bar")
MESSAGE(STATUS "REFERENCE: OK")
ENDIF("foo.bar" MATCHES "foo\\.bar")
FOO("foo\\\\\\\\.bar")
$
As you can see, I have to escaped one more time to make it works,
otherwise I have the same error as above. So I guess escaped
characters are expanded at each macro's call but I don't understand
why it should be the case.
I tried to surround ${regexp} with quotes, without success.
The behaviour is exactly the same with CMake cvs built this morning.
I want to be able to pass non-tricky regular expressions to macros,
firstly because escaping stuff is very annoying and secondly because a
user shouldn't need to know macro's internal mechanisms to use it.
If it is not a bug, can something clarify this to me?
Thx by advance.
--
Tristan Carel
Music with dinner is an insult both to the cook and the violinist.
http://www.tristancarel.com
More information about the CMake
mailing list