make2cmake.cmake 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # James Bigler, NVIDIA Corp (nvidia.com - jbigler)
  2. # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
  3. #
  4. # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
  5. #
  6. # Copyright (c) 2007-2009
  7. # Scientific Computing and Imaging Institute, University of Utah
  8. #
  9. # This code is licensed under the MIT License. See the FindCUDA.cmake script
  10. # for the text of the license.
  11. # The MIT License
  12. #
  13. # License for the specific language governing rights and limitations under
  14. # Permission is hereby granted, free of charge, to any person obtaining a
  15. # copy of this software and associated documentation files (the "Software"),
  16. # to deal in the Software without restriction, including without limitation
  17. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  18. # and/or sell copies of the Software, and to permit persons to whom the
  19. # Software is furnished to do so, subject to the following conditions:
  20. #
  21. # The above copyright notice and this permission notice shall be included
  22. # in all copies or substantial portions of the Software.
  23. #
  24. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  27. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  29. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  30. # DEALINGS IN THE SOFTWARE.
  31. #
  32. #######################################################################
  33. # This converts a file written in makefile syntax into one that can be included
  34. # by CMake.
  35. file(READ ${input_file} depend_text)
  36. if (${depend_text} MATCHES ".+")
  37. # message("FOUND DEPENDS")
  38. # Remember, four backslashes is escaped to one backslash in the string.
  39. string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
  40. # This works for the nvcc -M generated dependency files.
  41. string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
  42. string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
  43. set(dependency_list "")
  44. foreach(file ${depend_text})
  45. string(REGEX REPLACE "^ +" "" file ${file})
  46. if(NOT IS_DIRECTORY ${file})
  47. # If softlinks start to matter, we should change this to REALPATH. For now we need
  48. # to flatten paths, because nvcc can generate stuff like /bin/../include instead of
  49. # just /include.
  50. get_filename_component(file_absolute "${file}" ABSOLUTE)
  51. list(APPEND dependency_list "${file_absolute}")
  52. endif(NOT IS_DIRECTORY ${file})
  53. endforeach(file)
  54. else()
  55. # message("FOUND NO DEPENDS")
  56. endif()
  57. # Remove the duplicate entries and sort them.
  58. list(REMOVE_DUPLICATES dependency_list)
  59. list(SORT dependency_list)
  60. foreach(file ${dependency_list})
  61. set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
  62. endforeach()
  63. file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")