MantisBT - CMake
View Issue Details
0015369CMakeCMakepublic2015-01-23 14:322015-06-01 08:38
Joakim Söderberg 
 
highmajoralways
closedwon't fix 
CMake 2.8.12.2 
 
0015369: file(STRINGS file VAR) fails to read entire file
I am experiencing some weird issues with file(STRINGS.

It fails to read my entire file. The file is 2529 lines long, but CMake only read 1885. Or well it reads the entire file, but then stops splitting it up into lines, instead the last list entry consists of all the lines between 1885-2529.
cmake -DFILE=thefile.gcov -P testscript.cmake


testscript:

file(STRINGS ${FILE} LIST)
list(LENGTH LIST LIST_COUNT)
message("${LIST_COUNT}")
I have not been able to test with a later CMake yet. But I hope there is some workaround for this for older versions as well.
No tags attached.
? thefile.gcov (93,126) 2015-01-23 14:32
https://public.kitware.com/Bug/file/5360/thefile.gcov
Issue History
2015-01-23 14:32Joakim SöderbergNew Issue
2015-01-23 14:32Joakim SöderbergFile Added: thefile.gcov
2015-01-23 14:37Brad KingNote Added: 0037793
2015-01-23 14:37Brad KingStatusnew => resolved
2015-01-23 14:37Brad KingResolutionopen => won't fix
2015-01-23 14:51Joakim SöderbergNote Added: 0037794
2015-01-23 14:58Brad KingNote Added: 0037795
2015-01-23 15:21Joakim SöderbergNote Added: 0037799
2015-06-01 08:38Robert MaynardNote Added: 0038856
2015-06-01 08:38Robert MaynardStatusresolved => closed

Notes
(0037793)
Brad King   
2015-01-23 14:37   
The file contains lines with unmatched square brackets. As documented here:

 http://www.cmake.org/cmake/help/v3.1/manual/cmake-language.7.html#lists [^]

unmatched square brackets cause lists to not be split.

CMake is not a general-purpose language suitable for data processing.
(0037794)
Joakim Söderberg   
2015-01-23 14:51   
Ok, so I'm just screwed then? No way around this, except adding matching brackets (which I have confirmed works) as comments in the file.

So I'm totally in the wrong even trying something like this?:
https://github.com/JoakimSoderberg/coveralls-cmake/blob/master/cmake/CoverallsGenerateGcov.cmake [^]

Actually this is not the first time I've run into problems with how lists works. But I guess code like the above is better to write in an external C program that is compiled and passed the input.
(0037795)
Brad King   
2015-01-23 14:58   
Re 0015369:0037794: I don't think implementing coverage file parsing in the CMake language is a good idea.

CMake language lists were designed to do lists of source files. Their restrictions with respect to ";", "[", and "]" were necessary for compatibility with existing behavior at the time they were introduced. It was never designed to be general purpose.

At best you could hack around the limitation by using string(REPLACE) to substitute placeholders for "[" and "]" before doing anything else with the result of file(STRINGS).
(0037799)
Joakim Söderberg   
2015-01-23 15:21   
Thanks that fixed it!
(0038856)
Robert Maynard   
2015-06-01 08:38   
Closing resolved issues that have not been updated in more than 4 months.