summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmFileCommand.cxx14
-rw-r--r--Tests/RunCMake/File_Configure/NewLineStyle-ValidArg.cmake7
2 files changed, 14 insertions, 7 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 576f015..9377baa 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -3105,15 +3105,13 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
cmSystemTools::MakeDirectory(path);
}
- std::string newLineCharacters;
- bool open_with_binary_flag = false;
+ std::string newLineCharacters = "\n";
if (newLineStyle.IsValid()) {
- open_with_binary_flag = true;
newLineCharacters = newLineStyle.GetCharacters();
}
cmGeneratedFileStream fout;
- fout.Open(outputFile, false, open_with_binary_flag);
+ fout.Open(outputFile, false, true);
if (!fout) {
cmSystemTools::Error("Could not open file for write in copy operation " +
outputFile);
@@ -3126,11 +3124,15 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
std::stringstream sin(parsedArgs.Content, std::ios::in);
std::string inLine;
std::string outLine;
- while (cmSystemTools::GetLineFromStream(sin, inLine)) {
+ bool hasNewLine = false;
+ while (cmSystemTools::GetLineFromStream(sin, inLine, &hasNewLine)) {
outLine.clear();
makeFile.ConfigureString(inLine, outLine, parsedArgs.AtOnly,
parsedArgs.EscapeQuotes);
- fout << outLine << newLineCharacters;
+ fout << outLine;
+ if (hasNewLine || newLineStyle.IsValid()) {
+ fout << newLineCharacters;
+ }
}
// close file before attempting to copy
diff --git a/Tests/RunCMake/File_Configure/NewLineStyle-ValidArg.cmake b/Tests/RunCMake/File_Configure/NewLineStyle-ValidArg.cmake
index e384873..09aec45 100644
--- a/Tests/RunCMake/File_Configure/NewLineStyle-ValidArg.cmake
+++ b/Tests/RunCMake/File_Configure/NewLineStyle-ValidArg.cmake
@@ -1,10 +1,13 @@
set(file_name ${CMAKE_CURRENT_BINARY_DIR}/NewLineStyle.txt)
function(test_eol style in out)
+ if (style)
+ set(newline_stle NEWLINE_STYLE ${style})
+ endif()
file(CONFIGURE
OUTPUT ${file_name}
CONTENT "@in@"
- NEWLINE_STYLE ${style}
+ ${newline_stle}
)
file(READ ${file_name} new HEX)
if(NOT "${new}" STREQUAL "${out}")
@@ -18,3 +21,5 @@ test_eol(CRLF "c" "630d0a")
test_eol(UNIX "d" "640a")
test_eol(LF "e" "650a")
+
+test_eol("" "a\nb" "610a62")