[CMake] reading in a file and splitting by line

Philip Lowman philip at yhbt.com
Wed May 23 15:21:51 EDT 2007


David Cole wrote:
> This "works" with just cmake:
> 
>   FILE(READ "${file}" contents)
> 
>   # Convert file contents into a CMake list (where each element in the list
>   # is one line of the file)
>   #
>   STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
>   STRING(REGEX REPLACE "\n" ";" contents "${contents}")

Brilliant!  Thanks, that works wonderfully.

I hadn't even thought to transform the contents of the file into a list 
by simply replacing the carriage returns.

> The reason I say "works" (in quotes) is that there are two caveats 
> wherein it does not work:

Thanks for pointing out the caveats.  I can live with both of them :)

-- 
Philip Lowman
Simulation Development Engineer, Modeling and Simulation Technology
General Dynamics Land Systems
http://www.gdls.com


More information about the CMake mailing list