This &quot;works&quot; with just cmake:<br><br>&nbsp; FILE(READ &quot;${file}&quot; contents)<br><br>&nbsp; # Convert file contents into a CMake list (where each element in the list<br>&nbsp; # is one line of the file)<br>&nbsp; #<br>&nbsp; STRING(REGEX REPLACE &quot;;&quot; &quot;\\\\;&quot; contents &quot;${contents}&quot;)
<br>&nbsp; STRING(REGEX REPLACE &quot;\n&quot; &quot;;&quot; contents &quot;${contents}&quot;)<br><br>The reason I say &quot;works&quot; (in quotes) is that there are two caveats wherein it does not work:<br><br>(1) It puts each line of the (presumed to be text) file into an element of a cmake list including empty lines as unique elements... However, if you are familiar with cmake lists at all, you&#39;ll instantly say to yourself -- &quot;ah ha, so blank lines will be skipped in a FOREACH loop.&quot; True : caveat #1 : blank lines are undetectable in a cmake FOREACH structure. But the non-blank lines are usually the important ones... so skipping the blank ones is probably ok... depends on your task, I suppose.
<br><br>(2) It does not handle trailing backslashes at the end of a line &quot;correctly.&quot; It will end up with consecutive lines with trailing backslashes all put together as one line in the cmake list. caveat #2 : you&#39;ll need to do more work if you want to detect trailing backslashes and get lines including those stuffed into a cmake list properly
<br><br>Other than that, it&#39;s quite useful and works with CMake 2.4.6 (probably earlier versions, too, but most of my experience using this technique has been with 2.4.6.)<br><br>HTH,<br>David<br><br><br><div><span class="gmail_quote">
<br>On 5/23/07, <b class="gmail_sendername">Pau Garcia i Quiles</b> &lt;<a href="mailto:pgquiles@elpauer.org">pgquiles@elpauer.org</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Quoting Philip Lowman &lt;<a href="mailto:philip@yhbt.com">philip@yhbt.com</a>&gt;:<br><br>&gt; I&#39;m trying to figure out how to use FILE(READ) coupled with some other<br>&gt; CMake call to split a text file into multiple lines that ultimately end
<br>&gt; up in a CMake List.<br>&gt;<br>&gt; The goal is to get all of the lines into a CMake list so I can iterate<br>&gt; through it with FOREACH() and process each line separately.<br>&gt;<br>&gt; I was wondering if anyone has any ideas on how to do this?
<br><br>I don&#39;t know how to achieve that using only CMake.<br><br>I tried to do the same because I wanted to have a &quot;make uninstall&quot;<br>target in my projects and I had to resort to the shell. AFAIK you can<br>
group the platforms CMake supports in two groups: Windows (where you<br>have to script cmd.exe) and all the others (which have a<br>bsh-compatible shell).<br><br>This is the code I am using in my &quot;make uninstall&quot;, you can probably
<br>use it as a starting point:<br><br><br>#<br># Create a &quot;make uninstall&quot; target<br>#<br># Prototype:<br>#&nbsp;&nbsp;&nbsp;&nbsp;GENERATE_UNINSTALL_TARGET()<br># Parameters:<br>#&nbsp;&nbsp;&nbsp;&nbsp;(none)<br><br># Unix version works with any SUS-compliant operating system, as it
<br>needs only Bourne Shell features<br># Win32 version works with any Windows which supports extended cmd.exe<br>syntax (Windows NT 4.0 and newer, maybe Windows NT 3.x too).<br><br>MACRO(GENERATE_UNINSTALL_TARGET)<br>ADD_TO_DISTCLEAN( ${PROJECT_BINARY_DIR}/uninstall.dir )
<br>IF(WIN32)<br>&nbsp;&nbsp;ADD_CUSTOM_TARGET(uninstall<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\&quot;FOR /F \&quot;tokens=1* delims= \&quot; %%f IN<br>\(${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt&quot;}\)\&quot; DO \(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IF EXIST %%f \(
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;del /q /f %%f&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\) ELSE \(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo Problem when removing %%f - Probable causes: File already<br>removed or not enough permissions<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\) VERBATIM<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br>ELSE(WIN32)<br>&nbsp;&nbsp;&nbsp;&nbsp; # Unix<br>&nbsp;&nbsp;&nbsp;&nbsp; ADD_CUSTOM_TARGET(uninstall cat<br>&quot;${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt&quot; | while read f \;<br>do if [ -e \&quot;\$\${f}\&quot; ]; then rm \&quot;\$\${f}\&quot; \; else echo \&quot;Problem
<br>when removing \&quot;\$\${f}\&quot; - Probable causes: File already removed or<br>not enough permissions\&quot; \; fi\; done COMMENT Uninstalling... )<br>ENDIF(WIN32)<br>ENDMACRO(GENERATE_UNINSTALL_TARGET)<br><br>--<br>
Pau Garcia i Quiles<br><a href="http://www.elpauer.org">http://www.elpauer.org</a><br>(Due to the amount of work, I usually need 10 days to answer)<br><br><br><br>_______________________________________________<br>CMake mailing list
<br><a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br><a href="http://www.cmake.org/mailman/listinfo/cmake">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br>