[CMake] bug?
Brad King
brad.king at kitware.com
Tue Mar 8 15:20:31 EST 2005
John Biddiscombe wrote:
> If you save the following lines as a text file
> ----begin text file---
> This is text
> with a line with a;
> at the end
> ---end text ----
>
> and then do this
>
> FILE(READ ${FILENAME} CONTENTS)
>
> FOREACH(line ${CONTENTS})
> IF( "${line}" MATCHES ";" )
> MESSAGE("Got one")
> ENDIF( "${line}" MATCHES ";" )
> ENDFOREACH(line)
>
> you don't get a match for the line with the ; at the end. Is this
> intentional. I've noticed that cmake treats ; chars as eol delimiters in
> expressions. Its quite hard to do anything with files with ; in when you
> need them.
Using ${CONTENTS} as the argument to any function is the syntax for
evaluating the variable and splitting the results into multiple
arguments. The splitting is always done at ; characters. This is just
the definition of the CMake syntax.
The FOREACH command is just looping over the arguments it receives. In
this case it will receive two arguments...one with the text before the ;
and one with the text after it. The loop variable name "line" is a
misnomer. CMake is not a text processing language like perl and has
only minimal support for such operations.
You have two choices:
1.) Write a C program to process the file and setup the proper custom
commands to build the C program and process the file at make time.
2.) Write more careful CMake code to use STRING(REGEX ...) to split up
the file contents and escape the ;'s properly before using the FOREACH.
-Brad
More information about the CMake
mailing list