This "works" with just cmake:<br><br> FILE(READ "${file}" contents)<br><br> # Convert file contents into a CMake list (where each element in the list<br> # is one line of the file)<br> #<br> STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
<br> STRING(REGEX REPLACE "\n" ";" contents "${contents}")<br><br>The reason I say "works" (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'll instantly say to yourself -- "ah ha, so blank lines will be skipped in a FOREACH loop." 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 "correctly." It will end up with consecutive lines with trailing backslashes all put together as one line in the cmake list. caveat #2 : you'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'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> <<a href="mailto:pgquiles@elpauer.org">pgquiles@elpauer.org</a>> 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 <<a href="mailto:philip@yhbt.com">philip@yhbt.com</a>>:<br><br>> I'm trying to figure out how to use FILE(READ) coupled with some other<br>> CMake call to split a text file into multiple lines that ultimately end
<br>> up in a CMake List.<br>><br>> The goal is to get all of the lines into a CMake list so I can iterate<br>> through it with FOREACH() and process each line separately.<br>><br>> I was wondering if anyone has any ideas on how to do this?
<br><br>I don't know how to achieve that using only CMake.<br><br>I tried to do the same because I wanted to have a "make uninstall"<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 "make uninstall", you can probably
<br>use it as a starting point:<br><br><br>#<br># Create a "make uninstall" target<br>#<br># Prototype:<br># GENERATE_UNINSTALL_TARGET()<br># Parameters:<br># (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> ADD_CUSTOM_TARGET(uninstall<br> \"FOR /F \"tokens=1* delims= \" %%f IN<br>\(${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt"}\)\" DO \(<br> IF EXIST %%f \(
<br> del /q /f %%f"<br> \) ELSE \(<br> echo Problem when removing %%f - Probable causes: File already<br>removed or not enough permissions<br> \)<br>
\) VERBATIM<br> )<br>ELSE(WIN32)<br> # Unix<br> ADD_CUSTOM_TARGET(uninstall cat<br>"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt" | while read f \;<br>do if [ -e \"\$\${f}\" ]; then rm \"\$\${f}\" \; else echo \"Problem
<br>when removing \"\$\${f}\" - Probable causes: File already removed or<br>not enough permissions\" \; 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>