Problem Description
Recently, I needed to use CMake commands to create and write content to a file. Initially, I used the file(WRITE)
command to write the modified content, but later I wanted to ensure that the line endings of the files I create and modify are uniformly LF
.
After reading this issue, I learned that I can use file(GENERATE|CONFIGURE)
or configure_file()
with the NEWLINE_STYLE
option to specify the line ending format used during saving. For example:
#
# Write ${jsonCnt} into ${_filepath}
#
# file(WRITE "${_filepath}" ${jsonCnt})
file(CONFIGURE OUTPUT "${_filepath}" CONTENT ${jsonCnt} NEWLINE_STYLE LF)
Although the problem seems to be solved, I have a question:
Why doesn’t CMake offer the NEWLINE_STYLE option to file(WRITE|APPEND) as well?