ctkFunctionLFtoCRLF.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.commontk.org/LICENSE
  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. #
  22. #
  23. FUNCTION(ctkFunctionLFtoCRLF input_file output_file)
  24. # Make sure the file exists
  25. IF(NOT EXISTS ${input_file})
  26. MESSAGE(FATAL_ERROR "Failed to convert LF to CRLF - File [${input_file}] does NOT exist !")
  27. ENDIF()
  28. # Read lines
  29. FILE(STRINGS "${input_file}" lines)
  30. SET(string_with_crlf)
  31. SET(first_line TRUE)
  32. # Loop over lines and append \r\n
  33. FOREACH(line ${lines})
  34. IF(first_line)
  35. SET(string_with_crlf ${line})
  36. SET(first_line FALSE)
  37. ELSE()
  38. SET(string_with_crlf "${string_with_crlf}\r\n${line}")
  39. ENDIF()
  40. ENDFOREACH()
  41. FILE(WRITE ${output_file} ${string_with_crlf})
  42. ENDFUNCTION()
  43. #
  44. # Test - Use cmake -DFUNCTION_TESTING:BOOL=ON -DINPUT_FILE:FILEPATH=<FILE> -DOUTPUT_FILE:FILEPATH=<FILE> -P ctkFunctionLFtoCRLF.cmake
  45. #
  46. IF(FUNCTION_TESTING)
  47. IF(NOT DEFINED INPUT_FILE)
  48. MESSAGE(FATAL_ERROR "INPUT_FILE is not defined !")
  49. ENDIF()
  50. IF(NOT DEFINED OUTPUT_FILE)
  51. MESSAGE(FATAL_ERROR "OUTPUT_FILE is not defined !")
  52. ENDIF()
  53. #MESSAGE(STATUS "INPUT_FILE [${INPUT_FILE}]")
  54. #MESSAGE(STATUS "OUTPUT_FILE [${OUTPUT_FILE}]")
  55. ctkFunctionLFtoCRLF("${INPUT_FILE}" "${OUTPUT_FILE}")
  56. ENDIF()