configure_file() and file(GENERATE) line ending changes on windows
Dear CMake developers,
I am using a build pattern, where I configure my files in CMake (configure_file()
), then calling file(GENERATE)
on them to evaluate generator expressions. The original file is being overwritten. My goal is to have LF
line ending on every platform, as our third-party tool picky on that. It would be enough to keep the original line ending.
I am trying to do this in Windows, and I got a weird behavior.
If the configure_file()
call does not define NEWLINE_STYLE
parameter, then the line ending of the output file is not defined by the documentation.
If I investigated well, then the CMake will pick the line ending of the underlying platform (Windows-CRLF, Unix-LF).
As the CMake has no documentation for this case, some would expect that the line ending remains as it was in the input file, as no changing behavior was described.
If we accept this behavior, then the control above the line ending can be handled by the user CMake code by specifying the NEWLINE_STYLE
in every case.
But in the case of file(GENERATE)
where the input file is provided, the line ending changes to the platform line ending, totally inhibiting the input's line endings. (Again, as there is no documented behavior about line ending changes, I would expect that the line ending remains as it is.)
The bigger problem is, that there is no NEWLINE_STYLE
parameter or equivalent for the case when the input is a file.
As far as I know, there is no workaround other than dropping the support of generator expression evaluation and exclude the file.