# Why doesn't CMake offer the NEWLINE\_STYLE option to file(WRITE|APPEND) as well?

**URL:** <https://discourse.cmake.org/t/why-doesnt-cmake-offer-the-newline-style-option-to-file-write-append-as-well/9787>\
**Category:** Code\
**Created:** [January 7, 2024, 10:08am UTC](https://discourse.cmake.org/t/why-doesnt-cmake-offer-the-newline-style-option-to-file-write-append-as-well/9787 "2024-01-07T10:08:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Post date:** [January 7, 2024, 10:08am UTC](https://discourse.cmake.org/t/why-doesnt-cmake-offer-the-newline-style-option-to-file-write-append-as-well/9787/1 "2024-01-07T10:08:39Z")

</div>

### 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](https://gitlab.kitware.com/cmake/cmake/-/issues/19198), 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:

```cmake
#
# 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?_

### Reference Links

- [file(WRITE|APPEND)](https://cmake.org/cmake/help/v3.28/command/file.html#write)
- [file(CONFIGURE)](https://cmake.org/cmake/help/v3.28/command/file.html#configure)
- [file(GENERATE)](https://cmake.org/cmake/help/v3.28/command/file.html#generate)
- [configure\_file()](https://cmake.org/cmake/help/v3.28/command/configure_file.html)

---

<div class="post-metadata">

**Author:** ![dnglaze](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/74df32/32.png) [@dnglaze](https://discourse.cmake.org/u/dnglaze)\
**Post date:** [January 7, 2024, 7:14pm UTC](https://discourse.cmake.org/t/why-doesnt-cmake-offer-the-newline-style-option-to-file-write-append-as-well/9787/2 "2024-01-07T19:14:24Z")

</div>

It looks like there is an [open feature request](https://gitlab.kitware.com/cmake/cmake/-/issues/22249) addressing what you are asking. It doesn’t appear there is much information there as to go/no go on the feature. May not be a high priority feature? Might be a good feature to get introduced to CMake source development.

There’s a [different issue](https://gitlab.kitware.com/cmake/cmake/-/issues/23614) that goes into more of a discussion about what’s happening behind the scenes with the `file(WRITE)` command. They just open the file in text mode for that command so it’s relying on the C/C++ runtime behavior.
