CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkFunctionLFtoCRLF.cmake
Go to the documentation of this file.
1###########################################################################
2#
3# Library: CTK
4#
5# Copyright (c) Kitware Inc.
6#
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
10#
11# http://www.apache.org/licenses/LICENSE-2.0.txt
12#
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.
18#
19###########################################################################
20
21#! \ingroup CMakeUtilities
22function(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 !")
26 endif()
27
28 # Read lines
29 file(STRINGS "${input_file}" lines)
30
31 set(string_with_crlf)
32 set(first_line TRUE)
33 # Loop over lines and append \r\n
34 foreach(line ${lines})
35 if(first_line)
36 set(string_with_crlf ${line})
37 set(first_line FALSE)
38 else()
39 set(string_with_crlf "${string_with_crlf}\r\n${line}")
40 endif()
41 endforeach()
42
43 file(WRITE ${output_file} ${string_with_crlf})
44endfunction()
45
46#
47# Test - Use cmake -DFUNCTION_TESTING:BOOL=ON -DINPUT_FILE:FILEPATH=<FILE> -DOUTPUT_FILE:FILEPATH=<FILE> -P ctkFunctionLFtoCRLF.cmake
48#
49if(FUNCTION_TESTING)
50 if(NOT DEFINED INPUT_FILE)
51 message(FATAL_ERROR "INPUT_FILE is not defined !")
52 endif()
53
54 if(NOT DEFINED OUTPUT_FILE)
55 message(FATAL_ERROR "OUTPUT_FILE is not defined !")
56 endif()
57
58 #message(STATUS "INPUT_FILE [${INPUT_FILE}]")
59 #message(STATUS "OUTPUT_FILE [${OUTPUT_FILE}]")
60
61 ctkFunctionLFtoCRLF("${INPUT_FILE}" "${OUTPUT_FILE}")
62endif()