1 ###########################################################################
5 # Copyright (c) Kitware Inc.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 ###########################################################################
21 #! \ingroup CMakeUtilities
22 function(ctkFunctionLFtoCRLF input_file output_file)
23 # Make sure the file exists
24 if(NOT EXISTS ${input_file})
25 message(FATAL_ERROR "Failed to convert LF to CRLF - File [${input_file}] does NOT exist !")
29 file(STRINGS "${input_file}" lines)
33 # Loop over lines and append \r\n
34 foreach(line ${lines})
36 set(string_with_crlf ${line})
39 set(string_with_crlf "${string_with_crlf}\r\n${line}")
43 file(WRITE ${output_file} ${string_with_crlf})
47 # Test - Use cmake -DFUNCTION_TESTING:BOOL=ON -DINPUT_FILE:FILEPATH=<FILE> -DOUTPUT_FILE:FILEPATH=<FILE> -P ctkFunctionLFtoCRLF.cmake
50 if(NOT DEFINED INPUT_FILE)
51 message(FATAL_ERROR "INPUT_FILE is not defined !")
54 if(NOT DEFINED OUTPUT_FILE)
55 message(FATAL_ERROR "OUTPUT_FILE is not defined !")
58 #message(STATUS "INPUT_FILE [${INPUT_FILE}]")
59 #message(STATUS "OUTPUT_FILE [${OUTPUT_FILE}]")
61 ctkFunctionLFtoCRLF("${INPUT_FILE}" "${OUTPUT_FILE}")