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.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. #! \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()