ctkFunctionLFtoCRLF.cmake 1.9 KB

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